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 E3DA73846034 for ; Fri, 21 May 2021 19:18:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E3DA73846034 Received: by mail-qk1-x730.google.com with SMTP id v8so20925232qkv.1 for ; Fri, 21 May 2021 12:18:00 -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=CYoFSmwitJ6supUAYJX7DWUCaxEvrr/Swh2vefmet64=; b=C2aIpYCk5eWViMfbBz0CgCGOr9uWaMIrXu+B3eYkw9yrKxvKZKUfa5nzkSOk9N2FM1 LOK934cvMYTIAZlH4QjqloMz9iRRGBEw8STS801OsfZqy6CoqfbFjQr9Dp6+MwhyVPX2 cCbRrRLhNaGNtTXOjooJRJ57f6sOFLkg+tgdeEylnM5H080ciwbv7EdL8yPsYGakVUUQ GIaLtBi3QeLsTYg8Ds+tQtYXRHlRO/n0CdwKTG5G7nfFHsTmqQ+3nd7S7Y1/+q0d0LYx s66yf0Xfx1P0zTouG64m+AiUYDjp0qOBcczPS3sYzhAfvuo/WPytjreuyYrLNe5jYxQN cMlQ== X-Gm-Message-State: AOAM533SE0A9Sn+QASvivSv9+531ZNkQofyoKnRyzFvMSd8/3Dwb6nkj Rn4J4QDPvqxAdKgNLWfxawQgno2FmBy5FA== X-Google-Smtp-Source: ABdhPJybXxqMjsvl83ysQ+nHvZ50bcSBu2nJovVYLIGUeTP1BnVmAZNEB7t9J9TC9bFVuNF3UQtd9A== X-Received: by 2002:a37:b6c4:: with SMTP id g187mr14451703qkf.491.1621624680301; Fri, 21 May 2021 12:18:00 -0700 (PDT) Received: from [192.168.1.4] ([177.194.37.86]) by smtp.gmail.com with ESMTPSA id d16sm4888486qtw.23.2021.05.21.12.17.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 May 2021 12:18:00 -0700 (PDT) Subject: Re: [PATCH v2 05/25] linux: Add fallback for 64-bit time_t SO_{RCV, SND}TIMEO To: Florian Weimer Cc: Adhemerval Zanella via Libc-alpha References: <20210518205613.1487824-1-adhemerval.zanella@linaro.org> <20210518205613.1487824-6-adhemerval.zanella@linaro.org> <87zgwpsy3q.fsf@oldenburg.str.redhat.com> <6f44ae7d-40d5-3be1-e0ed-6cea4a8e1828@linaro.org> <874kew6igo.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Message-ID: Date: Fri, 21 May 2021 16:17:57 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <874kew6igo.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=-6.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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, 21 May 2021 19:18:02 -0000 On 21/05/2021 15:37, Florian Weimer wrote: > * Adhemerval Zanella: > >> On 20/05/2021 03:44, Florian Weimer wrote: >>> * Adhemerval Zanella via Libc-alpha: >>> >>>> +#ifndef __ASSUME_TIME64_SYSCALLS >>>> +static int >>>> +getsockopt32 (int fd, int level, int optname, void *optval, >>>> + socklen_t *len) >>>> +{ >>>> + int r = -1; >>>> + >>>> + if (level != SOL_SOCKET) >>>> + return r; >>>> + >>>> + switch (optname) >>>> + { >>>> + case COMPAT_SO_RCVTIMEO_NEW: >>>> + case COMPAT_SO_SNDTIMEO_NEW: >>>> + { >>>> + if (*len < sizeof (struct __timeval64)) >>>> + { >>>> + __set_errno (EINVAL); >>>> + break; >>>> + } >>>> + >>>> + if (optname == COMPAT_SO_RCVTIMEO_NEW) >>>> + optname = COMPAT_SO_RCVTIMEO_OLD; >>>> + if (optname == COMPAT_SO_SNDTIMEO_NEW) >>>> + optname = COMPAT_SO_SNDTIMEO_OLD; >>>> + >>>> + struct __timeval32 tv32; >>>> + r = getsockopt_syscall (fd, level, optname, &tv32, >>>> + (socklen_t[]) { sizeof tv32 }); >>>> + if (r < 0) >>>> + break; >>>> + struct __timeval64 *tv64 = (struct __timeval64 *) optval; >>>> + *tv64 = valid_timeval32_to_timeval64 (tv32); >>>> + *len = sizeof (*tv64); >>>> + } >>> >>> I think POSIX requires checking the incoming *len value and truncating >>> the output. >> >> The kernel will fail with EINVAL if the input argument is smaller than >> the expected one, so I think as QoI the truncation here should mean >> to return a timeout value clamped to 32 bits (instead of a truncated >> memory). > > Wow, that EINVAL behavior is not POSIX-compliant at all. > > If the kernel behaves that way, I guess glibc should as well. In fact, checking again the source it does seem that silently truncated the result: net/core/sock.c 1420 case SO_RCVTIMEO_OLD: 1421 case SO_RCVTIMEO_NEW: 1422 lv = sock_get_timeout(sk->sk_rcvtimeo, &v, SO_RCVTIMEO_OLD == optname); 1423 break; [...] 1624 if (len > lv) 1625 len = lv; 1626 if (copy_to_user(optval, &v, len)) 1627 return -EFAULT; So I think maybe we should do the same here, not sure if this is really an improvement over compatibility.