[PATCH v3 2/2] selftests/filesystems: skip listxattr kernfs test if xattrs are present
Disha Goel <[email protected]> Mon, 3 Aug 2026 20:38:37 +0530
| Newsgroups | org.kernel.vger.linux-kselftest,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> Signed-off-by: Disha Goel <[email protected]> --- 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/[email protected]/ .../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