* [LTP] [PATCH v3 0/5] Add fchmodat2 testing suite
@ 2024-07-24 9:45 Andrea Cervesato
2024-07-24 9:45 ` [LTP] [PATCH v3 1/5] Add SAFE_SYMLINKAT macro Andrea Cervesato
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-24 9:45 UTC (permalink / raw)
To: ltp
This is a patch-set that implements fchmodat2() syscall coverage.
fchmodat2() has been added in kernel 6.6 in order to support
AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH in fchmodat().
There's no man pages yet, so please take the following links as
main documentation along with kernel source code:
https://www.phoronix.com/news/fchmodat2-For-Linux-6.6
https://lore.kernel.org/lkml/20230824-frohlocken-vorabend-725f6fdaad50@brauner/
***********
* WARNING *
***********
fchmodat2_02 fails with EOPNOTSUPP because of missing feature.
According to documentation, the feature has been implemented in
kernel 6.6, but __in reality__ AT_SYMLINK_NOFOLLOW is not working
on symbolic files. Also kselftests, which are meant to test the
functionality, are not working and they are treating fchmodat2()
syscall failure as SKIP. Please take a look at the following code
before reviewing:
https://github.com/torvalds/linux/blob/8f6a15f095a63a83b096d9b29aaff4f0fbe6f6e6/tools/testing/selftests/fchmodat2/fchmodat2_test.c#L123
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Changes in v3:
- removed fchmodat2.h
- Link to v2: https://lore.kernel.org/r/20240723-fchmodat2-v2-0-e658a98b113e@suse.com
Changes in v2:
- merge first 3 tests into a unique one
- move fchmodat2 in lapi/stat.h
- add test for error checking
- Link to v1: https://lore.kernel.org/r/20240521-fchmodat2-v1-0-191b4a986202@suse.com
---
Andrea Cervesato (5):
Add SAFE_SYMLINKAT macro
Add fchmodat2 syscalls definitions
Add fchmodat2 fallback definition
Add fchmodat2_01 test
Add fchmodat2_02 test
include/lapi/stat.h | 13 +++
include/lapi/syscalls/aarch64.in | 1 +
include/lapi/syscalls/arc.in | 1 +
include/lapi/syscalls/arm.in | 1 +
include/lapi/syscalls/hppa.in | 1 +
include/lapi/syscalls/i386.in | 1 +
include/lapi/syscalls/ia64.in | 1 +
include/lapi/syscalls/loongarch.in | 1 +
include/lapi/syscalls/mips_n32.in | 1 +
include/lapi/syscalls/mips_n64.in | 1 +
include/lapi/syscalls/mips_o32.in | 1 +
include/lapi/syscalls/powerpc.in | 1 +
include/lapi/syscalls/powerpc64.in | 1 +
include/lapi/syscalls/s390.in | 1 +
include/lapi/syscalls/s390x.in | 1 +
include/lapi/syscalls/sh.in | 1 +
include/lapi/syscalls/sparc.in | 1 +
include/lapi/syscalls/sparc64.in | 1 +
include/lapi/syscalls/x86_64.in | 1 +
include/safe_macros_fn.h | 4 +
include/tst_safe_macros.h | 3 +
lib/safe_macros.c | 20 ++++
runtest/syscalls | 3 +
testcases/kernel/syscalls/fchmodat2/.gitignore | 2 +
testcases/kernel/syscalls/fchmodat2/Makefile | 7 ++
testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c | 114 +++++++++++++++++++++
testcases/kernel/syscalls/fchmodat2/fchmodat2_02.c | 68 ++++++++++++
27 files changed, 252 insertions(+)
---
base-commit: c5d95b6d34e2356bd19e6b646da06f1bce66a024
change-id: 20240517-fchmodat2-5b82867d71fc
Best regards,
--
Andrea Cervesato <andrea.cervesato@suse.com>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 10+ messages in thread
* [LTP] [PATCH v3 1/5] Add SAFE_SYMLINKAT macro
2024-07-24 9:45 [LTP] [PATCH v3 0/5] Add fchmodat2 testing suite Andrea Cervesato
@ 2024-07-24 9:45 ` Andrea Cervesato
2024-07-24 9:45 ` [LTP] [PATCH v3 2/5] Add fchmodat2 syscalls definitions Andrea Cervesato
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-24 9:45 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/safe_macros_fn.h | 4 ++++
include/tst_safe_macros.h | 3 +++
lib/safe_macros.c | 20 ++++++++++++++++++++
3 files changed, 27 insertions(+)
diff --git a/include/safe_macros_fn.h b/include/safe_macros_fn.h
index d256091b7..6d9e72e4f 100644
--- a/include/safe_macros_fn.h
+++ b/include/safe_macros_fn.h
@@ -122,6 +122,10 @@ int safe_symlink(const char *file, const int lineno,
void (cleanup_fn)(void), const char *oldpath,
const char *newpath);
+int safe_symlinkat(const char *file, const int lineno,
+ void (cleanup_fn)(void), const char *oldpath,
+ const int newdirfd, const char *newpath);
+
ssize_t safe_write(const char *file, const int lineno,
void (cleanup_fn)(void), enum safe_write_opts len_strict,
int fildes, const void *buf, size_t nbyte);
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 92b9bc119..47a6f99df 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -191,6 +191,9 @@ int safe_getgroups(const char *file, const int lineno, int size, gid_t list[]);
#define SAFE_SYMLINK(oldpath, newpath) \
safe_symlink(__FILE__, __LINE__, NULL, (oldpath), (newpath))
+#define SAFE_SYMLINKAT(oldpath, newdirfd, newpath) \
+ safe_symlinkat(__FILE__, __LINE__, NULL, (oldpath), (newdirfd), (newpath))
+
#define SAFE_WRITE(len_strict, fildes, buf, nbyte) \
safe_write(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte))
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index 109268587..f91e77022 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -527,6 +527,26 @@ int safe_symlink(const char *file, const int lineno,
return rval;
}
+int safe_symlinkat(const char *file, const int lineno,
+ void (cleanup_fn)(void), const char *oldpath,
+ const int newdirfd, const char *newpath)
+{
+ int rval;
+
+ rval = symlinkat(oldpath, newdirfd, newpath);
+
+ if (rval == -1) {
+ tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+ "symlinkat(%s,%d,%s) failed", oldpath, newdirfd, newpath);
+ } else if (rval) {
+ tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+ "Invalid symlinkat(%s,%d,%s) return value %d", oldpath,
+ newdirfd, newpath, rval);
+ }
+
+ return rval;
+}
+
ssize_t safe_write(const char *file, const int lineno, void (cleanup_fn) (void),
enum safe_write_opts len_strict, int fildes, const void *buf,
size_t nbyte)
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [LTP] [PATCH v3 2/5] Add fchmodat2 syscalls definitions
2024-07-24 9:45 [LTP] [PATCH v3 0/5] Add fchmodat2 testing suite Andrea Cervesato
2024-07-24 9:45 ` [LTP] [PATCH v3 1/5] Add SAFE_SYMLINKAT macro Andrea Cervesato
@ 2024-07-24 9:45 ` Andrea Cervesato
2024-07-29 20:38 ` Petr Vorel
2024-07-24 9:45 ` [LTP] [PATCH v3 3/5] Add fchmodat2 fallback definition Andrea Cervesato
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-24 9:45 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/lapi/syscalls/aarch64.in | 1 +
include/lapi/syscalls/arc.in | 1 +
include/lapi/syscalls/arm.in | 1 +
include/lapi/syscalls/hppa.in | 1 +
include/lapi/syscalls/i386.in | 1 +
include/lapi/syscalls/ia64.in | 1 +
include/lapi/syscalls/loongarch.in | 1 +
include/lapi/syscalls/mips_n32.in | 1 +
include/lapi/syscalls/mips_n64.in | 1 +
include/lapi/syscalls/mips_o32.in | 1 +
include/lapi/syscalls/powerpc.in | 1 +
include/lapi/syscalls/powerpc64.in | 1 +
include/lapi/syscalls/s390.in | 1 +
include/lapi/syscalls/s390x.in | 1 +
include/lapi/syscalls/sh.in | 1 +
include/lapi/syscalls/sparc.in | 1 +
include/lapi/syscalls/sparc64.in | 1 +
include/lapi/syscalls/x86_64.in | 1 +
18 files changed, 18 insertions(+)
diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in
index 3e7797718..6c3bd69b5 100644
--- a/include/lapi/syscalls/aarch64.in
+++ b/include/lapi/syscalls/aarch64.in
@@ -300,4 +300,5 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+fchmodat2 452
_sysctl 1078
diff --git a/include/lapi/syscalls/arc.in b/include/lapi/syscalls/arc.in
index 7fde1d263..f1721551e 100644
--- a/include/lapi/syscalls/arc.in
+++ b/include/lapi/syscalls/arc.in
@@ -320,3 +320,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in
index 8e76ad164..032941b7e 100644
--- a/include/lapi/syscalls/arm.in
+++ b/include/lapi/syscalls/arm.in
@@ -399,3 +399,4 @@ landlock_add_rule (__NR_SYSCALL_BASE+445)
landlock_restrict_self (__NR_SYSCALL_BASE+446)
memfd_secret (__NR_SYSCALL_BASE+447)
futex_waitv (__NR_SYSCALL_BASE+449)
+fchmodat2 (__NR_SYSCALL_BASE+452)
diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in
index 60c02aff2..39fdcc1d9 100644
--- a/include/lapi/syscalls/hppa.in
+++ b/include/lapi/syscalls/hppa.in
@@ -47,3 +47,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in
index 31ec1ecb2..36129b491 100644
--- a/include/lapi/syscalls/i386.in
+++ b/include/lapi/syscalls/i386.in
@@ -434,3 +434,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in
index 2e56da7f9..60f657457 100644
--- a/include/lapi/syscalls/ia64.in
+++ b/include/lapi/syscalls/ia64.in
@@ -347,3 +347,4 @@ landlock_create_ruleset 1468
landlock_add_rule 1469
landlock_restrict_self 1470
futex_waitv 1473
+fchmodat2 1476
diff --git a/include/lapi/syscalls/loongarch.in b/include/lapi/syscalls/loongarch.in
index 301f611f6..63e05d6b6 100644
--- a/include/lapi/syscalls/loongarch.in
+++ b/include/lapi/syscalls/loongarch.in
@@ -305,3 +305,4 @@ memfd_secret 447
process_mrelease 448
futex_waitv 449
set_mempolicy_home_node 450
+fchmodat2 452
diff --git a/include/lapi/syscalls/mips_n32.in b/include/lapi/syscalls/mips_n32.in
index 5f0fe65eb..b53fefc1f 100644
--- a/include/lapi/syscalls/mips_n32.in
+++ b/include/lapi/syscalls/mips_n32.in
@@ -374,3 +374,4 @@ landlock_create_ruleset 6444
landlock_add_rule 6445
landlock_restrict_self 6446
futex_waitv 6449
+fchmodat2 6452
diff --git a/include/lapi/syscalls/mips_n64.in b/include/lapi/syscalls/mips_n64.in
index f81c60e66..d9336c6e3 100644
--- a/include/lapi/syscalls/mips_n64.in
+++ b/include/lapi/syscalls/mips_n64.in
@@ -350,3 +350,4 @@ landlock_create_ruleset 5444
landlock_add_rule 5445
landlock_restrict_self 5446
futex_waitv 5449
+fchmodat2 5452
diff --git a/include/lapi/syscalls/mips_o32.in b/include/lapi/syscalls/mips_o32.in
index c2beffb75..30d42419e 100644
--- a/include/lapi/syscalls/mips_o32.in
+++ b/include/lapi/syscalls/mips_o32.in
@@ -420,3 +420,4 @@ landlock_create_ruleset 4444
landlock_add_rule 4445
landlock_restrict_self 4446
futex_waitv 4449
+fchmodat2 4452
diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in
index 5460e4197..2a2259841 100644
--- a/include/lapi/syscalls/powerpc.in
+++ b/include/lapi/syscalls/powerpc.in
@@ -427,3 +427,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in
index 5460e4197..2a2259841 100644
--- a/include/lapi/syscalls/powerpc64.in
+++ b/include/lapi/syscalls/powerpc64.in
@@ -427,3 +427,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in
index 275b27f47..656f5c118 100644
--- a/include/lapi/syscalls/s390.in
+++ b/include/lapi/syscalls/s390.in
@@ -414,3 +414,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in
index c200d02b2..46007bf89 100644
--- a/include/lapi/syscalls/s390x.in
+++ b/include/lapi/syscalls/s390x.in
@@ -362,3 +362,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in
index 6f482a77b..df7c1c378 100644
--- a/include/lapi/syscalls/sh.in
+++ b/include/lapi/syscalls/sh.in
@@ -408,3 +408,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in
index 7181e80a0..03030dd30 100644
--- a/include/lapi/syscalls/sparc.in
+++ b/include/lapi/syscalls/sparc.in
@@ -413,3 +413,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in
index c96ab2021..4ab40a5c5 100644
--- a/include/lapi/syscalls/sparc64.in
+++ b/include/lapi/syscalls/sparc64.in
@@ -378,3 +378,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in
index 3082ca110..57ffce837 100644
--- a/include/lapi/syscalls/x86_64.in
+++ b/include/lapi/syscalls/x86_64.in
@@ -355,6 +355,7 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+fchmodat2 452
rt_sigaction 512
rt_sigreturn 513
ioctl 514
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [LTP] [PATCH v3 3/5] Add fchmodat2 fallback definition
2024-07-24 9:45 [LTP] [PATCH v3 0/5] Add fchmodat2 testing suite Andrea Cervesato
2024-07-24 9:45 ` [LTP] [PATCH v3 1/5] Add SAFE_SYMLINKAT macro Andrea Cervesato
2024-07-24 9:45 ` [LTP] [PATCH v3 2/5] Add fchmodat2 syscalls definitions Andrea Cervesato
@ 2024-07-24 9:45 ` Andrea Cervesato
2024-07-30 9:14 ` Petr Vorel
2024-07-24 9:45 ` [LTP] [PATCH v3 4/5] Add fchmodat2_01 test Andrea Cervesato
2024-07-24 9:45 ` [LTP] [PATCH v3 5/5] Add fchmodat2_02 test Andrea Cervesato
4 siblings, 1 reply; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-24 9:45 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/lapi/stat.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/include/lapi/stat.h b/include/lapi/stat.h
index 3606c9eb0..5e289d3ca 100644
--- a/include/lapi/stat.h
+++ b/include/lapi/stat.h
@@ -229,4 +229,17 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
# define STATX_ATTR_VERITY 0x00100000
#endif
+static inline int fchmodat2(
+ int dfd, const char *filename, mode_t mode, int flags)
+{
+ int ret;
+
+ ret = tst_syscall(__NR_fchmodat2, dfd, filename, mode, flags);
+ if (ret == -1)
+ tst_brk(TBROK | TERRNO, "%s(%d,%s,%d,%d) error",
+ __func__, dfd, filename, mode, flags);
+
+ return ret;
+}
+
#endif /* LAPI_STAT_H__ */
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [LTP] [PATCH v3 4/5] Add fchmodat2_01 test
2024-07-24 9:45 [LTP] [PATCH v3 0/5] Add fchmodat2 testing suite Andrea Cervesato
` (2 preceding siblings ...)
2024-07-24 9:45 ` [LTP] [PATCH v3 3/5] Add fchmodat2 fallback definition Andrea Cervesato
@ 2024-07-24 9:45 ` Andrea Cervesato
2024-07-30 9:09 ` Petr Vorel
2024-07-24 9:45 ` [LTP] [PATCH v3 5/5] Add fchmodat2_02 test Andrea Cervesato
4 siblings, 1 reply; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-24 9:45 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test verifies that fchmodat2() syscall is properly working with
AT_SYMLINK_NOFOLLOW on regular files.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 2 +
testcases/kernel/syscalls/fchmodat2/.gitignore | 1 +
testcases/kernel/syscalls/fchmodat2/Makefile | 7 ++
testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c | 114 +++++++++++++++++++++
4 files changed, 124 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 27eb9a86b..b4bb4f391 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -265,6 +265,8 @@ fchmod06 fchmod06
fchmodat01 fchmodat01
fchmodat02 fchmodat02
+fchmodat2_01 fchmodat2_01
+
fchown01 fchown01
fchown01_16 fchown01_16
fchown02 fchown02
diff --git a/testcases/kernel/syscalls/fchmodat2/.gitignore b/testcases/kernel/syscalls/fchmodat2/.gitignore
new file mode 100644
index 000000000..47d5e2427
--- /dev/null
+++ b/testcases/kernel/syscalls/fchmodat2/.gitignore
@@ -0,0 +1 @@
+fchmodat2_01
diff --git a/testcases/kernel/syscalls/fchmodat2/Makefile b/testcases/kernel/syscalls/fchmodat2/Makefile
new file mode 100644
index 000000000..8cf1b9024
--- /dev/null
+++ b/testcases/kernel/syscalls/fchmodat2/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+
+top_srcdir ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
new file mode 100644
index 000000000..a00c06bf5
--- /dev/null
+++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that fchmodat2() syscall is properly working with
+ * AT_SYMLINK_NOFOLLOW regular files, symbolic links and directories.
+ */
+
+#include "tst_test.h"
+#include "tst_safe_file_at.h"
+#include "lapi/fcntl.h"
+#include "lapi/stat.h"
+
+#define MNTPOINT "mntpoint"
+#define FNAME "myfile"
+#define SNAME "symlink"
+#define DNAME "mydir"
+#define DNAME_PATH MNTPOINT"/"DNAME
+
+static int fd_dir = -1;
+
+static void verify_mode(int dirfd, const char *path, mode_t mode)
+{
+ struct stat st;
+
+ SAFE_FSTATAT(dirfd, path, &st, AT_SYMLINK_NOFOLLOW);
+ TST_EXP_EQ_LI(st.st_mode, mode);
+}
+
+static void test_regular_file(void)
+{
+ tst_res(TINFO, "Using regular files");
+
+ SAFE_CHMOD(MNTPOINT"/"FNAME, 0640);
+
+ TST_EXP_PASS(fchmodat2(fd_dir, FNAME, 0700, 0));
+ verify_mode(fd_dir, FNAME, S_IFREG | 0700);
+
+ TST_EXP_PASS(fchmodat2(fd_dir, FNAME, 0700, AT_SYMLINK_NOFOLLOW));
+ verify_mode(fd_dir, FNAME, S_IFREG | 0700);
+}
+
+static void test_symbolic_link(void)
+{
+ tst_res(TINFO, "Using symbolic link");
+
+ TST_EXP_PASS(fchmodat2(fd_dir, SNAME, 0700, 0));
+ verify_mode(fd_dir, FNAME, S_IFREG | 0700);
+ verify_mode(fd_dir, SNAME, S_IFLNK | 0777);
+
+ TST_EXP_PASS(fchmodat2(fd_dir, SNAME, 0640, AT_SYMLINK_NOFOLLOW));
+ verify_mode(fd_dir, FNAME, S_IFREG | 0700);
+ verify_mode(fd_dir, SNAME, S_IFLNK | 0640);
+}
+
+static void test_empty_folder(void)
+{
+ tst_res(TINFO, "Using empty folder");
+
+ int fd;
+
+ SAFE_CHMOD(DNAME_PATH, 0640);
+ fd = SAFE_OPEN(DNAME_PATH, O_PATH | O_DIRECTORY, 0640);
+
+ TST_EXP_PASS(fchmodat2(fd, "", 0777, AT_EMPTY_PATH));
+ verify_mode(fd_dir, DNAME, S_IFDIR | 0777);
+
+ SAFE_CLOSE(fd);
+}
+
+static void run(void)
+{
+ test_regular_file();
+ test_empty_folder();
+ test_symbolic_link();
+}
+
+static void setup(void)
+{
+ fd_dir = SAFE_OPEN(MNTPOINT, O_PATH | O_DIRECTORY, 0640);
+
+ if (access(DNAME_PATH, F_OK) == -1)
+ SAFE_MKDIR(DNAME_PATH, 0640);
+
+ SAFE_TOUCH(MNTPOINT"/"FNAME, 0640, NULL);
+ SAFE_SYMLINKAT(FNAME, fd_dir, SNAME);
+}
+
+static void cleanup(void)
+{
+ SAFE_UNLINKAT(fd_dir, SNAME, 0);
+ SAFE_RMDIR(DNAME_PATH);
+
+ if (fd_dir != -1)
+ SAFE_CLOSE(fd_dir);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .min_kver = "6.6",
+ .mntpoint = MNTPOINT,
+ .format_device = 1,
+ .all_filesystems = 1,
+ .skip_filesystems = (const char *const []) {
+ "fuse",
+ NULL
+ },
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [LTP] [PATCH v3 5/5] Add fchmodat2_02 test
2024-07-24 9:45 [LTP] [PATCH v3 0/5] Add fchmodat2 testing suite Andrea Cervesato
` (3 preceding siblings ...)
2024-07-24 9:45 ` [LTP] [PATCH v3 4/5] Add fchmodat2_01 test Andrea Cervesato
@ 2024-07-24 9:45 ` Andrea Cervesato
4 siblings, 0 replies; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-24 9:45 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test verifies that fchmodat2() syscall properly raises errors with
invalid arguments.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/fchmodat2/.gitignore | 1 +
testcases/kernel/syscalls/fchmodat2/fchmodat2_02.c | 68 ++++++++++++++++++++++
3 files changed, 70 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index b4bb4f391..5cbcf3a4c 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -266,6 +266,7 @@ fchmodat01 fchmodat01
fchmodat02 fchmodat02
fchmodat2_01 fchmodat2_01
+fchmodat2_02 fchmodat2_02
fchown01 fchown01
fchown01_16 fchown01_16
diff --git a/testcases/kernel/syscalls/fchmodat2/.gitignore b/testcases/kernel/syscalls/fchmodat2/.gitignore
index 47d5e2427..9f713198c 100644
--- a/testcases/kernel/syscalls/fchmodat2/.gitignore
+++ b/testcases/kernel/syscalls/fchmodat2/.gitignore
@@ -1 +1,2 @@
fchmodat2_01
+fchmodat2_02
diff --git a/testcases/kernel/syscalls/fchmodat2/fchmodat2_02.c b/testcases/kernel/syscalls/fchmodat2/fchmodat2_02.c
new file mode 100644
index 000000000..f8497d8a8
--- /dev/null
+++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2_02.c
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that fchmodat2() syscall properly raises errors with
+ * invalid values.
+ */
+
+#include "tst_test.h"
+#include "lapi/fcntl.h"
+#include "lapi/syscalls.h"
+#include "tst_tmpdir.h"
+
+#define FILENAME "file.bin"
+
+static char *tmpdir;
+static int fd;
+static int fd_invalid = -1;
+
+static struct tcase {
+ int *fd;
+ char *fname;
+ int mode;
+ int flag;
+ int exp_errno;
+ char *msg;
+} tcases[] = {
+ {&fd_invalid, FILENAME, 0777, 0, EBADF, "bad file descriptor"},
+ {&fd, "doesnt_exist.txt", 0777, 0, ENOENT, "unexisting file"},
+ {&fd, FILENAME, 0777, -1, EINVAL, "invalid flags"},
+};
+
+static void run(unsigned int i)
+{
+ struct tcase *tc = &tcases[i];
+
+ TST_EXP_FAIL(tst_syscall(__NR_fchmodat2,
+ *tc->fd, tc->fname, tc->mode, tc->flag),
+ tc->exp_errno,
+ "Test %s", tc->msg);
+}
+
+static void setup(void)
+{
+ tmpdir = tst_tmpdir_path();
+
+ SAFE_TOUCH(FILENAME, 0640, NULL);
+ fd = SAFE_OPEN(tmpdir, O_PATH | O_DIRECTORY, 0640);
+}
+
+static void cleanup(void)
+{
+ if (fd != -1)
+ SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+ .test = run,
+ .tcnt = ARRAY_SIZE(tcases),
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_tmpdir = 1,
+};
+
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH v3 2/5] Add fchmodat2 syscalls definitions
2024-07-24 9:45 ` [LTP] [PATCH v3 2/5] Add fchmodat2 syscalls definitions Andrea Cervesato
@ 2024-07-29 20:38 ` Petr Vorel
0 siblings, 0 replies; 10+ messages in thread
From: Petr Vorel @ 2024-07-29 20:38 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi Andrea,
after 5d35e26b1ff70ebd0edec47f9ab4f02957a1defc
(cachestat) this patch does not apply any more.
Could you please rebase your branch b4/fchmodat2?
(you don't need to repost).
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH v3 4/5] Add fchmodat2_01 test
2024-07-24 9:45 ` [LTP] [PATCH v3 4/5] Add fchmodat2_01 test Andrea Cervesato
@ 2024-07-30 9:09 ` Petr Vorel
2024-08-01 14:28 ` Andrea Cervesato via ltp
0 siblings, 1 reply; 10+ messages in thread
From: Petr Vorel @ 2024-07-30 9:09 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi Andrea,
FYI when testing on Tumbleweed 6.10.1 kernel the test fails on all filesystems:
fchmodat2.h:17: TPASS: st.st_mode == mode (41471)
../../../../include/lapi/stat.h:239: TBROK: fchmodat2(3,symlink,416,256) error: EOPNOTSUPP (95)
Also, file and line should be from the test (I'll note at the patch).
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH v3 3/5] Add fchmodat2 fallback definition
2024-07-24 9:45 ` [LTP] [PATCH v3 3/5] Add fchmodat2 fallback definition Andrea Cervesato
@ 2024-07-30 9:14 ` Petr Vorel
0 siblings, 0 replies; 10+ messages in thread
From: Petr Vorel @ 2024-07-30 9:14 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi Andrea,
...
> +static inline int fchmodat2(
> + int dfd, const char *filename, mode_t mode, int flags)
IMHO more consistent is:
static inline int fchmodat2(int dfd, const char *filename, mode_t mode, int flags)
But more important, you need to have as first two params: const char *file,
const int lineno, e.g.:
#define SAFE_FCHMODAT2(path, mode) \
safe_access(__FILE__, __LINE__, (filename), (mode), (flags))
static inline int fchmodat2(const char *file, const int lineno, int dfd, const
char *filename, mode_t mode, int flags)
{
...
#
This way instead of this:
../../../../include/lapi/stat.h:239: TBROK: fchmodat2(3,symlink,416,256) error: EOPNOTSUPP (95)
we get file and line of the test (common approach, see lib/tst_safe_macros.c
include/tst_safe_macros.h).
Kind regards,
Petr
> +{
> + int ret;
> +
> + ret = tst_syscall(__NR_fchmodat2, dfd, filename, mode, flags);
> + if (ret == -1)
> + tst_brk(TBROK | TERRNO, "%s(%d,%s,%d,%d) error",
> + __func__, dfd, filename, mode, flags);
> +
> + return ret;
> +}
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH v3 4/5] Add fchmodat2_01 test
2024-07-30 9:09 ` Petr Vorel
@ 2024-08-01 14:28 ` Andrea Cervesato via ltp
0 siblings, 0 replies; 10+ messages in thread
From: Andrea Cervesato via ltp @ 2024-08-01 14:28 UTC (permalink / raw)
To: Petr Vorel, Andrea Cervesato; +Cc: ltp
Hi!
On 7/30/24 11:09, Petr Vorel wrote:
> Hi Andrea,
>
> FYI when testing on Tumbleweed 6.10.1 kernel the test fails on all filesystems:
> fchmodat2.h:17: TPASS: st.st_mode == mode (41471)
> ../../../../include/lapi/stat.h:239: TBROK: fchmodat2(3,symlink,416,256) error: EOPNOTSUPP (95)
> Also, file and line should be from the test (I'll note at the patch).
>
> Kind regards,
> Petr
I explain the reason why fchmodat2 is failing with EOPNOTSUPP on recent
kernels in the testing suite cover letter.
It might be a kernel bug.
Andrea
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-08-01 14:29 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-24 9:45 [LTP] [PATCH v3 0/5] Add fchmodat2 testing suite Andrea Cervesato
2024-07-24 9:45 ` [LTP] [PATCH v3 1/5] Add SAFE_SYMLINKAT macro Andrea Cervesato
2024-07-24 9:45 ` [LTP] [PATCH v3 2/5] Add fchmodat2 syscalls definitions Andrea Cervesato
2024-07-29 20:38 ` Petr Vorel
2024-07-24 9:45 ` [LTP] [PATCH v3 3/5] Add fchmodat2 fallback definition Andrea Cervesato
2024-07-30 9:14 ` Petr Vorel
2024-07-24 9:45 ` [LTP] [PATCH v3 4/5] Add fchmodat2_01 test Andrea Cervesato
2024-07-30 9:09 ` Petr Vorel
2024-08-01 14:28 ` Andrea Cervesato via ltp
2024-07-24 9:45 ` [LTP] [PATCH v3 5/5] Add fchmodat2_02 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