[PATCH 4/4] xattrat: accept empty O_PATH file descriptors
From: Christian Brauner
Date: Mon Nov 30 2026 - 10:52:22 EST
From: Andreas Gruenbacher <agruenba@xxxxxxxxxx>
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@xxxxxxxxxx> 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@xxxxxxxxxx>
Link: https://patch.msgid.link/20260722151023.1308069-1-agruenba@xxxxxxxxxx
Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>
---
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