[LTP] [PATCH] syscalls/xattr: Add runtime probe for socket xattr backports
Darren Chang
chihsheng@google.com
Mon Jun 1 12:13:02 CEST 2026
Upstream commit dc0876b9846d ("xattr: support extended attributes on
sockets") was merged in v7.1.0. Currently, setxattr02 and fsetxattr02
strictly expect EPERM for sockets on kernels < 7.1.0.
However, downstream kernels (e.g., Android mainline branches) often
backport this feature to older kernel versions (such as 7.0.0). On
these kernels, the strict version check causes a false positive failure:
"passed unexpectedly".
This patch introduces a runtime probe in setup() for both tests to
detect if older kernels have the backported feature. If the xattr
syscalls succeed on a socket during setup, we assume the patch is
present and adjust the expected result to pass.
Signed-off-by: Darren Chang <chihsheng@google.com>
---
.../kernel/syscalls/fsetxattr/fsetxattr02.c | 28 +++++++++++++++++++
.../kernel/syscalls/setxattr/setxattr02.c | 15 ++++++++++
2 files changed, 43 insertions(+)
diff --git a/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c b/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c
index 2a48b7da7..ddb1804c8 100644
--- a/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c
+++ b/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c
@@ -245,6 +245,34 @@ static void setup(void)
}
socket_xattr_supported = tst_kvercmp(7, 1, 0) >= 0;
+
+ /*
+ * Probe for backports on older kernels.
+ * If the version is < 7.1.0 but fsetxattr() succeeds, we assume the patch
+ * has been backported.
+ */
+ int socket_idx = -1;
+ if (!socket_xattr_supported) {
+ for (i = 0; i < ARRAY_SIZE(tc); i++) {
+ if (tc[i].issocket) {
+ socket_idx = i;
+ break;
+ }
+ }
+
+ if (socket_idx != -1) {
+ if (fsetxattr(tc[socket_idx].fd, tc[socket_idx].key,
+ tc[socket_idx].value, tc[socket_idx].size,
+ tc[socket_idx].flags) == 0) {
+
+ tst_res(TINFO, "Socket xattr support detected (backport)");
+ socket_xattr_supported = true;
+
+ /* Clean up the probed xattr to avoid interfering with the actual test */
+ SAFE_FREMOVEXATTR(tc[socket_idx].fd, tc[socket_idx].key);
+ }
+ }
+ }
}
static void cleanup(void)
diff --git a/testcases/kernel/syscalls/setxattr/setxattr02.c b/testcases/kernel/syscalls/setxattr/setxattr02.c
index 994ab655d..94d1024e6 100644
--- a/testcases/kernel/syscalls/setxattr/setxattr02.c
+++ b/testcases/kernel/syscalls/setxattr/setxattr02.c
@@ -196,6 +196,21 @@ static void setup(void)
SAFE_MKNOD(SOCK, S_IFSOCK | 0777, 0);
socket_xattr_supported = tst_kvercmp(7, 1, 0) >= 0;
+
+ /*
+ * Commit dc0876b9846d "xattr: support extended attributes on sockets"
+ * merged in 7.1.0 mainline, but might be backported.
+ * Try to set xattr on socket to detect support.
+ */
+ if (!socket_xattr_supported) {
+ if (setxattr(SOCK, XATTR_TEST_KEY, XATTR_TEST_VALUE,
+ XATTR_TEST_VALUE_SIZE, XATTR_CREATE) == 0) {
+
+ tst_res(TINFO, "Socket xattr support detected (backport)");
+ socket_xattr_supported = true;
+ SAFE_REMOVEXATTR(SOCK, XATTR_TEST_KEY);
+ }
+ }
}
static struct tst_test test = {
--
2.54.0.1013.g208068f2d8-goog
More information about the ltp
mailing list