Linux driver-core infrastructure
 help / color / mirror / Atom feed
* [PATCH v2] kernfs: preserve security xattrs without allocating iattrs
@ 2026-08-22  5:17 hengyul
  2026-09-01 16:17 ` Danilo Krummrich
  0 siblings, 1 reply; 2+ messages in thread
From: hengyul @ 2026-08-22  5:17 UTC (permalink / raw)
  To: chenyichong, tj, dakr, gregkh; +Cc: driver-core, linux-kernel

From: Hengyu Liang <hengyul@cs.unc.edu>

Commit d5e81a5650b5 ("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 commit b09e0fa4b4ea ("tmpfs:
implement generic xattr support"). It was fixed by commit 8b0ba61df5a1c
("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 commit d5e81a5650b5 ("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: d5e81a5650b5 ("kernfs: avoid iattr allocation in listxattr")
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
Acked-by: Tejun Heo <tj@kernel.org>
---

Changes in v2:
- Remove an unnecessary line break.

v1: https://lore.kernel.org/driver-core/20260821161221.1270292-1-hengyul@cs.unc.edu/

 fs/kernfs/inode.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c
index 237dcdd73fc2..abb286bc3474 100644
--- a/fs/kernfs/inode.c
+++ b/fs/kernfs/inode.c
@@ -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)
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] kernfs: preserve security xattrs without allocating iattrs
  2026-08-22  5:17 [PATCH v2] kernfs: preserve security xattrs without allocating iattrs hengyul
@ 2026-09-01 16:17 ` Danilo Krummrich
  0 siblings, 0 replies; 2+ messages in thread
From: Danilo Krummrich @ 2026-09-01 16:17 UTC (permalink / raw)
  To: hengyul; +Cc: chenyichong, tj, dakr, gregkh, driver-core, linux-kernel

On Sat, 22 Aug 2026 01:17:05 -0400, hengyul@cs.unc.edu wrote:
> [PATCH v2] kernfs: preserve security xattrs without allocating iattrs

Applied, thanks!

  Branch: driver-core-linus
  Tree:   git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git

[1/1] kernfs: preserve security xattrs without allocating iattrs
      commit: 7b15d6cf25e6

The patch will appear in the next linux-next integration (typically within 24
hours on weekdays).

The patch is queued up for Linus's tree and should land in the next -rc release.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-01 16:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-22  5:17 [PATCH v2] kernfs: preserve security xattrs without allocating iattrs hengyul
2026-09-01 16:17 ` Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox