* [PATCH v3 2/2] selftests/filesystems: skip listxattr kernfs test if xattrs are present
@ 2026-08-03 15:08 Disha Goel
0 siblings, 0 replies; only message in thread
From: Disha Goel @ 2026-08-03 15:08 UTC (permalink / raw)
To: shuah
Cc: brauner, cyphar, amir73il, jack, ojaswin, yeswanth,
linux-kselftest, linux-kernel, maddy, ritesh.list, Disha Goel
kernfs_test assumes that flistxattr() on /sys/kernel/warn_count always
returns an empty list. However, systems with SELinux enabled may expose
security.selinux xattr via listxattr() during policy load, which makes
the test fail even though kernfs is behaving correctly.
Skip the xattr content check if any xattrs are present, while still
verifying that flistxattr() succeeds (returns >= 0) on a kernfs file.
The existing user.foo getxattr check remains unchanged.
This avoids false failures on SELinux-enabled systems while preserving
the original purpose of the test.
Tested-by: Yeswanth Krishna <yeswanth@linux.ibm.com>
Signed-off-by: Disha Goel <disgoel@linux.ibm.com>
---
v2 -> v3
- Skip the xattr content check instead of allowlisting security.selinux,
as suggested by Ojaswin.
- Add Tested-by tag.
Link to v2: https://lore.kernel.org/all/20260521101758.14639-2-disgoel@linux.ibm.com/
.../testing/selftests/filesystems/kernfs_test.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/filesystems/kernfs_test.c b/tools/testing/selftests/filesystems/kernfs_test.c
index 84c2b910a60d..ca13646c9328 100644
--- a/tools/testing/selftests/filesystems/kernfs_test.c
+++ b/tools/testing/selftests/filesystems/kernfs_test.c
@@ -12,12 +12,24 @@
TEST(kernfs_listxattr)
{
+ ssize_t len;
int fd;
- /* Read-only file that can never have any extended attributes set. */
+ /* Read-only file that can never have any extended attributes set.
+ * However, on systems with SELinux enabled, security.selinux xattr
+ * may be present. Skip the content check if any xattrs are found.
+ */
fd = open("/sys/kernel/warn_count", O_RDONLY | O_CLOEXEC);
ASSERT_GE(fd, 0);
- ASSERT_EQ(flistxattr(fd, NULL, 0), 0);
+
+ len = flistxattr(fd, NULL, 0);
+ ASSERT_GE(len, 0);
+
+ if (len > 0) {
+ close(fd);
+ SKIP(return, "xattrs present on /sys/kernel/warn_count, skipping xattr content check");
+ }
+
EXPECT_EQ(close(fd), 0);
}
--
2.45.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-08-03 15:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-03 15:08 [PATCH v3 2/2] selftests/filesystems: skip listxattr kernfs test if xattrs are present Disha Goel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®