Re: [RFC][PATCH 03/13] do_fchownat(): import pathname only once

Jan Kara
2025-11-13T10:13:49Z

On Sun 09-11-25 06:37:35, Al Viro wrote:
> Convert the user_path_at() call inside a retry loop into getname_flags() +
> filename_lookup() + putname() and leave only filename_lookup() inside
> the loop.
>
> Since we have the default logics for use of LOOKUP_EMPTY (passed iff
> AT_EMPTY_PATH is present in flags), just use getname_uflags() and
> don't bother with setting LOOKUP_EMPTY in lookup_flags - getname_uflags()
> will pass the right thing to getname_flags() and filename_lookup()
> doesn't care about LOOKUP_EMPTY at all.
>
> The things could be further simplified by use of cleanup.h stuff, but
> let's not clutter the patch with that.
>
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

Honza

> ---
> fs/open.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/fs/open.c b/fs/open.c
> index e9a08a820e49..e5110f5e80c7 100644
> --- a/fs/open.c
> +++ b/fs/open.c
> @@ -804,17 +804,17 @@ int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,
> int flag)
> {
> struct path path;
> - int error = -EINVAL;
> + int error;
> int lookup_flags;
> + struct filename *name;
>
> if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
> - goto out;
> + return -EINVAL;
>
> lookup_flags = (flag & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW;
> - if (flag & AT_EMPTY_PATH)
> - lookup_flags |= LOOKUP_EMPTY;
> + name = getname_uflags(filename, flag);
> retry:
> - error = user_path_at(dfd, filename, lookup_flags, &path);
> + error = filename_lookup(dfd, name, lookup_flags, &path, NULL);
> if (error)
> goto out;
> error = mnt_want_write(path.mnt);
> @@ -829,6 +829,7 @@ int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,
> goto retry;
> }
> out:
> + putname(name);
> return error;
> }
>
> --
> 2.47.3
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR