From: Disha Goel <disgoel@linux.ibm.com>
To: shuah@kernel.org
Cc: brauner@kernel.org, cyphar@cyphar.com, amir73il@gmail.com,
jack@suse.cz, ojaswin@linux.ibm.com, yeswanth@linux.ibm.com,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
maddy@linux.ibm.com, ritesh.list@gmail.com,
Disha Goel <disgoel@linux.ibm.com>
Subject: [PATCH v3 2/2] selftests/filesystems: skip listxattr kernfs test if xattrs are present
Date: Mon, 3 Aug 2026 20:38:37 +0530 [thread overview]
Message-ID: <20260803150837.91604-1-disgoel@linux.ibm.com> (raw)
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
reply other threads:[~2026-08-03 15:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260803150837.91604-1-disgoel@linux.ibm.com \
--to=disgoel@linux.ibm.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=cyphar@cyphar.com \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maddy@linux.ibm.com \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=shuah@kernel.org \
--cc=yeswanth@linux.ibm.com \
/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®