From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by sourceware.org (Postfix) with ESMTPS id 2E5C638930DB for ; Mon, 7 Jun 2021 17:52:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2E5C638930DB Received: by mail-qv1-xf2a.google.com with SMTP id t6so3459490qvp.5 for ; Mon, 07 Jun 2021 10:52:21 -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=vBr8PCNWtOrViL+12pRUZ3tP8eWSS8rcgB0SuBrfHa4=; b=jT/q1VM2/Yblzbd+yzYoz0J8Y4QrczfmY9+FSBkl33b2aPxHZVZ+aMbXbrbzKSoeAs NiYrAg6s1mPGOE3mfBjc5Qe8RENAfdYognYHUMVzKuHOe43H+RcLOTijXBd4OfLGcRNW 2QuxxY21P5JOlPwEbj3v09N1g+HpscjqpVjRF9MFyh70f2hQwYknKFxMI4trPBvkKtjU LN91QXbVAFOtqMlfgoxaAwmQR2LpAoNewj6TvdFS+HiewJN00GsNtybaM7we1ciHOUDN lQVxYiqhMJWbPu/CphqqrSiM6Mf7UgcYJwNRJjVZCQw1m2LnrZyZnmkGsg3gmP1tCJdb iHrA== X-Gm-Message-State: AOAM530dq75nzzUlUeCNv4wlU5rW9xffOFwIBdLpytGQmYvGJwqbkVoj 9IdmZtzcKjYg17YsdBlJ1NkvQg== X-Google-Smtp-Source: ABdhPJyoePFVtpVb7rCLy6jPvoxD/GzV4FwGfYYcqO+Qvv8gxrNl5vssMaWr5LA/G2ap82/cGqgm+w== X-Received: by 2002:a05:6214:c42:: with SMTP id r2mr18741105qvj.35.1623088340644; Mon, 07 Jun 2021 10:52:20 -0700 (PDT) Received: from [192.168.1.4] ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id 80sm8923797qkd.38.2021.06.07.10.52.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Jun 2021 10:52:20 -0700 (PDT) Subject: Re: [PATCH v2 05/25] linux: Add fallback for 64-bit time_t SO_{RCV,SND}TIMEO To: Carlos O'Donell , libc-alpha@sourceware.org References: <20210518205613.1487824-1-adhemerval.zanella@linaro.org> <20210518205613.1487824-6-adhemerval.zanella@linaro.org> From: Adhemerval Zanella Message-ID: Date: Mon, 7 Jun 2021 14:52:17 -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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.4 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: Mon, 07 Jun 2021 17:52:25 -0000 On 04/06/2021 16:30, Carlos O'Donell wrote: >> +#ifndef __ASSUME_TIME64_SYSCALLS >> +static int >> +setsockopt32 (int fd, int level, int optname, const 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; > > Same issue as above with size. Silent truncation required. For setsockopt I think returning EINVAL is the correct approach here. POSIX does not specify that the returned value should silently truncated in the case of the options is larger than the input value (as for getsockopt) and it is what kernel really does: net/core/sock.c: 364 static int sock_set_timeout(long *timeo_p, sockptr_t optval, int optlen, 365 bool old_timeval) 366 { 367 struct __kernel_sock_timeval tv; 368 369 if (old_timeval && in_compat_syscall() && !COMPAT_USE_64BIT_TIME) { 370 struct old_timeval32 tv32; 371 372 if (optlen < sizeof(tv32)) 373 return -EINVAL; 374 375 if (copy_from_sockptr(&tv32, optval, sizeof(tv32))) 376 return -EFAULT; 377 tv.tv_sec = tv32.tv_sec; 378 tv.tv_usec = tv32.tv_usec; 379 } else if (old_timeval) { 380 struct __kernel_old_timeval old_tv; 381 382 if (optlen < sizeof(old_tv)) 383 return -EINVAL; 384 if (copy_from_sockptr(&old_tv, optval, sizeof(old_tv))) 385 return -EFAULT; 386 tv.tv_sec = old_tv.tv_sec; 387 tv.tv_usec = old_tv.tv_usec; 388 } else { 389 if (optlen < sizeof(tv)) 390 return -EINVAL; 391 if (copy_from_sockptr(&tv, optval, sizeof(tv))) 392 return -EFAULT; 393 }