Skip to content

Commit 8b94775

Browse files
EliteTKopsiff
authored andcommitted
Revert "xattr: switch to CLASS(fd)"
This reverts commit 5a1e865e51063d6c56f673ec8ad4b6604321b455 which is commit a718743 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> Tested-by: Barry K. Nathan <barryn@pobox.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit 16d41d32b7c76f547f98932f2d1e4b6ae2c0666c) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent a2f6f01 commit 8b94775

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

fs/xattr.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
704704
int error;
705705

706706
CLASS(fd, f)(fd);
707+
if (!f.file)
708+
return -EBADF;
707709

708710
audit_file(f.file);
709711
error = setxattr_copy(name, &ctx);
@@ -814,11 +816,16 @@ SYSCALL_DEFINE4(lgetxattr, const char __user *, pathname,
814816
SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
815817
void __user *, value, size_t, size)
816818
{
817-
CLASS(fd, f)(fd);
819+
struct fd f = fdget(fd);
820+
ssize_t error = -EBADF;
818821

822+
if (!f.file)
823+
return error;
819824
audit_file(f.file);
820-
return getxattr(file_mnt_idmap(f.file), f.file->f_path.dentry,
825+
error = getxattr(file_mnt_idmap(f.file), f.file->f_path.dentry,
821826
name, value, size);
827+
fdput(f);
828+
return error;
822829
}
823830

824831
/*
@@ -885,10 +892,15 @@ SYSCALL_DEFINE3(llistxattr, const char __user *, pathname, char __user *, list,
885892

886893
SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
887894
{
888-
CLASS(fd, f)(fd);
895+
struct fd f = fdget(fd);
896+
ssize_t error = -EBADF;
889897

898+
if (!f.file)
899+
return error;
890900
audit_file(f.file);
891-
return listxattr(f.file->f_path.dentry, list, size);
901+
error = listxattr(f.file->f_path.dentry, list, size);
902+
fdput(f);
903+
return error;
892904
}
893905

894906
/*
@@ -951,10 +963,12 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
951963

952964
SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
953965
{
954-
CLASS(fd, f)(fd);
966+
struct fd f = fdget(fd);
955967
char kname[XATTR_NAME_MAX + 1];
956-
int error;
968+
int error = -EBADF;
957969

970+
if (!f.file)
971+
return error;
958972
audit_file(f.file);
959973

960974
error = strncpy_from_user(kname, name, sizeof(kname));
@@ -969,6 +983,7 @@ SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
969983
f.file->f_path.dentry, kname);
970984
mnt_drop_write_file(f.file);
971985
}
986+
fdput(f);
972987
return error;
973988
}
974989

0 commit comments

Comments
 (0)