mirror of
https://github.com/torvalds/linux.git
synced 2026-09-11 20:13:02 +02:00
kernfs: preserve security xattrs without allocating iattrs
Commitd5e81a5650("kernfs: avoid iattr allocation in listxattr") made kernfs_iop_listxattr() return an empty list when the kernfs node has no allocated kernfs_iattrs. However, this also skips security xattr names provided by simple_xattr_list(). As of now, applications can retrieve the SELinux label of a sysfs file with getxattr(), but cannot do it through listxattr(). A similar issue happened before in commitb09e0fa4b4("tmpfs: implement generic xattr support"). It was fixed by commit8b0ba61df5("fs/xattr.c: fix simple_xattr_list to always include security.* xattrs"). Perhaps this recent commit needs a fix as well. The issue can be reproduced with a simple python program: python3 - <<'PY' import os path = "/sys/kernel/warn_count" print("getxattr:", os.getxattr(path, "security.selinux")) print("listxattr:", os.listxattr(path)) PY Before commitd5e81a5650("kernfs: avoid iattr allocation in listxattr"), the result is: getxattr: b'system_u:object_r:sysfs_t:s0\x00' listxattr: ['security.selinux'] After that commit, the result is: getxattr: b'system_u:object_r:sysfs_t:s0\x00' listxattr: [] This patch will keep listxattr() consistent with getxattr() when security xattrs are available. Fixes:d5e81a5650("kernfs: avoid iattr allocation in listxattr") Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu> Acked-by: Tejun Heo <tj@kernel.org> Link: https://patch.msgid.link/20260822051705.1761850-1-hengyul@cs.unc.edu Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
parent
bb3a94a682
commit
7b15d6cf25
|
|
@ -142,10 +142,8 @@ ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size)
|
|||
struct kernfs_iattrs *attrs;
|
||||
|
||||
attrs = kernfs_iattrs_noalloc(kn);
|
||||
if (!attrs)
|
||||
return 0;
|
||||
|
||||
return simple_xattr_list(d_inode(dentry), &attrs->xattrs, buf, size);
|
||||
return simple_xattr_list(d_inode(dentry), attrs ? &attrs->xattrs : NULL, buf, size);
|
||||
}
|
||||
|
||||
static inline void set_default_inode_attr(struct inode *inode, umode_t mode)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user