Re: [PATCH 1/4] xattr: don't route f*xattr() through the *xattrat() helpers

From: Andreas Gruenbacher

Date: Mon Nov 30 2026 - 13:03:22 EST


On Mon, 30 Nov 2026 at 16:52, Christian Brauner <brauner@xxxxxxxxxx> wrote:
> Commit 6140be90ec70 ("fs/xattr: add *at family syscalls") turned the
> f*xattr() system calls into *xattrat() calls with a NULL path and
> AT_EMPTY_PATH. Commit f520bed25d17 ("fs/xattr: Fix handling of AT_FDCWD
> in setxattrat(2) and getxattrat(2)") then made the helpers resolve
> AT_FDCWD with an empty path to the current working directory. So
> fsetxattr(AT_FDCWD, ...) and fgetxattr(AT_FDCWD, ...) now operate on
> the current working directory instead of failing with EBADF.
>
> Do what fchmod() and fchown() do and let the f*xattr() system calls
> resolve the file descriptor themselves. They never need a path lookup
> and the *xattrat() helpers are left to the path based system calls.
>
> Fixes: f520bed25d17 ("fs/xattr: Fix handling of AT_FDCWD in setxattrat(2) and getxattrat(2)")
> Cc: stable@xxxxxxxxxxxxxxx # v6.15+
> Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>

Reviewd-by: Andreas Gruenbacher <agruenba@xxxxxxxxxx>

> ---
> fs/xattr.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 56 insertions(+), 5 deletions(-)
>
> diff --git a/fs/xattr.c b/fs/xattr.c
> index 0705801a62cc5..8e7cceeb0d23c 100644
> --- a/fs/xattr.c
> +++ b/fs/xattr.c
> @@ -779,8 +779,27 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
> SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
> const void __user *,value, size_t, size, int, flags)
> {
> - return path_setxattrat(fd, NULL, AT_EMPTY_PATH, name,
> - value, size, flags);
> + struct xattr_name kname;
> + struct kernel_xattr_ctx ctx = {
> + .cvalue = value,
> + .kvalue = NULL,
> + .size = size,
> + .kname = &kname,
> + .flags = flags,
> + };
> + int error;
> +
> + CLASS(fd, f)(fd);
> + if (fd_empty(f))
> + return -EBADF;
> +
> + error = setxattr_copy(name, &ctx);
> + if (error)
> + return error;
> +
> + error = file_setxattr(fd_file(f), &ctx);
> + kvfree(ctx.kvalue);
> + return error;
> }
>
> /*
> @@ -918,7 +937,24 @@ SYSCALL_DEFINE4(lgetxattr, const char __user *, pathname,
> SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
> void __user *, value, size_t, size)
> {
> - return path_getxattrat(fd, NULL, AT_EMPTY_PATH, name, value, size);
> + struct xattr_name kname;
> + struct kernel_xattr_ctx ctx = {
> + .value = value,
> + .size = size,
> + .kname = &kname,
> + .flags = 0,
> + };
> + ssize_t error;
> +
> + CLASS(fd, f)(fd);
> + if (fd_empty(f))
> + return -EBADF;
> +
> + error = import_xattr_name(&kname, name);
> + if (error)
> + return error;
> +
> + return file_getxattr(fd_file(f), &ctx);
> }
>
> /*
> @@ -1022,7 +1058,11 @@ SYSCALL_DEFINE3(llistxattr, const char __user *, pathname, char __user *, list,
>
> SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
> {
> - return path_listxattrat(fd, NULL, AT_EMPTY_PATH, list, size);
> + CLASS(fd, f)(fd);
> + if (fd_empty(f))
> + return -EBADF;
> +
> + return file_listxattr(fd_file(f), list, size);
> }
>
> /*
> @@ -1117,7 +1157,18 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
>
> SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
> {
> - return path_removexattrat(fd, NULL, AT_EMPTY_PATH, name);
> + struct xattr_name kname;
> + int error;
> +
> + CLASS(fd, f)(fd);
> + if (fd_empty(f))
> + return -EBADF;
> +
> + error = import_xattr_name(&kname, name);
> + if (error)
> + return error;
> +
> + return file_removexattr(fd_file(f), &kname);
> }
>
> int xattr_list_one(char **buffer, ssize_t *remaining_size, const char *name)
>
> --
> 2.53.0
>