From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by sourceware.org (Postfix) with ESMTPS id A0826385840C for ; Mon, 29 May 2023 21:59:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A0826385840C 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-oi1-x236.google.com with SMTP id 5614622812f47-39819d3c218so2322419b6e.1 for ; Mon, 29 May 2023 14:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685397569; x=1687989569; 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=i9w1YTmNGxmimd2vbn5m2CLOZiexnZXjudzR93R2zUM=; b=qVcXNKilUgq3hr4N0r0QWmEfE61FqWcYPHyRqF8BXrF4dGYQXj1mFHqdPvQDcg7BrI iddhcnWLs6ruXl+sJLR9hP01TXCXlRbzLbcob0gAtmjKhfgviqOrVvQXfH0VmWUnKjSO kNWZAb2HKsmchvPb6Gld7HUX8dAi7vReWulOqcZ80xlQLQJ3fDlzhXMA/ISldQvcnBsD /9TdBmxcNrVi0y5j9V01nI6+Y5QnpRwWalT1mbtWFKL5/ZczN4Q4+DfhBuQYmgs+D4+d 6Yxeam09cbwMR1B9dhiGB4YqKB5mJW/PQClMoad8j1eYU2vvEMHsCoVO+IakQFEq102q 7YlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685397569; x=1687989569; 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=i9w1YTmNGxmimd2vbn5m2CLOZiexnZXjudzR93R2zUM=; b=BNKy+AuMYuTc1U7RjfHJVjYYnIQLtr2gYo56QnFn9hJibMZ28rZb4TcbHP0qXkrc4O VxtEUQFhG0lwjHC7qBU7PIDER0VsOit4C0vUKCklALG/ddahWT+EBVnIa0qK7X/8OYWg HhSFtqQ2qWhXecJUSaxrjqz7oERF3+UUXAAMLBFF+4UoHAWx8FIzCWzc9xtnM6QkhIzB 8exuPsFO0XXNxNs8VK2hR8b8/op3fucWdaZoq6lIIaxHzL/g/0S79TDcmRoLnIfele0E gOUg7Mq6HD30uMPsaSMWRUMEAO6AorFjHEPjk0i+JEqWO/UN89n+G5GUmNk/+0JzKvvV 2sXg== X-Gm-Message-State: AC+VfDzyEq1K+2UqSm06l6L6HZXiMGPzXstR8eRkD5tEXm7rkKnz/7ge 5rBLE2WWGcgI98zp5QqAUqB9etzaWk2Pr8sCYla3o9k3beI= X-Google-Smtp-Source: ACHHUZ4Lnlu1X5oNIx3PRT9spJyFEcMoWUEUXe5D37nOqOVjWDrtYPITV8gqg79TzeLcIePEAY51taFWYZEgOxoa7qw= X-Received: by 2002:a05:6808:424c:b0:398:2d08:1143 with SMTP id dp12-20020a056808424c00b003982d081143mr139100oib.35.1685397568865; Mon, 29 May 2023 14:59:28 -0700 (PDT) MIME-Version: 1.0 References: <20230528172013.73111-1-bugaevc@gmail.com> <20230528172013.73111-4-bugaevc@gmail.com> <31457dbb-a805-262f-4b62-be0b40960ca6@linaro.org> <8354c659-cfb0-993a-2764-72a2cd6f6ed4@linaro.org> In-Reply-To: From: Sergey Bugaev Date: Tue, 30 May 2023 00:59:17 +0300 Message-ID: Subject: Re: [PATCH v2 3/3] io: Add FORTIFY_SOURCE check for fcntl arguments To: Adhemerval Zanella Netto Cc: Florian Weimer , libc-alpha@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,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: On Tue, May 30, 2023 at 12:09=E2=80=AFAM Adhemerval Zanella Netto wrote: > It is returned unmodified, but the asm acts a compiler barrier which gcc > documentation also declares as 'strong memory barrier' [1] (which I think= was > written before C11 memory semantic). > > [1] https://gcc.gnu.org/onlinedocs/gcc/Volatiles.html But that one is talking about load/store reordering, not constant propagation. Here's what I'm talking about: [0] (and an actual Rust version at [1]). [0]: https://godbolt.org/z/qaMa7EavY [1]: https://godbolt.org/z/c4dhaKbqe Would you like me to add something similar to Rust's black_box glibc-wide in a header (if so, what would be a good name?), or should I just do it locally in tst-fortify.c where I need it? > > Rust's black_box is / was [0] instead implemented as > > > > llvm_asm!("" : : "r"(&mut dummy) : "memory" : "volatile"); > > What the 'volatile' constraint does for the llvm_asm? Is is to mimic a > 'asm volatile' or is something else? Yes, I believe it was the same thing as 'asm volatile'. This is because llvm_asm!() was not a special *syntax* like inline asm is in GCC, but a magic macro, so 'volatile' has to go inside the macro. But also note that llvm_asm!() has been deprecated and removed [2] (it was always an unstable feature, never intended to be stabilized); it's been replaced by the new asm!() macro that has a different mini-syntax (more like the Rust formatting macros, less like GCC/LLVM inline assembly). [2]: https://github.com/rust-lang/rust/pull/92816 With the asm!() macro the same would rather look like this: asm!( "/* pretend to use {0} */", in(reg) &mut dummy, options(nostack, preserves_flags) ) The default around 'volatile' (and other flags) has been flipped, now you'd need to specify 'options(pure)' to get the previous non-volatile behavior. > It is exported because all tests are actually built with _GNU_SOURCE (don= e > by include/libc-symbols.h), so the test check is superfluous. It also > leaks implementation details, such as internal defines. Usually to check > for internal implementation we use test-internal (which are built > statically). > > But if you really want to check for _LARGEFILE64_SOURCE, you will need to > add *another* fortify test that undef _GNU_SOURCE (like stdlib/tst-strtol= -binary-c11.c > for instance). I thought the src-chk-nongnu =3D \#undef _GNU_SOURCE part handled undoing the #define _GNU_SOURCE (from include/libc-symbols.h) for the -nongnu- tests? I also think I might have actually gotten errors here about missing fcntl64 and the like before I added the ifdef check, but I might be misremembering this one. Sergey