From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by sourceware.org (Postfix) with ESMTPS id 3FEA63973000 for ; Thu, 20 May 2021 18:01:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3FEA63973000 Received: by mail-qt1-x834.google.com with SMTP id y12so13392052qtx.11 for ; Thu, 20 May 2021 11:01:04 -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:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=h8aCbCAdyMJl9MFdLF7fDfZYU8lukeMN+py+A4yQlJI=; b=P9ckAAyY00TDJMDGV7pFe9JZHeRZQL1LvHfaiwGLl6L5n0y00dtlUuPaq7fzhBl7ki Z9Ui0sx6OcNBHdHtek0fD2KVKDGS7AB3uOnlYIQZFqDJFnRD3UYp+7OT0u5+TABEZ/Bi EdpsUYX0osVDfvk1adPbigbFkc/ZrPhZvNEVIr/jZmkUoGAJhdnIsM8lWhctZQ/Ry4l8 bZfD+S2HpaL79DfNHoZw/0p8DHGBO2KouX9F7Hmdb1QHf+nyIrAnmIvpzT98ah2pbSOJ GN4X4Tdo/TBfr9CUNfrO7ZH3hLYs9gxvI454gmWmiZ5OYSg4DyrdD8ObWudYnL0Nv5eI hHaw== X-Gm-Message-State: AOAM532nZqeL2NXOIRZLPvI1SD43zAasxAKyRFihgnu6NRLV/LfZR9r7 /8o7WMZDoe/rk1zSEMl6ziWcjdc+odFskA== X-Google-Smtp-Source: ABdhPJy5IROI6xJ7+TNWrZb/KV3r7qLax/m1U07r6Qzv7gCdY7ISEAYByDR9MBrcoGUi9RBK0dKc6Q== X-Received: by 2002:ac8:a4f:: with SMTP id f15mr6673161qti.198.1621533663619; Thu, 20 May 2021 11:01:03 -0700 (PDT) Received: from [192.168.1.4] ([177.194.37.86]) by smtp.gmail.com with ESMTPSA id y1sm2423914qkp.21.2021.05.20.11.01.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 May 2021 11:01:03 -0700 (PDT) Subject: Re: [PATCH v2 05/25] linux: Add fallback for 64-bit time_t SO_{RCV, SND}TIMEO To: Florian Weimer , 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> From: Adhemerval Zanella Message-ID: <6f44ae7d-40d5-3be1-e0ed-6cea4a8e1828@linaro.org> Date: Thu, 20 May 2021 15:01:01 -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: <87zgwpsy3q.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.7 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: Thu, 20 May 2021 18:01:09 -0000 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).