* [LTP] [PATCH] syscalls/xattr: Add runtime probe for socket xattr backports
@ 2026-06-01 10:13 Darren Chang via ltp
2026-06-01 13:35 ` [LTP] " linuxtestproject.agent
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Darren Chang via ltp @ 2026-06-01 10:13 UTC (permalink / raw)
To: ltp
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [LTP] syscalls/xattr: Add runtime probe for socket xattr backports 2026-06-01 10:13 [LTP] [PATCH] syscalls/xattr: Add runtime probe for socket xattr backports Darren Chang via ltp @ 2026-06-01 13:35 ` linuxtestproject.agent 2026-06-01 15:14 ` [LTP] [PATCH v2] " Darren Chang via ltp 2026-06-01 16:53 ` [LTP] [PATCH v3] " Darren Chang via ltp 2 siblings, 0 replies; 9+ messages in thread From: linuxtestproject.agent @ 2026-06-01 13:35 UTC (permalink / raw) To: Darren Chang; +Cc: ltp Hi Darren, Thank you for this patch. The approach is sound: a runtime probe for backported socket xattr support is the right way to avoid false failures on downstream kernels. However there are a few issues in fsetxattr02.c that need fixing before this can be applied. Verdict: Needs revision --- [1] fsetxattr02.c — variable declared after executable statement The new `int socket_idx = -1;` declaration appears after the executable statement `socket_xattr_supported = tst_kvercmp(7, 1, 0) >= 0;`. The existing setup() declares all its local variables at the top of the function (`size_t i = 0;` etc.). This new variable must follow the same convention. Move `int socket_idx = -1;` to the top of setup(), alongside the existing declarations: static void setup(void) { size_t i = 0; int socket_idx = -1; /* add here */ struct sockaddr_un sun; ... [2] fsetxattr02.c — indentation uses spaces instead of tabs The `int socket_idx = -1;` line in the patch uses 4 spaces for indentation instead of a tab character: - int socket_idx = -1; /* 4 spaces — wrong */ + int socket_idx = -1; /* tab — correct */ The rest of the function uses tabs throughout. [3] fsetxattr02.c — comment doesn't reference the upstream commit The comment added to fsetxattr02.c is vague compared to the one added to setxattr02.c, which names the upstream commit and its title: setxattr02.c (new): /* * 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. */ fsetxattr02.c (new): /* * Probe for backports on older kernels. * If the version is < 7.1.0 but fsetxattr() succeeds, we assume the patch * has been backported. */ These describe the same feature. The fsetxattr02 comment should include the commit reference for consistency. Use the same wording as in setxattr02.c. [4] fsetxattr02.c — inline comment is unnecessary /* Clean up the probed xattr to avoid interfering with the actual test */ SAFE_FREMOVEXATTR(tc[socket_idx].fd, tc[socket_idx].key); The comment states the obvious. SAFE_FREMOVEXATTR after a successful setxattr-probe speaks for itself. Drop it, matching the style of the equivalent block in setxattr02.c which has no such comment. --- Aside from those four points the logic is correct. In particular: - setxattr02.c looks clean; no issues there. - The probe correctly uses the already-opened socket fd in fsetxattr02, mirroring the path-based probe in setxattr02. - Silently ignoring non-zero probe results is correct: EPERM means no backport, and EOPNOTSUPP is caught later in verify_fsetxattr(). - `socket_xattr_supported = true` (using bool) is consistent with the field type (`static bool socket_xattr_supported`). - The commit message is accurate and the Signed-off-by is present. --- LTP AI Reviewer -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 9+ messages in thread
* [LTP] [PATCH v2] syscalls/xattr: Add runtime probe for socket xattr backports 2026-06-01 10:13 [LTP] [PATCH] syscalls/xattr: Add runtime probe for socket xattr backports Darren Chang via ltp 2026-06-01 13:35 ` [LTP] " linuxtestproject.agent @ 2026-06-01 15:14 ` Darren Chang via ltp 2026-06-01 16:03 ` [LTP] " linuxtestproject.agent 2026-06-01 16:53 ` [LTP] [PATCH v3] " Darren Chang via ltp 2 siblings, 1 reply; 9+ messages in thread From: Darren Chang via ltp @ 2026-06-01 15:14 UTC (permalink / raw) To: ltp 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 | 27 +++++++++++++++++++ .../kernel/syscalls/setxattr/setxattr02.c | 15 +++++++++++ 2 files changed, 42 insertions(+) diff --git a/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c b/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c index 2a48b7da7..985204480 100644 --- a/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c +++ b/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c @@ -209,6 +209,7 @@ static void verify_fsetxattr(unsigned int i) static void setup(void) { size_t i = 0; + int socket_idx = -1; struct sockaddr_un sun; dev_t dev = makedev(1, 3); @@ -245,6 +246,32 @@ static void setup(void) } 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) { + 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; + + 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..d85eb7246 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 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [LTP] syscalls/xattr: Add runtime probe for socket xattr backports 2026-06-01 15:14 ` [LTP] [PATCH v2] " Darren Chang via ltp @ 2026-06-01 16:03 ` linuxtestproject.agent 0 siblings, 0 replies; 9+ messages in thread From: linuxtestproject.agent @ 2026-06-01 16:03 UTC (permalink / raw) To: Darren Chang; +Cc: ltp Hi Darren, Thank you for this patch. The overall approach — using a runtime probe to detect backported socket xattr support rather than relying solely on the version check — is correct and useful for Android downstream kernels. A couple of issues to fix before merging: --- [COMMIT MESSAGE] > was merged in v7.1.0 > strictly expect EPERM for sockets on kernels < 7.1.0. Kernel mainline releases are tagged as "v7.1", not "v7.1.0". The sublevel ".0" is not part of the release tag. Please replace "v7.1.0" → "v7.1" and "7.1.0" → "7.1" throughout the commit message. --- [testcases/kernel/syscalls/fsetxattr/fsetxattr02.c] > + 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)"); Blank line between the opening brace and the first statement. Linux kernel coding style does not permit blank lines immediately after an opening '{'. Please remove the blank line. Also, the inline code comment (line just added in setup()) reads: > + * merged in 7.1.0 mainline, but might be backported. Same version notation issue: "7.1.0" → "7.1". --- [testcases/kernel/syscalls/setxattr/setxattr02.c] > + if (setxattr(SOCK, XATTR_TEST_KEY, XATTR_TEST_VALUE, > + XATTR_TEST_VALUE_SIZE, XATTR_CREATE) == 0) { > + > + tst_res(TINFO, "Socket xattr support detected (backport)"); Same blank-line-after-brace issue as in fsetxattr02.c. Remove the blank line. Also: > + * merged in 7.1.0 mainline, but might be backported. "7.1.0" → "7.1". --- Verdict: Needs revision Regards, LTP AI Reviewer -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 9+ messages in thread
* [LTP] [PATCH v3] syscalls/xattr: Add runtime probe for socket xattr backports 2026-06-01 10:13 [LTP] [PATCH] syscalls/xattr: Add runtime probe for socket xattr backports Darren Chang via ltp 2026-06-01 13:35 ` [LTP] " linuxtestproject.agent 2026-06-01 15:14 ` [LTP] [PATCH v2] " Darren Chang via ltp @ 2026-06-01 16:53 ` Darren Chang via ltp 2026-06-01 20:26 ` [LTP] " linuxtestproject.agent 2026-06-02 1:07 ` [LTP] [PATCH v4] " Darren Chang via ltp 2 siblings, 2 replies; 9+ messages in thread From: Darren Chang via ltp @ 2026-06-01 16:53 UTC (permalink / raw) To: ltp Upstream commit dc0876b9846d ("xattr: support extended attributes on sockets") was merged in v7.1. Currently, setxattr02 and fsetxattr02 strictly expect EPERM for sockets on kernels < 7.1. However, downstream kernels (e.g., Android mainline branches) often backport this feature to older kernel versions (such as 7.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 | 26 +++++++++++++++++++ .../kernel/syscalls/setxattr/setxattr02.c | 14 ++++++++++ 2 files changed, 40 insertions(+) diff --git a/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c b/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c index 2a48b7da7..1b4f8e819 100644 --- a/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c +++ b/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c @@ -209,6 +209,7 @@ static void verify_fsetxattr(unsigned int i) static void setup(void) { size_t i = 0; + int socket_idx = -1; struct sockaddr_un sun; dev_t dev = makedev(1, 3); @@ -245,6 +246,31 @@ static void setup(void) } socket_xattr_supported = tst_kvercmp(7, 1, 0) >= 0; + + /* + * Commit dc0876b9846d "xattr: support extended attributes on sockets" + * merged in 7.1 mainline, but might be backported. + * Try to set xattr on socket to detect support. + */ + 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; + + 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..167e068cf 100644 --- a/testcases/kernel/syscalls/setxattr/setxattr02.c +++ b/testcases/kernel/syscalls/setxattr/setxattr02.c @@ -196,6 +196,20 @@ 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 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 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [LTP] syscalls/xattr: Add runtime probe for socket xattr backports 2026-06-01 16:53 ` [LTP] [PATCH v3] " Darren Chang via ltp @ 2026-06-01 20:26 ` linuxtestproject.agent 2026-06-02 1:07 ` [LTP] [PATCH v4] " Darren Chang via ltp 1 sibling, 0 replies; 9+ messages in thread From: linuxtestproject.agent @ 2026-06-01 20:26 UTC (permalink / raw) To: Darren Chang; +Cc: ltp Hi Darren, Thank you for the patch. The approach is sound: using a runtime probe in setup() to detect a backported feature is the correct LTP pattern when a version check alone is insufficient. One issue needs fixing before merging. --- syscalls/xattr: Add runtime probe for socket xattr backports Commit message: OK > diff --git a/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c b/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c Lines 8-26 (/*\ description comment, not changed by the patch): /*\ * ... * - Set attribute to a UNIX domain socket, fsetxattr(2) should * return -1 and set errno to EPERM on kernels < 7.1.0. * On kernel 7.1.0+ (dc0876b9846d "xattr: support extended * attributes on sockets"), returns 0 (success) as sockets now * support user.* xattrs. */ The patch changes the socket test-case behavior for kernels < 7.1.0 with the backport, but does not update this description. After the patch there are three outcomes for the socket case: - kernel < 7.1.0, no backport → EPERM - kernel < 7.1.0, backport present → 0 (success, detected by probe) - kernel >= 7.1.0 → 0 (success) The comment currently describes only the first and third case. Please update it to mention the runtime probe for backported kernels. For example: * - Set attribute to a UNIX domain socket, fsetxattr(2) should * return -1 and set errno to EPERM on kernels < 7.1.0, unless the * feature is detected at runtime (e.g. backport). On kernel 7.1.0+ * (dc0876b9846d "xattr: support extended attributes on sockets"), * or when the backport is probed in setup(), returns 0 (success). Note: setxattr02.c uses "EPERM/SUCCEED" in its description which is already open-ended; no change is needed there. > + int socket_idx = -1; > ... > + for (i = 0; i < ARRAY_SIZE(tc); i++) { > + if (tc[i].issocket) { > + socket_idx = i; Nit: `socket_idx` is `int` but assigned from `size_t i`. Not a runtime problem here (small array), but declaring it as `size_t socket_idx` with `ARRAY_SIZE(tc)` as the "not found" sentinel would avoid the implicit narrowing. If you keep `int`, that is also acceptable given the tiny array size. > diff --git a/testcases/kernel/syscalls/setxattr/setxattr02.c b/testcases/kernel/syscalls/setxattr/setxattr02.c New probe code: OK. Clean and straightforward. --- Verdict: Needs revision 🔴 The description comment in fsetxattr02.c must be updated to reflect the three possible outcomes for the socket test case. Everything else is correct. LTP AI Reviewer -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 9+ messages in thread
* [LTP] [PATCH v4] syscalls/xattr: Add runtime probe for socket xattr backports 2026-06-01 16:53 ` [LTP] [PATCH v3] " Darren Chang via ltp 2026-06-01 20:26 ` [LTP] " linuxtestproject.agent @ 2026-06-02 1:07 ` Darren Chang via ltp 2026-06-02 4:06 ` [LTP] " linuxtestproject.agent 2026-06-03 10:34 ` [LTP] [PATCH v4] " Cyril Hrubis 1 sibling, 2 replies; 9+ messages in thread From: Darren Chang via ltp @ 2026-06-02 1:07 UTC (permalink / raw) To: ltp Upstream commit dc0876b9846d ("xattr: support extended attributes on sockets") was merged in v7.1. Currently, setxattr02 and fsetxattr02 strictly expect EPERM for sockets on kernels < 7.1. However, downstream kernels (e.g., Android mainline branches) often backport this feature to older kernel versions (such as 7.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 | 34 ++++++++++++++++--- .../kernel/syscalls/setxattr/setxattr02.c | 14 ++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c b/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c index 2a48b7da7..4a0997445 100644 --- a/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c +++ b/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c @@ -19,10 +19,10 @@ * - Set attribute to a block special file, fsetxattr(2) should * return -1 and set errno to EPERM. * - Set attribute to a UNIX domain socket, fsetxattr(2) should - * return -1 and set errno to EPERM on kernels < 7.1.0. - * On kernel 7.1.0+ (dc0876b9846d "xattr: support extended - * attributes on sockets"), returns 0 (success) as sockets now - * support user.* xattrs. + * return -1 and set errno to EPERM on kernels < 7.1, unless the + * feature is detected at runtime (e.g. backport). On kernel 7.1+ + * (dc0876b9846d "xattr: support extended attributes on sockets"), + * or when the backport is probed in setup(), returns 0 (success). */ /* @@ -209,6 +209,7 @@ static void verify_fsetxattr(unsigned int i) static void setup(void) { size_t i = 0; + size_t socket_idx = ARRAY_SIZE(tc); struct sockaddr_un sun; dev_t dev = makedev(1, 3); @@ -245,6 +246,31 @@ static void setup(void) } socket_xattr_supported = tst_kvercmp(7, 1, 0) >= 0; + + /* + * Commit dc0876b9846d "xattr: support extended attributes on sockets" + * merged in 7.1 mainline, but might be backported. + * Try to set xattr on socket to detect support. + */ + if (!socket_xattr_supported) { + for (i = 0; i < ARRAY_SIZE(tc); i++) { + if (tc[i].issocket) { + socket_idx = i; + break; + } + } + + if (socket_idx != ARRAY_SIZE(tc)) { + 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; + + 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..167e068cf 100644 --- a/testcases/kernel/syscalls/setxattr/setxattr02.c +++ b/testcases/kernel/syscalls/setxattr/setxattr02.c @@ -196,6 +196,20 @@ 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 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.929.g9b7fa37559-goog -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [LTP] syscalls/xattr: Add runtime probe for socket xattr backports 2026-06-02 1:07 ` [LTP] [PATCH v4] " Darren Chang via ltp @ 2026-06-02 4:06 ` linuxtestproject.agent 2026-06-03 10:34 ` [LTP] [PATCH v4] " Cyril Hrubis 1 sibling, 0 replies; 9+ messages in thread From: linuxtestproject.agent @ 2026-06-02 4:06 UTC (permalink / raw) To: Darren Chang; +Cc: ltp Hi Darren, On Tue, 02 Jun 2026 01:07:54 +0000, Darren Chang wrote: > syscalls/xattr: Add runtime probe for socket xattr backports > > Upstream commit dc0876b9846d ("xattr: support extended attributes on > sockets") was merged in v7.1. Nit: "merged in v7.1" uses the `v` prefix, but the rest of the commit message writes "7.1" (without `v`). LTP commit bodies should use a consistent notation. Either drop the `v` here ("merged in 7.1") or use it throughout. > Currently, setxattr02 and fsetxattr02 > strictly expect EPERM for sockets on kernels < 7.1. > > However, downstream kernels (e.g., Android mainline branches) often > backport this feature to older kernel versions (such as 7.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. The motivation and approach are clearly explained. Good. > Signed-off-by: Darren Chang <chihsheng@google.com> > > diff --git a/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c b/testcases/kernel/syscalls/fsetxattr/fsetxattr02.c > @@ -19,10 +19,10 @@ > * - Set attribute to a UNIX domain socket, fsetxattr(2) should > - * return -1 and set errno to EPERM on kernels < 7.1.0. > - * On kernel 7.1.0+ (dc0876b9846d "xattr: support extended > - * attributes on sockets"), returns 0 (success) as sockets now > - * support user.* xattrs. > + * return -1 and set errno to EPERM on kernels < 7.1, unless the > + * feature is detected at runtime (e.g. backport). On kernel 7.1+ > + * (dc0876b9846d "xattr: support extended attributes on sockets"), > + * or when the backport is probed in setup(), returns 0 (success). The updated doc comment in fsetxattr02.c accurately reflects the new behaviour, including the backport probe path. Good. > @@ -209,6 +209,7 @@ static void verify_fsetxattr(unsigned int i) > static void setup(void) > { > size_t i = 0; > + size_t socket_idx = ARRAY_SIZE(tc); Initialising socket_idx to ARRAY_SIZE(tc) as a sentinel before the search is correct and safe. > + if (!socket_xattr_supported) { > + for (i = 0; i < ARRAY_SIZE(tc); i++) { > + if (tc[i].issocket) { > + socket_idx = i; > + break; > + } > + } > + > + if (socket_idx != ARRAY_SIZE(tc)) { > + 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; > + > + SAFE_FREMOVEXATTR(tc[socket_idx].fd, tc[socket_idx].key); > + } > + } > + } The probe logic is correct: - It uses a raw fsetxattr() (not SAFE_) so EPERM does not abort. - On success it logs TINFO, sets the flag and removes the xattr with SAFE_FREMOVEXATTR before the test iterations run, so the subsequent XATTR_CREATE in verify_fsetxattr(6) finds a clean state. - On failure for any reason the flag stays false and the test conservatively expects EPERM. This is the right default. - The probe operates on the real, bound UNIX socket fd, which is the same fd used by the test, so there is no mismatch. > diff --git a/testcases/kernel/syscalls/setxattr/setxattr02.c b/testcases/kernel/syscalls/setxattr/setxattr02.c > @@ -196,6 +196,20 @@ 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 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); > + } > + } The setxattr02 probe is simpler (path-based, no fd to look up) and correct for the same reasons as the fsetxattr02 version. The mknod- created S_IFSOCK inode and a real bound socket are treated identically by the VFS xattr permission check that dc0876b9846d patches, so the probe is a valid detector for both path- and fd-based scenarios. Nit: the doc comment in setxattr02.c was not updated in parallel with fsetxattr02.c. The existing comment just says: - EPERM/SUCCEED - set attribute to a UNIX domain socket (dc0876b9846d ...) While "SUCCEED" technically covers the backport case, a reader will not learn that the SUCCEED outcome can now also be triggered on kernels < 7.1 via the runtime probe. fsetxattr02.c makes this explicit. Consider adding a line to the setxattr02.c comment such as: - EPERM/SUCCEED - set attribute to a UNIX domain socket (dc0876b9846d "xattr: support extended attributes on sockets"), SUCCEED also when the backport is probed at runtime in setup() --- Overall the approach is sound: probe only when the kernel version check says the feature is absent, use the real syscall interface, clean up after a successful probe, and fall back conservatively on any failure. Both tests are covered consistently. The two nits above (commit message `v7.1` wording and the missing update to the setxattr02.c doc comment) are minor; the code itself is correct. Verdict: Reviewed LTP AI Reviewer -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH v4] syscalls/xattr: Add runtime probe for socket xattr backports 2026-06-02 1:07 ` [LTP] [PATCH v4] " Darren Chang via ltp 2026-06-02 4:06 ` [LTP] " linuxtestproject.agent @ 2026-06-03 10:34 ` Cyril Hrubis 1 sibling, 0 replies; 9+ messages in thread From: Cyril Hrubis @ 2026-06-03 10:34 UTC (permalink / raw) To: Darren Chang; +Cc: ltp Hi! > socket_xattr_supported = tst_kvercmp(7, 1, 0) >= 0; > + > + /* > + * Commit dc0876b9846d "xattr: support extended attributes on sockets" > + * merged in 7.1 mainline, but might be backported. > + * Try to set xattr on socket to detect support. > + */ > + if (!socket_xattr_supported) { > + for (i = 0; i < ARRAY_SIZE(tc); i++) { > + if (tc[i].issocket) { > + socket_idx = i; > + break; > + } > + } > + > + if (socket_idx != ARRAY_SIZE(tc)) { > + 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; > + > + SAFE_FREMOVEXATTR(tc[socket_idx].fd, tc[socket_idx].key); > + } Instead of looking up the attribute in the array we can just create a socket, try ato add an attribute and remove the socked instead. With that we can up the code into a common header so that it's not duplicated int two testcases. I guess that the best place would be the lapi/socket.h header and we should add a static inline function socket_xattrs_supported() there. > + } > + } > } > > static void cleanup(void) > diff --git a/testcases/kernel/syscalls/setxattr/setxattr02.c b/testcases/kernel/syscalls/setxattr/setxattr02.c > index 994ab655d..167e068cf 100644 > --- a/testcases/kernel/syscalls/setxattr/setxattr02.c > +++ b/testcases/kernel/syscalls/setxattr/setxattr02.c > @@ -196,6 +196,20 @@ 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 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.929.g9b7fa37559-goog > -- Cyril Hrubis chrubis@suse.cz -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-06-03 10:35 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-06-01 10:13 [LTP] [PATCH] syscalls/xattr: Add runtime probe for socket xattr backports Darren Chang via ltp 2026-06-01 13:35 ` [LTP] " linuxtestproject.agent 2026-06-01 15:14 ` [LTP] [PATCH v2] " Darren Chang via ltp 2026-06-01 16:03 ` [LTP] " linuxtestproject.agent 2026-06-01 16:53 ` [LTP] [PATCH v3] " Darren Chang via ltp 2026-06-01 20:26 ` [LTP] " linuxtestproject.agent 2026-06-02 1:07 ` [LTP] [PATCH v4] " Darren Chang via ltp 2026-06-02 4:06 ` [LTP] " linuxtestproject.agent 2026-06-03 10:34 ` [LTP] [PATCH v4] " Cyril Hrubis
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox