* [LTP] [PATCH 0/8] setxattrat coverage
@ 2025-01-27 14:08 Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 1/8] syscalls: add *xattrat syscalls Andrea Cervesato
` (7 more replies)
0 siblings, 8 replies; 12+ messages in thread
From: Andrea Cervesato @ 2025-01-27 14:08 UTC (permalink / raw)
To: ltp
This is a patch-set meant to cover setxattrat() syscalls scenarios.
There are two parts:
- cover errors and features which are already tested for setxattr()
by adding a new setxattrat() test variant to setxattr() testing
suite
- cover errors which are strictly related to the setxattrat() syscall
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Andrea Cervesato (8):
syscalls: add *xattrat syscalls
lapi: add struct xattr_args fallback
setxattr01: add setxattrat variant
setxattr02: add setxattrat variant
setxattr03: add setxattrat variant
lapi: add safe *xattrat macros
Add setxattrat01 test
Add setxattrat02 test
configure.ac | 1 +
include/lapi/syscalls/arc.in | 4 +
include/lapi/syscalls/arm.in | 4 +
include/lapi/syscalls/arm64.in | 4 +
include/lapi/syscalls/i386.in | 4 +
include/lapi/syscalls/loongarch64.in | 4 +
include/lapi/syscalls/mips64.in | 4 +
include/lapi/syscalls/mips64n32.in | 4 +
include/lapi/syscalls/mipso32.in | 4 +
include/lapi/syscalls/parisc.in | 4 +
include/lapi/syscalls/powerpc.in | 4 +
include/lapi/syscalls/powerpc64.in | 4 +
include/lapi/syscalls/s390.in | 4 +
include/lapi/syscalls/s390x.in | 4 +
include/lapi/syscalls/sh.in | 4 +
include/lapi/syscalls/sparc.in | 4 +
include/lapi/syscalls/sparc64.in | 4 +
include/lapi/syscalls/x86_64.in | 4 +
include/lapi/xattr.h | 117 ++++++++++++++++
testcases/kernel/syscalls/setxattr/setxattr01.c | 53 ++++++--
testcases/kernel/syscalls/setxattr/setxattr02.c | 71 ++++++++--
testcases/kernel/syscalls/setxattr/setxattr03.c | 25 +++-
testcases/kernel/syscalls/setxattrat/.gitignore | 2 +
testcases/kernel/syscalls/setxattrat/Makefile | 8 ++
.../kernel/syscalls/setxattrat/setxattrat01.c | 151 +++++++++++++++++++++
.../kernel/syscalls/setxattrat/setxattrat02.c | 126 +++++++++++++++++
26 files changed, 597 insertions(+), 25 deletions(-)
---
base-commit: de17245aa04e4cdfacc9f84893ba78a1f029cc2a
change-id: 20250121-xattrat-1b1653ccea31
Best regards,
--
Andrea Cervesato <andrea.cervesato@suse.com>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 12+ messages in thread
* [LTP] [PATCH 1/8] syscalls: add *xattrat syscalls
2025-01-27 14:08 [LTP] [PATCH 0/8] setxattrat coverage Andrea Cervesato
@ 2025-01-27 14:08 ` Andrea Cervesato
2025-01-31 9:09 ` Petr Vorel
2025-01-27 14:08 ` [LTP] [PATCH 2/8] lapi: add struct xattr_args fallback Andrea Cervesato
` (6 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Andrea Cervesato @ 2025-01-27 14:08 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Add following syscalls:
- setxattrat
- getxattrat
- listxattrat
- removexattrat
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/lapi/syscalls/arc.in | 4 ++++
include/lapi/syscalls/arm.in | 4 ++++
include/lapi/syscalls/arm64.in | 4 ++++
include/lapi/syscalls/i386.in | 4 ++++
include/lapi/syscalls/loongarch64.in | 4 ++++
include/lapi/syscalls/mips64.in | 4 ++++
include/lapi/syscalls/mips64n32.in | 4 ++++
include/lapi/syscalls/mipso32.in | 4 ++++
include/lapi/syscalls/parisc.in | 4 ++++
include/lapi/syscalls/powerpc.in | 4 ++++
include/lapi/syscalls/powerpc64.in | 4 ++++
include/lapi/syscalls/s390.in | 4 ++++
include/lapi/syscalls/s390x.in | 4 ++++
include/lapi/syscalls/sh.in | 4 ++++
include/lapi/syscalls/sparc.in | 4 ++++
include/lapi/syscalls/sparc64.in | 4 ++++
include/lapi/syscalls/x86_64.in | 4 ++++
17 files changed, 68 insertions(+)
diff --git a/include/lapi/syscalls/arc.in b/include/lapi/syscalls/arc.in
index f680d4119c10f73e2f1b8938c3be4a7254965ed0..5eff428f30b8cf4395edffbd3a002e6a6cad22b9 100644
--- a/include/lapi/syscalls/arc.in
+++ b/include/lapi/syscalls/arc.in
@@ -340,3 +340,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in
index 32e48b2151afbf55a19e493518395e4265c670a0..1e8732b4be1a7c94d5ba46d1466cad6809bfc298 100644
--- a/include/lapi/syscalls/arm.in
+++ b/include/lapi/syscalls/arm.in
@@ -413,3 +413,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
diff --git a/include/lapi/syscalls/arm64.in b/include/lapi/syscalls/arm64.in
index be7e9df6480c065ff63345d55082b1a6b2532760..f5c3653e7ee7433ca6bf06748064835bd9f4e857 100644
--- a/include/lapi/syscalls/arm64.in
+++ b/include/lapi/syscalls/arm64.in
@@ -316,3 +316,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in
index 13f72e7950ded9393e665cb1a44fe955343f820c..32f85a36cb56c4a9e176f7a18a0bf48ad91cb923 100644
--- a/include/lapi/syscalls/i386.in
+++ b/include/lapi/syscalls/i386.in
@@ -447,3 +447,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
diff --git a/include/lapi/syscalls/loongarch64.in b/include/lapi/syscalls/loongarch64.in
index 2c1ecd7aeeb2fa4f38999bad144cfceee39a4a54..70b8033ae561d147b5a94e5363a5e284a96fdba5 100644
--- a/include/lapi/syscalls/loongarch64.in
+++ b/include/lapi/syscalls/loongarch64.in
@@ -312,3 +312,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
diff --git a/include/lapi/syscalls/mips64.in b/include/lapi/syscalls/mips64.in
index 8be734158fb7840b7757a012b6ed823f29eb7ab9..27e3fd168f22e38e6ac01794b1cc3c19a5834978 100644
--- a/include/lapi/syscalls/mips64.in
+++ b/include/lapi/syscalls/mips64.in
@@ -362,3 +362,7 @@ lsm_get_self_attr 5459
lsm_set_self_attr 5460
lsm_list_modules 5461
mseal 5462
+setxattrat 5463
+getxattrat 5464
+listxattrat 5465
+removexattrat 5466
diff --git a/include/lapi/syscalls/mips64n32.in b/include/lapi/syscalls/mips64n32.in
index 153fe50bf9a7c62978e458e1cb7225aa63b9edda..6f41bf200fd705a791925bedd2881a6633f5e191 100644
--- a/include/lapi/syscalls/mips64n32.in
+++ b/include/lapi/syscalls/mips64n32.in
@@ -386,3 +386,7 @@ lsm_get_self_attr 6459
lsm_set_self_attr 6460
lsm_list_modules 6461
mseal 6462
+setxattrat 6463
+getxattrat 6464
+listxattrat 6465
+removexattrat 6466
diff --git a/include/lapi/syscalls/mipso32.in b/include/lapi/syscalls/mipso32.in
index 1ed74c1ecf281a3d208eded4a0dbd35fcc57e45f..c97e7d952d880ec7470e1e0d971b53f1daabc5c7 100644
--- a/include/lapi/syscalls/mipso32.in
+++ b/include/lapi/syscalls/mipso32.in
@@ -426,3 +426,7 @@ lsm_get_self_attr 4459
lsm_set_self_attr 4460
lsm_list_modules 4461
mseal 4462
+setxattrat 4463
+getxattrat 4464
+listxattrat 4465
+removexattrat 4466
diff --git a/include/lapi/syscalls/parisc.in b/include/lapi/syscalls/parisc.in
index 662bfea4428cf3b090b03632f2087251aaf3b513..87508325bf263896bbfb2e1dcfbe2c2700ce7645 100644
--- a/include/lapi/syscalls/parisc.in
+++ b/include/lapi/syscalls/parisc.in
@@ -395,3 +395,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in
index faaa75883a7d2a0b70ca0e8064b6c91dae21d20c..9be82e6d2084b4a57ff11c8bf4be6510224b27c6 100644
--- a/include/lapi/syscalls/powerpc.in
+++ b/include/lapi/syscalls/powerpc.in
@@ -437,3 +437,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in
index 23b65e7840869c0cc08559324271b3b0d865ac01..756f224c48ef97459c0e61ab7d6721db4abae7df 100644
--- a/include/lapi/syscalls/powerpc64.in
+++ b/include/lapi/syscalls/powerpc64.in
@@ -409,3 +409,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in
index 69d7408b7bdf0d9019d3c319cd52ff48022aca39..5f17ed825841698e88807c03f06a260b8aaf8628 100644
--- a/include/lapi/syscalls/s390.in
+++ b/include/lapi/syscalls/s390.in
@@ -430,3 +430,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in
index fa98054c732787b62528c71f60b04de490b98958..cf7866fdb5ecc3c6412af29e7359feb56da44983 100644
--- a/include/lapi/syscalls/s390x.in
+++ b/include/lapi/syscalls/s390x.in
@@ -378,3 +378,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in
index 2e584253c61d51b140c3b2f586e3c49e5740e7af..4dc31daaaa4b777715e0dec4faf9835329f5f355 100644
--- a/include/lapi/syscalls/sh.in
+++ b/include/lapi/syscalls/sh.in
@@ -424,3 +424,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in
index fcdb9b812ee6844d4981550f3eeed7ff081852f8..094170372b6ca261129b5c82979d5895d0029e51 100644
--- a/include/lapi/syscalls/sparc.in
+++ b/include/lapi/syscalls/sparc.in
@@ -428,3 +428,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in
index 4256aaf77674ed0c00bbd092d7c715038e52f1c3..16509d27794d4c36d508ec433e6bfbbbc05f064f 100644
--- a/include/lapi/syscalls/sparc64.in
+++ b/include/lapi/syscalls/sparc64.in
@@ -391,3 +391,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in
index e6c0a3b4047d60e0e372c023c8f6a9bab76697af..458748a995764cd046558164799d07b7cd6e79f9 100644
--- a/include/lapi/syscalls/x86_64.in
+++ b/include/lapi/syscalls/x86_64.in
@@ -373,3 +373,7 @@ lsm_get_self_attr 459
lsm_set_self_attr 460
lsm_list_modules 461
mseal 462
+setxattrat 463
+getxattrat 464
+listxattrat 465
+removexattrat 466
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [LTP] [PATCH 2/8] lapi: add struct xattr_args fallback
2025-01-27 14:08 [LTP] [PATCH 0/8] setxattrat coverage Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 1/8] syscalls: add *xattrat syscalls Andrea Cervesato
@ 2025-01-27 14:08 ` Andrea Cervesato
2025-01-31 8:36 ` Petr Vorel
2025-01-27 14:08 ` [LTP] [PATCH 3/8] setxattr01: add setxattrat variant Andrea Cervesato
` (5 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Andrea Cervesato @ 2025-01-27 14:08 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
configure.ac | 1 +
include/lapi/xattr.h | 19 +++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/configure.ac b/configure.ac
index 6992d75ca300ccc4cc21a45a916f6b3be1a3b8fe..eb1a966322313cf785c25af0f317700418186927 100644
--- a/configure.ac
+++ b/configure.ac
@@ -247,6 +247,7 @@ AC_CHECK_TYPES([struct cachestat_range],,,[#include <sys/mman.h>])
AC_CHECK_TYPES([struct cachestat],,,[#include <sys/mman.h>])
AC_CHECK_TYPES([struct mnt_id_req],,,[#include <linux/mount.h>])
AC_CHECK_TYPES([struct statmount],,,[#include <linux/mount.h>])
+AC_CHECK_TYPES([struct xattr_args],,,[#include <linux/xattr.h>])
# Tools knobs
diff --git a/include/lapi/xattr.h b/include/lapi/xattr.h
new file mode 100644
index 0000000000000000000000000000000000000000..b30b24ac0dce04ee225a7609e92fb7af8b545283
--- /dev/null
+++ b/include/lapi/xattr.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2025 Linux Test Project
+ */
+
+#ifndef LAPI_XATTR_H__
+#define LAPI_XATTR_H__
+
+#include <stdint.h>
+
+#ifndef STRUCT_XATTR_ARGS
+struct xattr_args {
+ void *value;
+ uint32_t size;
+ uint32_t flags;
+};
+#endif
+
+#endif /* LAPI_XATTR_H__ */
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [LTP] [PATCH 3/8] setxattr01: add setxattrat variant
2025-01-27 14:08 [LTP] [PATCH 0/8] setxattrat coverage Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 1/8] syscalls: add *xattrat syscalls Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 2/8] lapi: add struct xattr_args fallback Andrea Cervesato
@ 2025-01-27 14:08 ` Andrea Cervesato
2025-03-06 12:46 ` Cyril Hrubis
2025-01-27 14:08 ` [LTP] [PATCH 4/8] setxattr02: " Andrea Cervesato
` (4 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Andrea Cervesato @ 2025-01-27 14:08 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/syscalls/setxattr/setxattr01.c | 53 ++++++++++++++++++++-----
1 file changed, 44 insertions(+), 9 deletions(-)
diff --git a/testcases/kernel/syscalls/setxattr/setxattr01.c b/testcases/kernel/syscalls/setxattr/setxattr01.c
index de3ea67ec4000905651f20e2684a6b0aef493da7..67b053c4a2593df6cd2800c5450b5951ff78ae0d 100644
--- a/testcases/kernel/syscalls/setxattr/setxattr01.c
+++ b/testcases/kernel/syscalls/setxattr/setxattr01.c
@@ -36,6 +36,8 @@
# include <sys/xattr.h>
#endif
#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/xattr.h"
#ifdef HAVE_SYS_XATTR_H
#define XATTR_NAME_MAX 255
@@ -45,11 +47,13 @@
#define XATTR_TEST_VALUE "this is a test value"
#define XATTR_TEST_VALUE_SIZE 20
#define MNTPOINT "mntpoint"
-#define FNAME MNTPOINT"/setxattr01testfile"
+#define FNAME_REL "setxattr01testfile"
+#define FNAME MNTPOINT"/"FNAME_REL
static char long_key[XATTR_NAME_LEN];
static char *long_value;
static char *xattr_value = XATTR_TEST_VALUE;
+static int mnt_fd = -1;
struct test_case {
char *key;
@@ -128,44 +132,65 @@ struct test_case tc[] = {
static void verify_setxattr(unsigned int i)
{
+ char *sysname;
+
/* some tests might require existing keys for each iteration */
if (tc[i].keyneeded) {
SAFE_SETXATTR(FNAME, tc[i].key, *tc[i].value, tc[i].size,
XATTR_CREATE);
}
- TEST(setxattr(FNAME, tc[i].key, *tc[i].value, tc[i].size, tc[i].flags));
+ if (tst_variant) {
+ sysname = "setxattrat";
+
+ struct xattr_args args = {
+ .value = tc[i].value,
+ .size = tc[i].size,
+ .flags = tc[i].flags,
+ };
+
+ TEST(tst_syscall(__NR_setxattrat,
+ mnt_fd, FNAME_REL, AT_SYMLINK_NOFOLLOW,
+ tc[i].key, &args, sizeof(args)));
+ } else {
+ sysname = "setxattr";
+
+ TEST(setxattr(
+ FNAME,
+ tc[i].key, *tc[i].value, tc[i].size,
+ tc[i].flags));
+ }
if (TST_RET == -1 && TST_ERR == EOPNOTSUPP)
- tst_brk(TCONF, "setxattr(2) not supported");
+ tst_brk(TCONF, "%s(2) not supported", sysname);
/* success */
if (!tc[i].exp_err) {
if (TST_RET) {
tst_res(TFAIL | TTERRNO,
- "setxattr(2) failed with %li", TST_RET);
+ "%s(2) failed with %li", sysname, TST_RET);
return;
}
/* this is needed for subsequent iterations */
SAFE_REMOVEXATTR(FNAME, tc[i].key);
- tst_res(TPASS, "setxattr(2) passed");
+ tst_res(TPASS, "%s(2) passed", sysname);
return;
}
if (TST_RET == 0) {
- tst_res(TFAIL, "setxattr(2) passed unexpectedly");
+ tst_res(TFAIL, "%s(2) passed unexpectedly", sysname);
return;
}
/* error */
if (tc[i].exp_err != TST_ERR) {
- tst_res(TFAIL | TTERRNO, "setxattr(2) should fail with %s",
- tst_strerrno(tc[i].exp_err));
+ tst_res(TFAIL | TTERRNO, "%s(2) should fail with %s",
+ sysname, tst_strerrno(tc[i].exp_err));
return;
}
@@ -173,7 +198,7 @@ static void verify_setxattr(unsigned int i)
if (tc[i].keyneeded)
SAFE_REMOVEXATTR(FNAME, tc[i].key);
- tst_res(TPASS | TTERRNO, "setxattr(2) failed");
+ tst_res(TPASS | TTERRNO, "%s(2) failed", sysname);
}
static void setup(void)
@@ -194,12 +219,22 @@ static void setup(void)
if (!tc[i].key)
tc[i].key = tst_get_bad_addr(NULL);
}
+
+ mnt_fd = SAFE_OPEN(MNTPOINT, O_DIRECTORY);
+}
+
+static void cleanup(void)
+{
+ if (mnt_fd != -1)
+ SAFE_CLOSE(mnt_fd);
}
static struct tst_test test = {
.setup = setup,
+ .cleanup = cleanup,
.test = verify_setxattr,
.tcnt = ARRAY_SIZE(tc),
+ .test_variants = 2,
.mntpoint = MNTPOINT,
.mount_device = 1,
.all_filesystems = 1,
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [LTP] [PATCH 4/8] setxattr02: add setxattrat variant
2025-01-27 14:08 [LTP] [PATCH 0/8] setxattrat coverage Andrea Cervesato
` (2 preceding siblings ...)
2025-01-27 14:08 ` [LTP] [PATCH 3/8] setxattr01: add setxattrat variant Andrea Cervesato
@ 2025-01-27 14:08 ` Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 5/8] setxattr03: " Andrea Cervesato
` (3 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Andrea Cervesato @ 2025-01-27 14:08 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/syscalls/setxattr/setxattr02.c | 71 ++++++++++++++++++++-----
1 file changed, 57 insertions(+), 14 deletions(-)
diff --git a/testcases/kernel/syscalls/setxattr/setxattr02.c b/testcases/kernel/syscalls/setxattr/setxattr02.c
index 18afc031b495570c803dcc2dfc5207c6e8308bf4..a61fcedf447633179946f8e33c12c6ce71f0d5b9 100644
--- a/testcases/kernel/syscalls/setxattr/setxattr02.c
+++ b/testcases/kernel/syscalls/setxattr/setxattr02.c
@@ -36,6 +36,9 @@
# include <sys/xattr.h>
#endif
#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/xattr.h"
+#include "lapi/fcntl.h"
#ifdef HAVE_SYS_XATTR_H
#define XATTR_TEST_KEY "user.testkey"
@@ -51,6 +54,8 @@
#define BLK "setxattr02blk"
#define SOCK "setxattr02sock"
+static int tmpdir_fd = -1;
+
struct test_case {
char *fname;
char *key;
@@ -122,39 +127,59 @@ static struct test_case tc[] = {
static void verify_setxattr(unsigned int i)
{
+ char *sysname;
+
/* some tests might require existing keys for each iteration */
if (tc[i].needskeyset) {
SAFE_SETXATTR(tc[i].fname, tc[i].key, tc[i].value, tc[i].size,
- XATTR_CREATE);
+ XATTR_CREATE);
}
- TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value, tc[i].size,
- tc[i].flags));
+ if (tst_variant) {
+ sysname = "setxattrat";
+
+ struct xattr_args args = {
+ .value = tc[i].value,
+ .size = tc[i].size,
+ .flags = tc[i].flags,
+ };
+
+ int at_flags = tc[i].needskeyset ? 0 : AT_SYMLINK_NOFOLLOW;
+
+ TEST(tst_syscall(__NR_setxattrat,
+ tmpdir_fd, tc[i].fname, at_flags,
+ tc[i].key, &args, sizeof(args)));
+ } else {
+ sysname = "setxattr";
+
+ TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value, tc[i].size,
+ tc[i].flags));
+ }
if (TST_RET == -1 && TST_ERR == EOPNOTSUPP)
- tst_brk(TCONF, "setxattr(2) not supported");
+ tst_brk(TCONF, "%s(2) not supported", sysname);
/* success */
if (!tc[i].exp_err) {
if (TST_RET) {
tst_res(TFAIL | TTERRNO,
- "setxattr(2) on %s failed with %li",
- tc[i].fname + OFFSET, TST_RET);
+ "%s(2) on %s failed with %li",
+ sysname, tc[i].fname + OFFSET, TST_RET);
return;
}
/* this is needed for subsequent iterations */
SAFE_REMOVEXATTR(tc[i].fname, tc[i].key);
- tst_res(TPASS, "setxattr(2) on %s passed",
- tc[i].fname + OFFSET);
+ tst_res(TPASS, "%s(2) on %s passed",
+ sysname, tc[i].fname + OFFSET);
return;
}
if (TST_RET == 0) {
- tst_res(TFAIL, "setxattr(2) on %s passed unexpectedly",
- tc[i].fname + OFFSET);
+ tst_res(TFAIL, "%s(2) on %s passed unexpectedly",
+ sysname, tc[i].fname + OFFSET);
return;
}
@@ -162,8 +187,8 @@ static void verify_setxattr(unsigned int i)
if (tc[i].exp_err != TST_ERR) {
tst_res(TFAIL | TTERRNO,
- "setxattr(2) on %s should have failed with %s",
- tc[i].fname + OFFSET,
+ "%s(2) on %s should have failed with %s",
+ sysname, tc[i].fname + OFFSET,
tst_strerrno(tc[i].exp_err));
return;
}
@@ -172,8 +197,8 @@ static void verify_setxattr(unsigned int i)
if (tc[i].needskeyset)
SAFE_REMOVEXATTR(tc[i].fname, tc[i].key);
- tst_res(TPASS | TTERRNO, "setxattr(2) on %s failed",
- tc[i].fname + OFFSET);
+ tst_res(TPASS | TTERRNO, "%s(2) on %s failed",
+ sysname, tc[i].fname + OFFSET);
}
static void setup(void)
@@ -187,12 +212,30 @@ 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);
+
+ tmpdir_fd = SAFE_OPEN(tst_tmpdir_path(), O_DIRECTORY);
+}
+
+static void cleanup(void)
+{
+ if (tmpdir_fd != -1)
+ SAFE_CLOSE(tmpdir_fd);
+
+ SAFE_UNLINK(FILENAME);
+ SAFE_RMDIR(DIRNAME);
+ SAFE_UNLINK(SYMLINK);
+ SAFE_UNLINK(FIFO);
+ SAFE_UNLINK(CHR);
+ SAFE_UNLINK(BLK);
+ SAFE_UNLINK(SOCK);
}
static struct tst_test test = {
.setup = setup,
+ .cleanup = cleanup,
.test = verify_setxattr,
.tcnt = ARRAY_SIZE(tc),
+ .test_variants = 2,
.needs_tmpdir = 1,
.needs_root = 1,
};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [LTP] [PATCH 5/8] setxattr03: add setxattrat variant
2025-01-27 14:08 [LTP] [PATCH 0/8] setxattrat coverage Andrea Cervesato
` (3 preceding siblings ...)
2025-01-27 14:08 ` [LTP] [PATCH 4/8] setxattr02: " Andrea Cervesato
@ 2025-01-27 14:08 ` Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 6/8] lapi: add safe *xattrat macros Andrea Cervesato
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Andrea Cervesato @ 2025-01-27 14:08 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/syscalls/setxattr/setxattr03.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/testcases/kernel/syscalls/setxattr/setxattr03.c b/testcases/kernel/syscalls/setxattr/setxattr03.c
index 52cec078877580ab17385dfaaad77ec0ed7ec563..92f12c31c7858fade8fd535923bde7c887484b7c 100644
--- a/testcases/kernel/syscalls/setxattr/setxattr03.c
+++ b/testcases/kernel/syscalls/setxattr/setxattr03.c
@@ -32,6 +32,8 @@
#include "lapi/fs.h"
#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/xattr.h"
#if defined HAVE_SYS_XATTR_H
#define XATTR_TEST_KEY "user.testkey"
@@ -78,11 +80,24 @@ static struct test_case tc[] = {
static int immu_fd;
static int append_fd;
+static int tmpdir_fd = -1;
static void verify_setxattr(unsigned int i)
{
- TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value, tc[i].size,
- tc[i].flags));
+ if (tst_variant) {
+ struct xattr_args args = {
+ .value = tc[i].value,
+ .size = tc[i].size,
+ .flags = tc[i].flags,
+ };
+
+ TEST(tst_syscall(__NR_setxattrat,
+ tmpdir_fd, tc[i].fname, AT_SYMLINK_NOFOLLOW,
+ tc[i].key, &args, sizeof(args)));
+ } else {
+ TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value, tc[i].size,
+ tc[i].flags));
+ }
if (!TST_RET) {
tst_res(TFAIL, "%s succeeded unexpectedly", tc[i].desc);
@@ -145,10 +160,15 @@ static void setup(void)
if (set_append_on(append_fd))
tst_brk(TBROK | TERRNO, "Set %s append-only failed",
APPEND_FILE);
+
+ tmpdir_fd = SAFE_OPEN(tst_tmpdir_path(), O_DIRECTORY);
}
static void cleanup(void)
{
+ if (tmpdir_fd != -1)
+ SAFE_CLOSE(tmpdir_fd);
+
if ((immu_fd > 0) && set_immutable_off(immu_fd))
tst_res(TWARN | TERRNO, "Unset %s immutable failed",
IMMU_FILE);
@@ -169,6 +189,7 @@ static struct tst_test test = {
.cleanup = cleanup,
.test = verify_setxattr,
.tcnt = ARRAY_SIZE(tc),
+ .test_variants = 2,
.needs_tmpdir = 1,
.needs_root = 1,
};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [LTP] [PATCH 6/8] lapi: add safe *xattrat macros
2025-01-27 14:08 [LTP] [PATCH 0/8] setxattrat coverage Andrea Cervesato
` (4 preceding siblings ...)
2025-01-27 14:08 ` [LTP] [PATCH 5/8] setxattr03: " Andrea Cervesato
@ 2025-01-27 14:08 ` Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 7/8] Add setxattrat01 test Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 8/8] Add setxattrat02 test Andrea Cervesato
7 siblings, 0 replies; 12+ messages in thread
From: Andrea Cervesato @ 2025-01-27 14:08 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Introduce the following new safe macros:
- SAFE_SETXATTRAT
- SAFE_GETXATTRAT
- SAFE_REMOVEXATTRAT
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/lapi/xattr.h | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
diff --git a/include/lapi/xattr.h b/include/lapi/xattr.h
index b30b24ac0dce04ee225a7609e92fb7af8b545283..8bf8a5de2c25e9ed8727b78ec0488779f4b65403 100644
--- a/include/lapi/xattr.h
+++ b/include/lapi/xattr.h
@@ -7,6 +7,8 @@
#define LAPI_XATTR_H__
#include <stdint.h>
+#include <stddef.h>
+#include "lapi/syscalls.h"
#ifndef STRUCT_XATTR_ARGS
struct xattr_args {
@@ -16,4 +18,100 @@ struct xattr_args {
};
#endif
+int safe_setxattrat(const char *file, const int lineno,
+ int dfd, const char *path, int at_flags,
+ const char *key, struct xattr_args *args, size_t size)
+{
+ int rval;
+
+ rval = tst_syscall(__NR_setxattrat,
+ dfd, path, at_flags, key, args, size);
+
+ if (rval == -1) {
+ if (errno == ENOTSUP) {
+ tst_brk_(file, lineno, TCONF,
+ "no xattr support in fs, mounted without user_xattr option "
+ "or invalid namespace/name format");
+ return rval;
+ }
+
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "setxattrat(%d, %s, %d, %s, %p, %zu) failed",
+ dfd, path, at_flags, key, args, size);
+ } else if (rval) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid setxattrat(%d, %s, %d, %s, %p, %zu) return value %d",
+ dfd, path, at_flags, key, args, size, rval);
+ }
+
+ return rval;
+}
+
+#define SAFE_SETXATTRAT(dfd, path, at_flags, key, args, size) \
+ safe_setxattrat(__FILE__, __LINE__, \
+ (dfd), (path), (at_flags), (key), (args), (size))
+
+int safe_getxattrat(const char *file, const int lineno,
+ int dfd, const char *path, int at_flags,
+ const char *key, struct xattr_args *args, size_t size)
+{
+ int rval;
+
+ rval = tst_syscall(__NR_getxattrat,
+ dfd, path, at_flags, key, args, size);
+
+ if (rval == -1) {
+ if (errno == ENOTSUP) {
+ tst_brk_(file, lineno, TCONF,
+ "no xattr support in fs, mounted without user_xattr option "
+ "or invalid namespace/name format");
+ return rval;
+ }
+
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "getxattrat(%d, %s, %d, %s, %p, %zu) failed",
+ dfd, path, at_flags, key, args, size);
+ } else if (rval < 0) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid getxattrat(%d, %s, %d, %s, %p, %zu) return value %d",
+ dfd, path, at_flags, key, args, size, rval);
+ }
+
+ return rval;
+}
+
+#define SAFE_GETXATTRAT(dfd, path, at_flags, key, args, size) \
+ safe_getxattrat(__FILE__, __LINE__, \
+ (dfd), (path), (at_flags), (key), (args), (size))
+
+int safe_removexattrat(const char *file, const int lineno,
+ int dfd, const char *path, int at_flags, const char *name)
+{
+ int rval;
+
+ rval = tst_syscall(__NR_removexattrat, dfd, path, at_flags, name);
+
+ if (rval == -1) {
+ if (errno == ENOTSUP) {
+ tst_brk_(file, lineno, TCONF,
+ "no xattr support in fs or mounted without user_xattr option");
+ return rval;
+ }
+
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "removexattrat(%d, %s, %d, %s) failed",
+ dfd, path, at_flags, name);
+ } else if (rval) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid removexattrat(%d, %s, %d, %s) return value %d",
+ dfd, path, at_flags, name, rval);
+ }
+
+ return rval;
+}
+
+#define SAFE_REMOVEXATTRAT(dfd, path, at_flags, name) \
+ safe_removexattrat(__FILE__, __LINE__, \
+ (dfd), (path), (at_flags), (name))
+
#endif /* LAPI_XATTR_H__ */
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [LTP] [PATCH 7/8] Add setxattrat01 test
2025-01-27 14:08 [LTP] [PATCH 0/8] setxattrat coverage Andrea Cervesato
` (5 preceding siblings ...)
2025-01-27 14:08 ` [LTP] [PATCH 6/8] lapi: add safe *xattrat macros Andrea Cervesato
@ 2025-01-27 14:08 ` Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 8/8] Add setxattrat02 test Andrea Cervesato
7 siblings, 0 replies; 12+ messages in thread
From: Andrea Cervesato @ 2025-01-27 14:08 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Test if setxattrat() syscall is correctly following symlink, setting
a xattr on a file.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/syscalls/setxattrat/.gitignore | 1 +
testcases/kernel/syscalls/setxattrat/Makefile | 8 ++
.../kernel/syscalls/setxattrat/setxattrat01.c | 151 +++++++++++++++++++++
3 files changed, 160 insertions(+)
diff --git a/testcases/kernel/syscalls/setxattrat/.gitignore b/testcases/kernel/syscalls/setxattrat/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..e636401d7ac3ed58c5f9a24ad31291f0dc1c9ae7
--- /dev/null
+++ b/testcases/kernel/syscalls/setxattrat/.gitignore
@@ -0,0 +1 @@
+setxattrat01
diff --git a/testcases/kernel/syscalls/setxattrat/Makefile b/testcases/kernel/syscalls/setxattrat/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..e582f727dd8719bf51685070d1e4a4c5f5fac61f
--- /dev/null
+++ b/testcases/kernel/syscalls/setxattrat/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2025 SUSE LLC
+
+top_srcdir ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/setxattrat/setxattrat01.c b/testcases/kernel/syscalls/setxattrat/setxattrat01.c
new file mode 100644
index 0000000000000000000000000000000000000000..ef0ab2b1137e800b2edee85bd42bdf6d34fe0adc
--- /dev/null
+++ b/testcases/kernel/syscalls/setxattrat/setxattrat01.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2025 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if setxattrat() syscall is correctly following symlink, setting a
+ * xattr on a file.
+ *
+ * [Algorithm]
+ *
+ * - create a file and the symlink pointing to it
+ * - run setxattrat() on the symlink following the pointing file
+ * - verify that file xattr has been set
+ * - verify that symlink xattr has not been set
+ * - run setxattrat() on the symlink with AT_SYMLINK_NOFOLLOW
+ * - verify that file xattr has not been set
+ * - verify that symlink xattr has been set
+ */
+
+#include <sys/xattr.h>
+
+#include "tst_test.h"
+#include "lapi/xattr.h"
+#include "lapi/fcntl.h"
+
+#define FNAME "ltp_file"
+#define SNAME "ltp_symbolic_file"
+#define XATTR_TEST_KEY "trusted.ltptestkey"
+#define XATTR_TEST_VALUE "ltprulez"
+#define XATTR_TEST_VALUE_SIZE 8
+
+static struct xattr_args *args;
+static int tmpdir_fd = -1;
+
+static struct tcase {
+ char *dst_set;
+ char *dst_noset;
+ int at_flags;
+} tcases[] = {
+ {
+ .dst_set = FNAME,
+ .dst_noset = SNAME,
+ .at_flags = 0,
+ },
+ {
+ .dst_set = SNAME,
+ .dst_noset = FNAME,
+ .at_flags = AT_SYMLINK_NOFOLLOW,
+ }
+};
+
+static void expect_xattr(const char *fname)
+{
+ int ret;
+ char buff[XATTR_TEST_VALUE_SIZE];
+
+ tst_res(TINFO, "Check if %s has xattr", fname);
+
+ memset(args, 0, sizeof(*args));
+ memset(buff, 0, XATTR_TEST_VALUE_SIZE);
+
+ args->value = buff;
+ args->size = XATTR_TEST_VALUE_SIZE;
+
+ ret = SAFE_GETXATTRAT(tmpdir_fd, fname, AT_SYMLINK_NOFOLLOW,
+ XATTR_TEST_KEY, args, sizeof(*args));
+
+ TST_EXP_EQ_LI(ret, XATTR_TEST_VALUE_SIZE);
+ TST_EXP_EQ_LI(args->size, XATTR_TEST_VALUE_SIZE);
+ TST_EXP_EQ_LI(args->flags, 0);
+ TST_EXP_EQ_STRN(args->value, XATTR_TEST_VALUE, XATTR_TEST_VALUE_SIZE);
+}
+
+static void expect_no_xattr(const char *fname)
+{
+ char buff[XATTR_TEST_VALUE_SIZE];
+
+ tst_res(TINFO, "Check if %s has no xattr", fname);
+
+ memset(args, 0, sizeof(*args));
+ memset(buff, 0, XATTR_TEST_VALUE_SIZE);
+
+ args->value = buff;
+ args->size = 0;
+
+ TST_EXP_FAIL(tst_syscall(__NR_getxattrat, tmpdir_fd, fname,
+ AT_SYMLINK_NOFOLLOW, XATTR_TEST_KEY, args, sizeof(*args)),
+ ENODATA);
+
+ TST_EXP_EQ_LI(args->size, 0);
+ TST_EXP_EQ_LI(args->flags, 0);
+ TST_EXP_EQ_STRN(args->value, "\0", 1);
+}
+
+static void run(unsigned int i)
+{
+ struct tcase *tc = &tcases[i];
+
+ args->value = XATTR_TEST_VALUE;
+ args->size = XATTR_TEST_VALUE_SIZE;
+ args->flags = XATTR_CREATE;
+
+ tst_res(TINFO, "Setting xattr '%s' in %s (flags=%s)",
+ XATTR_TEST_KEY, SNAME,
+ !tc->at_flags ? "0" : "AT_SYMLINK_NOFOLLOW");
+
+ SAFE_SETXATTRAT(tmpdir_fd, SNAME, tc->at_flags, XATTR_TEST_KEY,
+ args, sizeof(*args));
+
+ expect_xattr(tc->dst_set);
+ expect_no_xattr(tc->dst_noset);
+
+ SAFE_REMOVEXATTRAT(tmpdir_fd, tc->dst_set, tc->at_flags,
+ XATTR_TEST_KEY);
+}
+
+static void setup(void)
+{
+ char *tmpdir;
+
+ tmpdir = tst_tmpdir_path();
+ tmpdir_fd = SAFE_OPEN(tmpdir, O_DIRECTORY);
+
+ SAFE_TOUCH(FNAME, 0777, NULL);
+ SAFE_SYMLINK(FNAME, SNAME);
+}
+
+static void cleanup(void)
+{
+ if (tmpdir_fd != -1)
+ SAFE_CLOSE(tmpdir_fd);
+
+ SAFE_UNLINK(SNAME);
+ SAFE_UNLINK(FNAME);
+}
+
+static struct tst_test test = {
+ .test = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_tmpdir = 1,
+ .needs_root = 1,
+ .tcnt = ARRAY_SIZE(tcases),
+ .bufs = (struct tst_buffers []) {
+ {&args, .size = sizeof(struct xattr_args)},
+ {},
+ }
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [LTP] [PATCH 8/8] Add setxattrat02 test
2025-01-27 14:08 [LTP] [PATCH 0/8] setxattrat coverage Andrea Cervesato
` (6 preceding siblings ...)
2025-01-27 14:08 ` [LTP] [PATCH 7/8] Add setxattrat01 test Andrea Cervesato
@ 2025-01-27 14:08 ` Andrea Cervesato
7 siblings, 0 replies; 12+ messages in thread
From: Andrea Cervesato @ 2025-01-27 14:08 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Test if setxattrat() syscall is correctly raising errors when giving
invalid inputs.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/syscalls/setxattrat/.gitignore | 1 +
.../kernel/syscalls/setxattrat/setxattrat02.c | 126 +++++++++++++++++++++
2 files changed, 127 insertions(+)
diff --git a/testcases/kernel/syscalls/setxattrat/.gitignore b/testcases/kernel/syscalls/setxattrat/.gitignore
index e636401d7ac3ed58c5f9a24ad31291f0dc1c9ae7..9d007a44dfca6e06cdb5b368201921461c68684d 100644
--- a/testcases/kernel/syscalls/setxattrat/.gitignore
+++ b/testcases/kernel/syscalls/setxattrat/.gitignore
@@ -1 +1,2 @@
setxattrat01
+setxattrat02
diff --git a/testcases/kernel/syscalls/setxattrat/setxattrat02.c b/testcases/kernel/syscalls/setxattrat/setxattrat02.c
new file mode 100644
index 0000000000000000000000000000000000000000..7891dc9e5f7c051c8413cfea677417d7edd8bef5
--- /dev/null
+++ b/testcases/kernel/syscalls/setxattrat/setxattrat02.c
@@ -0,0 +1,126 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2025 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if setxattrat() syscall is correctly raising errors when giving invalid
+ * inputs.
+ */
+
+#include <sys/xattr.h>
+
+#include "tst_test.h"
+#include "lapi/xattr.h"
+#include "lapi/syscalls.h"
+
+#define FNAME "ltp_file"
+#define XATTR_TEST_KEY "trusted.ltptestkey"
+#define XATTR_TEST_VALUE "ltprulez"
+#define XATTR_TEST_VALUE_SIZE 8
+
+static struct xattr_args *args;
+static struct xattr_args *null_args;
+static int invalid_fd = -1;
+static int tmpdir_fd = -1;
+
+static struct tcase {
+ int *dfd;
+ int at_flags;
+ struct xattr_args **args;
+ size_t args_size;
+ int exp_errno;
+ char *reason;
+} tcases[] = {
+ {
+ .dfd = &invalid_fd,
+ .args = &args,
+ .args_size = sizeof(struct xattr_args),
+ .exp_errno = EBADF,
+ .reason = "Invalid directory file descriptor",
+ },
+ {
+ .dfd = &tmpdir_fd,
+ .at_flags = -1,
+ .args = &args,
+ .args_size = sizeof(struct xattr_args),
+ .exp_errno = EINVAL,
+ .reason = "Invalid AT flags",
+ },
+ {
+ .dfd = &tmpdir_fd,
+ .at_flags = AT_SYMLINK_NOFOLLOW + 1,
+ .args = &args,
+ .args_size = sizeof(struct xattr_args),
+ .exp_errno = EINVAL,
+ .reason = "Out of bound AT flags",
+ },
+ {
+ .dfd = &tmpdir_fd,
+ .args = &null_args,
+ .args_size = sizeof(struct xattr_args),
+ .exp_errno = EINVAL,
+ .reason = "Invalid arguments",
+ },
+ {
+ .dfd = &tmpdir_fd,
+ .args = &args,
+ .args_size = SIZE_MAX,
+ .exp_errno = E2BIG,
+ .reason = "Arguments size is too big",
+ },
+ {
+ .dfd = &tmpdir_fd,
+ .args = &args,
+ .args_size = sizeof(struct xattr_args) - 1,
+ .exp_errno = EINVAL,
+ .reason = "Invalid arguments size",
+ },
+};
+
+static void run(unsigned int i)
+{
+ struct tcase *tc = &tcases[i];
+
+ args->flags = XATTR_CREATE;
+ args->value = XATTR_TEST_VALUE;
+ args->size = XATTR_TEST_VALUE_SIZE;
+
+ TST_EXP_FAIL(tst_syscall(__NR_setxattrat,
+ tc->dfd, FNAME, tc->at_flags, XATTR_TEST_KEY,
+ tc->args, tc->args_size),
+ tc->exp_errno, "%s", tc->reason);
+}
+
+static void setup(void)
+{
+ char *tmpdir;
+
+ tmpdir = tst_tmpdir_path();
+ tmpdir_fd = SAFE_OPEN(tmpdir, O_DIRECTORY);
+
+ SAFE_TOUCH(FNAME, 0777, NULL);
+}
+
+static void cleanup(void)
+{
+ if (tmpdir_fd != -1)
+ SAFE_CLOSE(tmpdir_fd);
+
+ SAFE_UNLINK(FNAME);
+}
+
+static struct tst_test test = {
+ .test = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .tcnt = ARRAY_SIZE(tcases),
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .bufs = (struct tst_buffers []) {
+ {&args, .size = sizeof(struct xattr_args)},
+ {},
+ }
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [LTP] [PATCH 2/8] lapi: add struct xattr_args fallback
2025-01-27 14:08 ` [LTP] [PATCH 2/8] lapi: add struct xattr_args fallback Andrea Cervesato
@ 2025-01-31 8:36 ` Petr Vorel
0 siblings, 0 replies; 12+ messages in thread
From: Petr Vorel @ 2025-01-31 8:36 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi Andrea,
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
> configure.ac | 1 +
> include/lapi/xattr.h | 19 +++++++++++++++++++
> 2 files changed, 20 insertions(+)
> diff --git a/configure.ac b/configure.ac
> index 6992d75ca300ccc4cc21a45a916f6b3be1a3b8fe..eb1a966322313cf785c25af0f317700418186927 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -247,6 +247,7 @@ AC_CHECK_TYPES([struct cachestat_range],,,[#include <sys/mman.h>])
> AC_CHECK_TYPES([struct cachestat],,,[#include <sys/mman.h>])
> AC_CHECK_TYPES([struct mnt_id_req],,,[#include <linux/mount.h>])
> AC_CHECK_TYPES([struct statmount],,,[#include <linux/mount.h>])
> +AC_CHECK_TYPES([struct xattr_args],,,[#include <linux/xattr.h>])
> # Tools knobs
> diff --git a/include/lapi/xattr.h b/include/lapi/xattr.h
> new file mode 100644
> index 0000000000000000000000000000000000000000..b30b24ac0dce04ee225a7609e92fb7af8b545283
> --- /dev/null
> +++ b/include/lapi/xattr.h
> @@ -0,0 +1,19 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (c) 2025 Linux Test Project
> + */
> +
> +#ifndef LAPI_XATTR_H__
> +#define LAPI_XATTR_H__
> +
> +#include <stdint.h>
Could you, please, move conditional include from tests to this lapi header?
#ifdef HAVE_LINUX_XATTR_H
# include <linux/xattr.h>
#endif
That's the way we agreed in the past (tests include just a lapi header, not a
kernel one).
Otherwise LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
> +
> +#ifndef STRUCT_XATTR_ARGS
> +struct xattr_args {
> + void *value;
> + uint32_t size;
> + uint32_t flags;
> +};
> +#endif
> +
> +#endif /* LAPI_XATTR_H__ */
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [LTP] [PATCH 1/8] syscalls: add *xattrat syscalls
2025-01-27 14:08 ` [LTP] [PATCH 1/8] syscalls: add *xattrat syscalls Andrea Cervesato
@ 2025-01-31 9:09 ` Petr Vorel
0 siblings, 0 replies; 12+ messages in thread
From: Petr Vorel @ 2025-01-31 9:09 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi Andrea,
> Add following syscalls:
> - setxattrat
> - getxattrat
> - listxattrat
> - removexattrat
Obviously correct, thank you!
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Your generate_arch.sh script is really helpful :).
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [LTP] [PATCH 3/8] setxattr01: add setxattrat variant
2025-01-27 14:08 ` [LTP] [PATCH 3/8] setxattr01: add setxattrat variant Andrea Cervesato
@ 2025-03-06 12:46 ` Cyril Hrubis
0 siblings, 0 replies; 12+ messages in thread
From: Cyril Hrubis @ 2025-03-06 12:46 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> diff --git a/testcases/kernel/syscalls/setxattr/setxattr01.c b/testcases/kernel/syscalls/setxattr/setxattr01.c
> index de3ea67ec4000905651f20e2684a6b0aef493da7..67b053c4a2593df6cd2800c5450b5951ff78ae0d 100644
> --- a/testcases/kernel/syscalls/setxattr/setxattr01.c
> +++ b/testcases/kernel/syscalls/setxattr/setxattr01.c
> @@ -36,6 +36,8 @@
> # include <sys/xattr.h>
> #endif
> #include "tst_test.h"
> +#include "lapi/syscalls.h"
> +#include "lapi/xattr.h"
>
> #ifdef HAVE_SYS_XATTR_H
> #define XATTR_NAME_MAX 255
> @@ -45,11 +47,13 @@
> #define XATTR_TEST_VALUE "this is a test value"
> #define XATTR_TEST_VALUE_SIZE 20
> #define MNTPOINT "mntpoint"
> -#define FNAME MNTPOINT"/setxattr01testfile"
> +#define FNAME_REL "setxattr01testfile"
> +#define FNAME MNTPOINT"/"FNAME_REL
>
> static char long_key[XATTR_NAME_LEN];
> static char *long_value;
> static char *xattr_value = XATTR_TEST_VALUE;
> +static int mnt_fd = -1;
>
> struct test_case {
> char *key;
> @@ -128,44 +132,65 @@ struct test_case tc[] = {
>
> static void verify_setxattr(unsigned int i)
> {
> + char *sysname;
> +
> /* some tests might require existing keys for each iteration */
> if (tc[i].keyneeded) {
> SAFE_SETXATTR(FNAME, tc[i].key, *tc[i].value, tc[i].size,
> XATTR_CREATE);
> }
>
> - TEST(setxattr(FNAME, tc[i].key, *tc[i].value, tc[i].size, tc[i].flags));
> + if (tst_variant) {
> + sysname = "setxattrat";
> +
> + struct xattr_args args = {
> + .value = tc[i].value,
> + .size = tc[i].size,
> + .flags = tc[i].flags,
> + };
> +
> + TEST(tst_syscall(__NR_setxattrat,
> + mnt_fd, FNAME_REL, AT_SYMLINK_NOFOLLOW,
> + tc[i].key, &args, sizeof(args)));
The setxattrat() function should be put into the lapi/setxattr.h and
enabled only if configure script didn't find setxattrat() in the
sys/setxattr.h. That way we will switch to the system definition of the
function once it's available.
Any time we are adding tests for syscalls that are not in the libc now
but will end up there in the future we have to do this:
* Add AC_CHECK_FUNC() into configure
* Add syscall wrapper inside ifndef HAVE_FUNC block into respective lapi header
* Include the lapi header in the test
* Call the function as func() and not by tst_syscall(__NR_func, ...)
> + } else {
> + sysname = "setxattr";
> +
> + TEST(setxattr(
> + FNAME,
> + tc[i].key, *tc[i].value, tc[i].size,
> + tc[i].flags));
> + }
This pattern repeats in several tests, so it would make more sense to
write a wrapper that would call the respective syscall based on
tst_variant and put it into a common header. i.e.
static inline int call_setxattr(const char *fname, const char *name,
const void *value, size_t line, int flags)
{
if (tst_variant) {
struct xattr_args args = {
.value = tc[i].value,
.size = tc[i].size,
.flags = tc[i].flags,
};
return setxattrat(...);
} else {
return setxattr(...);
}
}
> if (TST_RET == -1 && TST_ERR == EOPNOTSUPP)
> - tst_brk(TCONF, "setxattr(2) not supported");
> + tst_brk(TCONF, "%s(2) not supported", sysname);
>
> /* success */
>
> if (!tc[i].exp_err) {
> if (TST_RET) {
> tst_res(TFAIL | TTERRNO,
> - "setxattr(2) failed with %li", TST_RET);
> + "%s(2) failed with %li", sysname, TST_RET);
> return;
> }
>
> /* this is needed for subsequent iterations */
> SAFE_REMOVEXATTR(FNAME, tc[i].key);
>
> - tst_res(TPASS, "setxattr(2) passed");
> + tst_res(TPASS, "%s(2) passed", sysname);
>
> return;
> }
>
> if (TST_RET == 0) {
> - tst_res(TFAIL, "setxattr(2) passed unexpectedly");
> + tst_res(TFAIL, "%s(2) passed unexpectedly", sysname);
> return;
> }
>
> /* error */
>
> if (tc[i].exp_err != TST_ERR) {
> - tst_res(TFAIL | TTERRNO, "setxattr(2) should fail with %s",
> - tst_strerrno(tc[i].exp_err));
> + tst_res(TFAIL | TTERRNO, "%s(2) should fail with %s",
> + sysname, tst_strerrno(tc[i].exp_err));
> return;
> }
>
> @@ -173,7 +198,7 @@ static void verify_setxattr(unsigned int i)
> if (tc[i].keyneeded)
> SAFE_REMOVEXATTR(FNAME, tc[i].key);
>
> - tst_res(TPASS | TTERRNO, "setxattr(2) failed");
> + tst_res(TPASS | TTERRNO, "%s(2) failed", sysname);
> }
>
> static void setup(void)
> @@ -194,12 +219,22 @@ static void setup(void)
> if (!tc[i].key)
> tc[i].key = tst_get_bad_addr(NULL);
> }
> +
> + mnt_fd = SAFE_OPEN(MNTPOINT, O_DIRECTORY);
> +}
> +
> +static void cleanup(void)
> +{
> + if (mnt_fd != -1)
> + SAFE_CLOSE(mnt_fd);
> }
>
> static struct tst_test test = {
> .setup = setup,
> + .cleanup = cleanup,
> .test = verify_setxattr,
> .tcnt = ARRAY_SIZE(tc),
> + .test_variants = 2,
> .mntpoint = MNTPOINT,
> .mount_device = 1,
> .all_filesystems = 1,
>
> --
> 2.43.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-03-06 12:46 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-27 14:08 [LTP] [PATCH 0/8] setxattrat coverage Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 1/8] syscalls: add *xattrat syscalls Andrea Cervesato
2025-01-31 9:09 ` Petr Vorel
2025-01-27 14:08 ` [LTP] [PATCH 2/8] lapi: add struct xattr_args fallback Andrea Cervesato
2025-01-31 8:36 ` Petr Vorel
2025-01-27 14:08 ` [LTP] [PATCH 3/8] setxattr01: add setxattrat variant Andrea Cervesato
2025-03-06 12:46 ` Cyril Hrubis
2025-01-27 14:08 ` [LTP] [PATCH 4/8] setxattr02: " Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 5/8] setxattr03: " Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 6/8] lapi: add safe *xattrat macros Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 7/8] Add setxattrat01 test Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 8/8] Add setxattrat02 test Andrea Cervesato
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox