mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org
Cc: "Andreas Gruenbacher" <agruenba@redhat.com>,
	"Jan Kara" <jack@suse.cz>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Christian Göttsche" <cgzones@googlemail.com>,
	linux-kernel@vger.kernel.org,
	"Christian Brauner (Amutable)" <brauner@kernel.org>,
	stable@vger.kernel.org
Subject: [PATCH 1/4] xattr: don't route f*xattr() through the *xattrat() helpers
Date: Mon, 30 Nov 2026 16:51:37 +0100	[thread overview]
Message-ID: <20261130-work-xattr-at_fdcwd-misc-v1-1-ab8a1727f992@kernel.org> (raw)
In-Reply-To: <20261130-work-xattr-at_fdcwd-misc-v1-0-ab8a1727f992@kernel.org>

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@vger.kernel.org # v6.15+
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 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


  reply	other threads:[~2026-11-30 15:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 15:51 [PATCH 0/4] xattr: fix AT_FDCWD handling Christian Brauner
2026-11-30 15:51 ` Christian Brauner [this message]
2026-11-30 18:02   ` [PATCH 1/4] xattr: don't route f*xattr() through the *xattrat() helpers Andreas Gruenbacher
2026-11-30 15:51 ` [PATCH 2/4] xattr: let listxattrat() and removexattrat() handle AT_FDCWD Christian Brauner
2026-11-30 18:03   ` Andreas Gruenbacher
2026-11-30 18:04   ` Andreas Gruenbacher
2026-11-30 15:51 ` [PATCH 3/4] selftests/xattr: add AT_FDCWD tests Christian Brauner
2026-11-30 15:51 ` [PATCH 4/4] xattrat: accept empty O_PATH file descriptors Christian Brauner
2026-11-30 18:05 ` [PATCH 0/4] xattr: fix AT_FDCWD handling Andreas Gruenbacher

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=20261130-work-xattr-at_fdcwd-misc-v1-1-ab8a1727f992@kernel.org \
    --to=brauner@kernel.org \
    --cc=agruenba@redhat.com \
    --cc=cgzones@googlemail.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®