From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) by sourceware.org (Postfix) with ESMTPS id 9FA263858D37 for ; Tue, 23 May 2023 19:19:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9FA263858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-5557d18020bso64252eaf.0 for ; Tue, 23 May 2023 12:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684869565; x=1687461565; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=v3WWlvpQd+1yqedC5fTDq00RQaX+L1LXPfrvBinrWUU=; b=Rxk+EG0yRBSkxSItjGFap4hhuHdVh00an8RpDThWE4G5lkMqDEO6MqnbGr9bWT6V23 KVYYafddPJpdtQNLCcD/67JUy2azuN95W7Jsgkoju9wdcsp2D+mjpXJ1nU7Z0MQxGfRR JJrRQ0c4ulFzQvCyUiQrVs0BbIfutalqo1bDZCZXihLwB6CpO9mZKtCue7cAOZlYHiYH dAAgLCYeiXzRjsPHZlA8tvb+SZZweyT/x6fdkeghJDon0p5D9og8TlP6skSDGW36JHKP wCA8RXIH/hIgxP1CJADGlcJXcdHvsqW51VBdycm2UADV4RU4qWusRSGmHxDDAFMZhF5l HsBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684869565; x=1687461565; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v3WWlvpQd+1yqedC5fTDq00RQaX+L1LXPfrvBinrWUU=; b=ZVkRUADHCvq+n9pKxUMJIKemxC5Og6TNR72qZN3sAaGJde9Od1tfcHg8h6y8pvoAR1 TK5UCfGKsNNaBaK1pbXqO595jUMUlB9zNXSv00sG8UlFo90tAjFYFp8gkIz03NUVOVGK HZnpUETptn1uLDanXdRkxtIiEWdHhklIga1KswtfhTxdTG8fLvvsa7TDBAmoQGahxZdG WEmu0Bi259HC928H58bHMF2Kfo/AhtrBQR4uMoFCEMkr6I4VrdGcJ40Tsx2IQ5+pERfh K75tuXmsmTWffrW6WOJF/KsuvNTwzcCwKn7o1Y/da59vTUj7K9l8FEH09hfJnH9u5mS6 hVig== X-Gm-Message-State: AC+VfDxaht/tLkCWWmkw8+f/yRC8ETRbwRuRIqhyLvFqmV828jF87Y0j LZc97dlCtlFXRrxaKr9dEIvHYUiL3MTDAriaReA= X-Google-Smtp-Source: ACHHUZ5s5SaDyZ5VQ9kML6xf+H2Ckc8dtirgrb9vvaFYUOGuzHweBzQwcKNZL9+z5ksXv1gzXya7TYVL2k05s6oNVGY= X-Received: by 2002:aca:1207:0:b0:394:3d96:8cf3 with SMTP id 7-20020aca1207000000b003943d968cf3mr7366707ois.25.1684869564737; Tue, 23 May 2023 12:19:24 -0700 (PDT) MIME-Version: 1.0 References: <20230520182125.3986459-1-bugaevc@gmail.com> <2ee46c72-ea05-b45b-0848-30f31a2696ac@linaro.org> In-Reply-To: <2ee46c72-ea05-b45b-0848-30f31a2696ac@linaro.org> From: Sergey Bugaev Date: Tue, 23 May 2023 22:19:13 +0300 Message-ID: Subject: Re: [RFC PATCH] debug: Add tests for fortified fcntl () To: Adhemerval Zanella Netto Cc: libc-alpha@sourceware.org, Joseph Myers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello, thank you for taking a look. On Tue, May 23, 2023 at 9:40=E2=80=AFPM Adhemerval Zanella Netto wrote: > > + res =3D __fcntl (lockfd1, F_OFD_GETLK, &flock); > > This is an external case, so use the external default name. Do you mean that this should be s/__fcntl/fcntl/? If that is what you mean -- here's why I used __fcntl here, but not in all the other places: The point of the OFD tests in the patch is to check for 32-bit vs 64-bit confusion in the fortification. If, for example, in some configuration the plain fcntl is supposed to be 32-bit (and struct flock is 32-bit), but the fortified version of fcntl mistakenly forwards to fcntl64, then the 32-bit struct flock will not be converted to struct flock64, and will be passed to the kernel as-is. It will yield some garbage when interpreted as a struct flock64, and the kernel will likely reject it with an error (EINVAL, perhaps) -- which is what the test checks against. But the test also needs to work on the kernel versions that do not support OFD locks, so it does this check for support being present at all first, and skips running the OFD tests if the kernel does not support it. But how do you check for OFD locks support? -- you try to F_OFD_GETLK and see if the kernel returns EINVAL. If it does return that, OFD locks are unsupported. And herein lies the problem, we cannot differentiate between EINVALs caused by missing kernel support from EINVALs caused by the very kind of bugs this test checks against! We'd mistake the actual issue we wanted to catch for missing kernel support, skip the bulk of the test, and report success. So in this first check of whether or not OFD locks are supported at all, I've used __fcntl, which does not get fortified and so cannot suffer from the 32-bit vs 64-bit confusion bug. The rest of the code uses the regular fcntl. There's a comment above briefly mentioning this, too -- clearly it has to be expanded. So, with this in mind, should I be using __fcntl here, or is there a better option? Sergey