From: David Laight <david.laight.linux@gmail.com>
To: Masaharu Noguchi <nogunix@gmail.com>
Cc: Jeff Layton <jlayton@kernel.org>,
Chuck Lever <chuck.lever@oracle.com>,
Jesper Juhl <jesperjuhl76@gmail.com>,
Alexander Aring <alex.aring@gmail.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] uapi: fcntl: guard AT_RENAME_* aliases
Date: Mon, 10 Nov 2025 23:11:57 +0000 [thread overview]
Message-ID: <20251110231157.4ab7601b@pumpkin> (raw)
In-Reply-To: <20251110144232.3765169-2-nogunix@gmail.com>
On Mon, 10 Nov 2025 23:42:31 +0900
Masaharu Noguchi <nogunix@gmail.com> wrote:
> Including <linux/fcntl.h> after libc headers such as stdio.h may leave
> the renameat2() flag macros defined to libc's values. That leaks the
> wrong numbers into user space even though the kernel header tries to
> provide its own aliases.
>
> Check whether AT_RENAME_* is already defined and whether the value
> matches what the uapi header expects. If not, drop the old definition
> and replace it with the kernel one so the exported flags stay stable
> regardless of include order.
>
> Signed-off-by: Masaharu Noguchi <nogunix@gmail.com>
> ---
> include/uapi/linux/fcntl.h | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/include/uapi/linux/fcntl.h b/include/uapi/linux/fcntl.h
> index 3741ea1b73d8..8b667550e44a 100644
> --- a/include/uapi/linux/fcntl.h
> +++ b/include/uapi/linux/fcntl.h
> @@ -156,10 +156,23 @@
> * as possible, so we can use them for generic bits in the future if necessary.
> */
>
> -/* Flags for renameat2(2) (must match legacy RENAME_* flags). */
> +/* Flags for renameat2(2) (must match legacy RENAME_* flags).
> + * stdio.h may define these differently, so check explicitly.
> + */
> +#if !defined(AT_RENAME_NOREPLACE) || AT_RENAME_NOREPLACE != 0x0001
> +#undef AT_RENAME_NOREPLACE
I deliberately left out the #undef so you'd get a compile-time error
if the values of the definitions differ.
David
> #define AT_RENAME_NOREPLACE 0x0001
> +#endif
> +
> +#if !defined(AT_RENAME_EXCHANGE) || AT_RENAME_EXCHANGE != 0x0002
> +#undef AT_RENAME_EXCHANGE
> #define AT_RENAME_EXCHANGE 0x0002
> +#endif
> +
> +#if !defined(AT_RENAME_WHITEOUT) || AT_RENAME_WHITEOUT != 0x0004
> +#undef AT_RENAME_WHITEOUT
> #define AT_RENAME_WHITEOUT 0x0004
> +#endif
>
> /* Flag for faccessat(2). */
> #define AT_EACCESS 0x200 /* Test access permitted for
next prev parent reply other threads:[~2025-11-10 23:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-10 14:42 [PATCH v2 0/2] uapi/samples: guard renameat2 flag macros Masaharu Noguchi
2025-11-10 14:42 ` [PATCH v2 1/2] uapi: fcntl: guard AT_RENAME_* aliases Masaharu Noguchi
2025-11-10 23:11 ` David Laight [this message]
2025-11-10 14:42 ` [PATCH v2 2/2] samples: vfs: avoid libc AT_RENAME_* redefinitions Masaharu Noguchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251110231157.4ab7601b@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=alex.aring@gmail.com \
--cc=chuck.lever@oracle.com \
--cc=jesperjuhl76@gmail.com \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nogunix@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox