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>
Subject: [PATCH 4/4] xattrat: accept empty O_PATH file descriptors
Date: Mon, 30 Nov 2026 16:51:40 +0100 [thread overview]
Message-ID: <20261130-work-xattr-at_fdcwd-misc-v1-4-ab8a1727f992@kernel.org> (raw)
In-Reply-To: <20261130-work-xattr-at_fdcwd-misc-v1-0-ab8a1727f992@kernel.org>
From: Andreas Gruenbacher <agruenba@redhat.com>
Currently, the setxattrat(), getxattrat(), listxattrat(), and removexattrat()
system calls fail with -EBADF when dfd is an O_PATH file descriptor, pathname
is an empty string or NULL, and the AT_EMPTY_PATH flag is set in at_flags.
This is inconsistent with the behavior of other system calls like fstatat() and
fchmodat() which do accept O_PATH file descriptors, so change the *xattrat()
system calls to accept O_PATH file descriptors as well.
In environments where /proc is available, operations on O_PATH file descriptors
can also be carried out by using "/proc/self/fd/<dfd>" as the pathname, so from
a security standpoint, this is a relatively insignificant change.
We stick with the existing practice of leaving the behavior of the fsetxattr(),
fgetxattr(), flistxattr(), and fremovexattr() system calls unchanged: those
will still reject O_PATH file descriptors.
Christian Brauner <brauner@kernel.org> says:
The f*xattr() system calls don't go through the *xattrat() helpers
anymore. So the helpers can simply use CLASS(fd_raw) and the
fd_maybe_raw class isn't needed.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Link: https://patch.msgid.link/20260722151023.1308069-1-agruenba@redhat.com
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
fs/xattr.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/xattr.c b/fs/xattr.c
index 0c59dfcbe6958..1866618ecf723 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -725,7 +725,7 @@ static int path_setxattrat(int dfd, const char __user *pathname,
CLASS(filename_maybe_null, filename)(pathname, at_flags);
if (!filename && dfd >= 0) {
- CLASS(fd, f)(dfd);
+ CLASS(fd_raw, f)(dfd);
if (fd_empty(f))
error = -EBADF;
else
@@ -884,7 +884,7 @@ static ssize_t path_getxattrat(int dfd, const char __user *pathname,
CLASS(filename_maybe_null, filename)(pathname, at_flags);
if (!filename && dfd >= 0) {
- CLASS(fd, f)(dfd);
+ CLASS(fd_raw, f)(dfd);
if (fd_empty(f))
return -EBADF;
return file_getxattr(fd_file(f), &ctx);
@@ -1027,7 +1027,7 @@ static ssize_t path_listxattrat(int dfd, const char __user *pathname,
CLASS(filename_maybe_null, filename)(pathname, at_flags);
if (!filename && dfd >= 0) {
- CLASS(fd, f)(dfd);
+ CLASS(fd_raw, f)(dfd);
if (fd_empty(f))
return -EBADF;
return file_listxattr(fd_file(f), list, size);
@@ -1128,7 +1128,7 @@ static int path_removexattrat(int dfd, const char __user *pathname,
CLASS(filename_maybe_null, filename)(pathname, at_flags);
if (!filename && dfd >= 0) {
- CLASS(fd, f)(dfd);
+ CLASS(fd_raw, f)(dfd);
if (fd_empty(f))
return -EBADF;
return file_removexattr(fd_file(f), &kname);
--
2.53.0
next prev parent 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 ` [PATCH 1/4] xattr: don't route f*xattr() through the *xattrat() helpers Christian Brauner
2026-11-30 18:02 ` 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 ` Christian Brauner [this message]
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-4-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=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®