From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id 0B92D398B8A3 for ; Fri, 9 Apr 2021 12:46:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0B92D398B8A3 Received: by mail-qk1-x730.google.com with SMTP id c3so5612920qkc.5 for ; Fri, 09 Apr 2021 05:46:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=E3n5rJGZq1cnOQBPro9n6FUN5HC5hVohy0A2JfJmiso=; b=Ty9xIlJ5Ix3Q0euC823YEx42HNP3TB35Wquax01RlgzgUZb92LMjp08x0RDtZ55V5L T7mAnLAmVlQWG1kw6lsWWv2JIxD1GmQD/dgoA8kMIaQEtgFnKhyo3hoTPfmCIxuCIuax F68bwZKe7zmZK56jhc6kujUE4VV8uQn04qLjtr5n6qMBF9rBP7ZQ8C9+KOv/bp//bg1X m3UACT6wM3aIJO1cayWtSKWyqqNJsr8VlD1rOrrOUkGYkArJzBOWfJ3giP48/UwkXnMY CeL87V/O29NYFB4/ezfS/oRz5HNhf0kaJI6A2OOTE9fnfjdfZczu0pdYrjvRLv4Gjd17 hYJg== X-Gm-Message-State: AOAM531v0JyjKWbvGdHKi7YhtsxSTb4UOBL806RNXATAltxtri9IdVUS fWffB8u4baztvdy/RHFK44DWNQ== X-Google-Smtp-Source: ABdhPJyzkrUzYc3CgmY3go9HUEOFkV9ZuF9H8+p3Y9beUiZg1svx9mOukVRuWDV7llq5f/6hzOjCtA== X-Received: by 2002:a05:620a:210a:: with SMTP id l10mr13225184qkl.398.1617972373556; Fri, 09 Apr 2021 05:46:13 -0700 (PDT) Received: from [192.168.1.132] ([177.194.41.149]) by smtp.gmail.com with ESMTPSA id k126sm1662611qkb.4.2021.04.09.05.46.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Apr 2021 05:46:13 -0700 (PDT) Subject: Re: [PATCH v2 1/2] linux: Normalize and return timeout on select (BZ #27651) To: Florian Weimer , Adhemerval Zanella via Libc-alpha Cc: Andreas Schwab References: <20210409113639.1124756-1-adhemerval.zanella@linaro.org> <87czv3y6n5.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Message-ID: Date: Fri, 9 Apr 2021 09:46:10 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <87czv3y6n5.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Apr 2021 12:46:15 -0000 On 09/04/2021 09:38, Florian Weimer wrote: > * Adhemerval Zanella via Libc-alpha: > >> +/* Return true if select modify the timeout to reflect the amount of time >> + no slept. */ >> +extern bool support_select_modify_timeout (void); >> + >> +/* Return true if select normalize the timeout input by taking in account >> + tv_usec larger than 1000000. */ >> +extern bool support_select_normalize_timeout (void); > > Maybe use support_select_modifies_timeout and > support_select_normalizes_timeout? > > Please commit the support/ bits separately. > >> diff --git a/sysdeps/unix/sysv/linux/select.c b/sysdeps/unix/sysv/linux/select.c >> index 415aa87d3c..d075270ff4 100644 >> --- a/sysdeps/unix/sysv/linux/select.c >> +++ b/sysdeps/unix/sysv/linux/select.c >> @@ -33,12 +33,34 @@ int >> __select64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, >> struct __timeval64 *timeout) >> { >> + __time64_t s = timeout != NULL ? timeout->tv_sec : 0; >> + int32_t us = timeout != NULL ? timeout->tv_usec : 0; >> + int32_t ns; >> + >> + if (s < 0 || us < 0) >> + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); >> + >> + /* Normalize the timeout, as legacy Linux __NR_select and __NR__newselect. >> + Different than syscall, it also handle possible overflow. */ >> + if (us / USEC_PER_SEC > INT64_MAX - s) >> { >> + s = INT64_MAX; >> + ns = NSEC_PER_SEC - 1; >> } >> + else >> + { >> + s += us / USEC_PER_SEC; >> + us = us % USEC_PER_SEC; >> + ns = us * NSEC_PER_USEC; >> + } >> + >> + struct __timespec64 ts64, *pts64 = NULL; >> + if (timeout != NULL) >> + { >> + ts64.tv_sec = s; >> + ts64.tv_nsec = ns; >> + pts64 = &ts64; >> + } > > The overflow handling is slightly inconsistent with the in_time_t_range > range check below. Here we use silently saturating arithmetic, below > it's an error. In fact on the in_time_t below it needs to check for the normalized tv_sec on ts64.tv_sec instead of the input timeout. I will fix it and send a newer version without the libsupport bits.