Re: [RFC][PATCH] Mark AT_* path flags as deprecated and add missing RESOLVE_ flags

From: Stefan Metzmacher
Date: Thu Mar 05 2020 - 15:11:55 EST


Hi David,

> Do we want to do this? Or should we duplicate the RESOLVE_* flags to AT_*
> flags so that existing *at() syscalls can make use of them?
>
> David
> ---
> commit 448731bf3b29f2b1f7c969d7efe1f0673ae13b5e
> Author: David Howells <dhowells@xxxxxxxxxx>
> Date: Thu Mar 5 17:40:02 2020 +0000
>
> Mark AT_* flags as deprecated and add missing RESOLVE_ flags
>
> It has been suggested that new path-using system calls should use RESOLVE_*
> flags instead of AT_* flags, but the RESOLVE_* flag functions are not a
> superset of the AT_* flag functions. So formalise this by:
>
> (1) In linux/fcntl.h, add a comment noting that the AT_* flags are
> deprecated for new system calls and that RESOLVE_* flags should be
> used instead.
>
> (2) Add some missing flags:
>
> RESOLVE_NO_TERMINAL_SYMLINKS for AT_SYMLINK_NOFOLLOW
> RESOLVE_NO_TERMINAL_AUTOMOUNTS for AT_NO_AUTOMOUNT
> RESOLVE_EMPTY_PATH for AT_EMPTY_PATH

For me "TERMINAL" sounds strange here (I'm not a native speaker, so feel
free to ignore me...). I'd use "BASENAME" instead.

> (3) Make openat2() support RESOLVE_NO_TERMINAL_SYMLINKS. LOOKUP_OPEN
> internally implies LOOKUP_AUTOMOUNT, and AT_EMPTY_PATH is probably not
> worth supporting (maybe use dup2() instead?).
>
> Reported-by: Stefan Metzmacher <metze@xxxxxxxxx>
> Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
> cc: Aleksa Sarai <cyphar@xxxxxxxxxx>
>
> diff --git a/fs/open.c b/fs/open.c
> index 0788b3715731..6946ad09b42b 100644
> --- a/fs/open.c
> +++ b/fs/open.c
> @@ -977,7 +977,7 @@ inline struct open_how build_open_how(int flags, umode_t mode)
> inline int build_open_flags(const struct open_how *how, struct open_flags *op)
> {
> int flags = how->flags;
> - int lookup_flags = 0;
> + int lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT;
> int acc_mode = ACC_MODE(flags);
>
> /* Must never be set by userspace */
> @@ -1055,8 +1055,8 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op)
>
> if (flags & O_DIRECTORY)
> lookup_flags |= LOOKUP_DIRECTORY;
> - if (!(flags & O_NOFOLLOW))
> - lookup_flags |= LOOKUP_FOLLOW;
> + if (flags & O_NOFOLLOW)
> + lookup_flags &= ~LOOKUP_FOLLOW;
>
> if (how->resolve & RESOLVE_NO_XDEV)
> lookup_flags |= LOOKUP_NO_XDEV;
> @@ -1068,6 +1068,8 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op)
> lookup_flags |= LOOKUP_BENEATH;
> if (how->resolve & RESOLVE_IN_ROOT)
> lookup_flags |= LOOKUP_IN_ROOT;
> + if (how->resolve & RESOLVE_NO_TERMINAL_SYMLINKS)
> + lookup_flags &= ~LOOKUP_FOLLOW;

Where's the RESOLVE_NO_TERMINAL_AUTOMOUNTS check?

metze

Attachment: signature.asc
Description: OpenPGP digital signature