[LTP] [PATCH v3 2/2] setxattr02: Adapt test for kernel 7.1.0+ socket xattr support
Jan Polensky
japo@linux.ibm.com
Mon Mar 16 13:27:25 CET 2026
Starting with kernel 7.1.0, sockets support extended attributes in the
user.* namespace. This behavior was enabled by dc0876b9846d ("xattr:
support extended attributes on sockets"), which permits user.* xattrs on
S_IFSOCK inodes (previously rejected with -EPERM).
Adapts the test to expect success (exp_err = 0) instead of EPERM when
testing setxattr(2) on sockets with kernel 7.1.0+.
Behavior:
- Kernel < 7.1.0: setxattr() on socket returns -EPERM (original behavior)
- Kernel >= 7.1.0: setxattr() on socket returns 0 (success, new behavior)
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
---
.../kernel/syscalls/setxattr/setxattr02.c | 20 ++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/setxattr/setxattr02.c b/testcases/kernel/syscalls/setxattr/setxattr02.c
index 9f5f998da9ba..c1996fb60d73 100644
--- a/testcases/kernel/syscalls/setxattr/setxattr02.c
+++ b/testcases/kernel/syscalls/setxattr/setxattr02.c
@@ -15,7 +15,8 @@
* - EPERM - set attribute to a FIFO
* - EPERM - set attribute to a char special file
* - EPERM - set attribute to a block special file
- * - EPERM - set attribute to a UNIX domain socket
+ * - EPERM/SUCCEED - set attribute to a UNIX domain socket (dc0876b9846d
+ * "xattr: support extended attributes on sockets")
*/
#include "config.h"
@@ -49,6 +50,8 @@
#define BLK "setxattr02blk"
#define SOCK "setxattr02sock"
+static bool socket_xattr_supported;
+
struct test_case {
char *fname;
char *key;
@@ -57,7 +60,16 @@ struct test_case {
int flags;
int exp_err;
int needskeyset;
+ void (*fix_errno)(struct test_case *tc);
};
+
+static void fix_sock(struct test_case *tc)
+{
+ /* dc0876b9846d ("xattr: support extended attributes on sockets") */
+ if (socket_xattr_supported)
+ tc->exp_err = 0;
+}
+
static struct test_case tc[] = {
{ /* case 00, set attr to reg */
.fname = FILENAME,
@@ -115,6 +127,7 @@ static struct test_case tc[] = {
.size = XATTR_TEST_VALUE_SIZE,
.flags = XATTR_CREATE,
.exp_err = EPERM,
+ .fix_errno = fix_sock,
},
};
@@ -126,6 +139,9 @@ static void verify_setxattr(unsigned int i)
XATTR_CREATE);
}
+ if (tc[i].fix_errno)
+ tc[i].fix_errno(&tc[i]);
+
TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value, tc[i].size,
tc[i].flags));
@@ -185,6 +201,8 @@ static void setup(void)
SAFE_MKNOD(CHR, S_IFCHR | 0777, dev);
SAFE_MKNOD(BLK, S_IFBLK | 0777, 0);
SAFE_MKNOD(SOCK, S_IFSOCK | 0777, 0);
+
+ socket_xattr_supported = (tst_kvercmp(7, 1, 0) >= 0);
}
static struct tst_test test = {
--
2.53.0
More information about the ltp
mailing list