From: Tomasz Kramkowski <tomasz@kramkow.ski>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, stable@vger.kernel.org
Cc: Christian Brauner <brauner@kernel.org>,
linux-fsdevel@vger.kernel.org,
Tomasz Kramkowski <tomasz@kramkow.ski>,
Brad Spengler <spender@grsecurity.net>,
Alva Lan <alvalan9@foxmail.com>,
Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH] Revert "xattr: switch to CLASS(fd)"
Date: Sat, 4 Apr 2026 12:22:19 +0100 [thread overview]
Message-ID: <20260404112219.389495-1-tomasz@kramkow.ski> (raw)
This reverts commit 5a1e865e51063d6c56f673ec8ad4b6604321b455 which is
commit a71874379ec8c6e788a61d71b3ad014a8d9a5c08 upstream.
A backporting mistake erroneously removed file descriptor checks for
`fgetxattr`, `flistxattr`, `fremovexattr`, and `fsetxattr` which lead to
kernel panics when those functions were called from userspace with a
file descriptor which did not reference an open file.
Reported-by: Brad Spengler <spender@grsecurity.net>
Closes: https://x.com/spendergrsec/status/2040049852793450561
Cc: Alva Lan <alvalan9@foxmail.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Tomasz Kramkowski <tomasz@kramkow.ski>
---
Was asked to send a revert instead of a fix. Previous patch was here:
https://lore.kernel.org/stable/20260403230636.344097-1-tomasz@kramkow.ski/
Tested via qemu to verify the fix and ensure there were no unexpected
consequences.
I was made aware of this after being shown a screenshot from Brad
Spengler's twitter feed. I looked around for other reverts and tried to
match the trailers.
fs/xattr.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/fs/xattr.c b/fs/xattr.c
index 5f2d74332ea6..7574d24b982e 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -698,6 +698,8 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
int error;
CLASS(fd, f)(fd);
+ if (!f.file)
+ return -EBADF;
audit_file(f.file);
error = setxattr_copy(name, &ctx);
@@ -808,11 +810,16 @@ SYSCALL_DEFINE4(lgetxattr, const char __user *, pathname,
SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
void __user *, value, size_t, size)
{
- CLASS(fd, f)(fd);
+ struct fd f = fdget(fd);
+ ssize_t error = -EBADF;
+ if (!f.file)
+ return error;
audit_file(f.file);
- return getxattr(file_mnt_idmap(f.file), f.file->f_path.dentry,
+ error = getxattr(file_mnt_idmap(f.file), f.file->f_path.dentry,
name, value, size);
+ fdput(f);
+ return error;
}
/*
@@ -879,10 +886,15 @@ SYSCALL_DEFINE3(llistxattr, const char __user *, pathname, char __user *, list,
SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
{
- CLASS(fd, f)(fd);
+ struct fd f = fdget(fd);
+ ssize_t error = -EBADF;
+ if (!f.file)
+ return error;
audit_file(f.file);
- return listxattr(f.file->f_path.dentry, list, size);
+ error = listxattr(f.file->f_path.dentry, list, size);
+ fdput(f);
+ return error;
}
/*
@@ -939,10 +951,12 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
{
- CLASS(fd, f)(fd);
+ struct fd f = fdget(fd);
char kname[XATTR_NAME_MAX + 1];
- int error;
+ int error = -EBADF;
+ if (!f.file)
+ return error;
audit_file(f.file);
error = strncpy_from_user(kname, name, sizeof(kname));
@@ -957,6 +971,7 @@ SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
f.file->f_path.dentry, kname);
mnt_drop_write_file(f.file);
}
+ fdput(f);
return error;
}
--
2.51.0
next reply other threads:[~2026-04-04 11:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-04 11:22 Tomasz Kramkowski [this message]
2026-04-04 12:11 ` [PATCH] Revert "xattr: switch to CLASS(fd)" Tomasz Kramkowski
2026-04-05 5:32 ` Greg Kroah-Hartman
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=20260404112219.389495-1-tomasz@kramkow.ski \
--to=tomasz@kramkow.ski \
--cc=alvalan9@foxmail.com \
--cc=brauner@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=spender@grsecurity.net \
--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