From: Disha Goel <disgoel@linux.ibm.com>
To: shuah@kernel.org
Cc: brauner@kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, Disha Goel <disgoel@linux.ibm.com>
Subject: [PATCH v2 2/2] selftests/filesystems: allow security.selinux xattr in listxattr kernfs test
Date: Thu, 21 May 2026 15:47:57 +0530 [thread overview]
Message-ID: <20260521101758.14639-2-disgoel@linux.ibm.com> (raw)
In-Reply-To: <20260521101758.14639-1-disgoel@linux.ibm.com>
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.
Allow security.selinux xattr in kernfs_listxattr while continuing to
reject other unexpected xattrs. Keep the existing user.foo getxattr
check unchanged.
This avoids false failures on SELinux-enabled systems while preserving
the original purpose of the test.
Signed-off-by: Disha Goel <disgoel@linux.ibm.com>
---
.../selftests/filesystems/kernfs_test.c | 27 +++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/filesystems/kernfs_test.c b/tools/testing/selftests/filesystems/kernfs_test.c
index 84c2b910a60d..a5e480d662e0 100644
--- a/tools/testing/selftests/filesystems/kernfs_test.c
+++ b/tools/testing/selftests/filesystems/kernfs_test.c
@@ -4,6 +4,8 @@
#include <fcntl.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <sys/stat.h>
#include <sys/xattr.h>
@@ -12,12 +14,33 @@
TEST(kernfs_listxattr)
{
+ char *buf, *xattr;
+ ssize_t len, ret;
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, SELinux may set security.selinux xattr on kernfs files
+ * during policy load, so we explicitly ignore it.
+ */
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) {
+ buf = malloc(len);
+ ASSERT_NE(buf, NULL);
+
+ ret = flistxattr(fd, buf, len);
+ ASSERT_EQ(ret, len);
+
+ for (xattr = buf; xattr < buf + len; xattr += strlen(xattr) + 1)
+ ASSERT_EQ(strcmp(xattr, "security.selinux"), 0);
+
+ free(buf);
+ }
+
EXPECT_EQ(close(fd), 0);
}
--
2.45.1
next prev parent reply other threads:[~2026-05-21 10:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-21 10:17 [PATCH v2 1/2] selftests/filesystems: Move file_stressor to dedicated subdirectory Disha Goel
2026-05-21 10:17 ` Disha Goel [this message]
2026-06-15 5:19 ` [PATCH v2 2/2] selftests/filesystems: allow security.selinux xattr in listxattr kernfs test Ojaswin Mujoo
2026-06-17 11:18 ` Yeswanth Krishna
2026-06-15 5:12 ` [PATCH v2 1/2] selftests/filesystems: Move file_stressor to dedicated subdirectory Ojaswin Mujoo
2026-06-17 11:14 ` Yeswanth Krishna
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260521101758.14639-2-disgoel@linux.ibm.com \
--to=disgoel@linux.ibm.com \
--cc=brauner@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®