Add fchmodat2 testing suite
v2 cover Add fchmodat2 testing suite
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:
---
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/[email protected]
---
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.h | 20 ++++ testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c | 105 +++++++++++++++++++++ testcases/kernel/syscalls/fchmodat2/fchmodat2_02.c | 68 +++++++++++++ 28 files changed, 263 insertions(+)
---
base-commit: c5d95b6d34e2356bd19e6b646da06f1bce66a024
change-id: 20240517-fchmodat2-5b82867d71fc
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/5 Add SAFE_SYMLINKAT macro
From: Andrea Cervesato <[email protected]>
--- include/safe_macros_fn.h | 4 ++++ include/tst_safe_macros.h | 3 +++ lib/safe_macros.c | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+)
include/safe_macros_fn.h +4 -0
@@ -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);
include/tst_safe_macros.h +3 -0
@@ -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))
lib/safe_macros.c +20 -0
@@ -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)
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/5 Add fchmodat2 syscalls definitions
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- 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(+)
include/lapi/syscalls/aarch64.in +1 -0
@@ -300,4 +300,5 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +fchmodat2 452 _sysctl 1078
include/lapi/syscalls/arc.in +1 -0
@@ -320,3 +320,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +fchmodat2 452
include/lapi/syscalls/arm.in +1 -0
@@ -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)
include/lapi/syscalls/hppa.in +1 -0
@@ -47,3 +47,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +fchmodat2 452
include/lapi/syscalls/i386.in +1 -0
@@ -434,3 +434,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +fchmodat2 452
include/lapi/syscalls/ia64.in +1 -0
@@ -347,3 +347,4 @@ landlock_create_ruleset 1468 landlock_add_rule 1469 landlock_restrict_self 1470 futex_waitv 1473 +fchmodat2 1476
include/lapi/syscalls/loongarch.in +1 -0
@@ -305,3 +305,4 @@ memfd_secret 447 process_mrelease 448 futex_waitv 449 set_mempolicy_home_node 450 +fchmodat2 452
include/lapi/syscalls/mips_n32.in +1 -0
@@ -374,3 +374,4 @@ landlock_create_ruleset 6444 landlock_add_rule 6445 landlock_restrict_self 6446 futex_waitv 6449 +fchmodat2 6452
include/lapi/syscalls/mips_n64.in +1 -0
@@ -350,3 +350,4 @@ landlock_create_ruleset 5444 landlock_add_rule 5445 landlock_restrict_self 5446 futex_waitv 5449 +fchmodat2 5452
include/lapi/syscalls/mips_o32.in +1 -0
@@ -420,3 +420,4 @@ landlock_create_ruleset 4444 landlock_add_rule 4445 landlock_restrict_self 4446 futex_waitv 4449 +fchmodat2 4452
include/lapi/syscalls/powerpc.in +1 -0
@@ -427,3 +427,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +fchmodat2 452
include/lapi/syscalls/powerpc64.in +1 -0
@@ -427,3 +427,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +fchmodat2 452
include/lapi/syscalls/s390.in +1 -0
@@ -414,3 +414,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +fchmodat2 452
include/lapi/syscalls/s390x.in +1 -0
@@ -362,3 +362,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +fchmodat2 452
include/lapi/syscalls/sh.in +1 -0
@@ -408,3 +408,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +fchmodat2 452
include/lapi/syscalls/sparc.in +1 -0
@@ -413,3 +413,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +fchmodat2 452
include/lapi/syscalls/sparc64.in +1 -0
@@ -378,3 +378,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +fchmodat2 452
include/lapi/syscalls/x86_64.in +1 -0
@@ -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
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/5 Add fchmodat2 fallback definition
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- include/lapi/stat.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/lapi/stat.h +13 -0
@@ -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__ */
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 4/5 Add fchmodat2_01 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that fchmodat2() syscall is properly working with AT_SYMLINK_NOFOLLOW on regular files.
--- runtest/syscalls | 2 + testcases/kernel/syscalls/fchmodat2/.gitignore | 1 + testcases/kernel/syscalls/fchmodat2/Makefile | 7 ++ testcases/kernel/syscalls/fchmodat2/fchmodat2.h | 20 ++++ testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c | 105 +++++++++++++++++++++ 5 files changed, 135 insertions(+)
runtest/syscalls +2 -0
@@ -265,6 +265,8 @@ fchmod06 fchmod06 fchmodat01 fchmodat01 fchmodat02 fchmodat02 +fchmodat2_01 fchmodat2_01 + fchown01 fchown01 fchown01_16 fchown01_16 fchown02 fchown02
testcases/kernel/syscalls/fchmodat2/.gitignore new file +1 -0
@@ -0,0 +1 @@ +fchmodat2_01
testcases/kernel/syscalls/fchmodat2/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/fchmodat2/fchmodat2.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +#ifndef FCHMODAT2_H +#define FCHMODAT2_H + +#include "tst_test.h" +#include "tst_safe_file_at.h" + +static inline 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); +} + +#endif
testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c new file +105 -0
105 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 5/5 Add fchmodat2_02 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that fchmodat2() syscall properly raises errors with invalid arguments.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/fchmodat2/.gitignore | 1 + testcases/kernel/syscalls/fchmodat2/fchmodat2_02.c | 68 ++++++++++++++++++++++ 3 files changed, 70 insertions(+)
runtest/syscalls +1 -0
@@ -266,6 +266,7 @@ fchmodat01 fchmodat01 fchmodat02 fchmodat02 fchmodat2_01 fchmodat2_01 +fchmodat2_02 fchmodat2_02 fchown01 fchown01 fchown01_16 fchown01_16
testcases/kernel/syscalls/fchmodat2/.gitignore +1 -0
@@ -1 +1,2 @@ fchmodat2_01 +fchmodat2_02
testcases/kernel/syscalls/fchmodat2/fchmodat2_02.c new file +68 -0
68 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi,
I just noticed an error in the patch. fchmodat2.h can be merged with the first test. I will send v3, please ignore this v2.
Thanks,
Andrea
Quoted 73 lines · Andrea Cervesato
This is a patch-set that implements
fchmodat2()syscall coverage.fchmodat2()has been added in kernel 6.6 in order to supportAT_SYMLINK_NOFOLLOWandAT_EMPTY_PATHinfchmodat(). 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_02fails with EOPNOTSUPP because of missing feature. According to documentation, the feature has been implemented in kernel 6.6, but__inreality__AT_SYMLINK_NOFOLLOWis not working on symbolic files. Also kselftests, which are meant to test the functionality, are not working and they are treatingfchmodat2()syscall failure as SKIP. Please take a look at the following code before reviewing:Signed-off-by Andrea Cervesato <[email protected]>---
Changes in v2:
- merge first 3 tests into a unique one
- move fchmodat2 inlapi/stat.h
- add test for error checking
- Link to v1: https://lore.kernel.org/r/[email protected]---
Andrea Cervesato (5):
AddSAFE_SYMLINKATmacro
Add fchmodat2 syscalls definitions
Add fchmodat2 fallback definition
Addfchmodat2_01test
Addfchmodat2_02testinclude/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.h | 20 ++++ testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c | 105 +++++++++++++++++++++ testcases/kernel/syscalls/fchmodat2/fchmodat2_02.c | 68 +++++++++++++ 28 files changed, 263 insertions(+)---
base-commit:c5d95b6d34e2356bd19e6b646da06f1bce66a024
change-id: 20240517-fchmodat2-5b82867d71fcBest regards,
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp