Skip to contentSkip to conversation

Add fchmodat2 testing suite

PATCH Superseded Andrea Cervesato 2 participants 7 messages Jul 23, 2024 – Jul 24, 2024 Library code

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

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:

https://github.com/torvalds/linux/blob/8f6a15f095a63a83b096d9b29aaff4f0fbe6f6e6/tools/testing/selftests/fchmodat2/fchmodat2_test.c#L123

---
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
#1 lore raw

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
index d256091b7..6d9e72e4f 100644
@@ -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
index 92b9bc119..47a6f99df 100644
@@ -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
index 109268587..f91e77022 100644
@@ -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
#2 lore raw

PATCH v2 2/5 Add fchmodat2 syscalls definitions

In reply to Andrea Cervesato

From: 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
index 3e7797718..6c3bd69b5 100644
@@ -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
index 7fde1d263..f1721551e 100644
@@ -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
index 8e76ad164..032941b7e 100644
@@ -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
index 60c02aff2..39fdcc1d9 100644
@@ -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
index 31ec1ecb2..36129b491 100644
@@ -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
index 2e56da7f9..60f657457 100644
@@ -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
index 301f611f6..63e05d6b6 100644
@@ -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
index 5f0fe65eb..b53fefc1f 100644
@@ -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
index f81c60e66..d9336c6e3 100644
@@ -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
index c2beffb75..30d42419e 100644
@@ -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
index 5460e4197..2a2259841 100644
@@ -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
index 5460e4197..2a2259841 100644
@@ -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
index 275b27f47..656f5c118 100644
@@ -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
index c200d02b2..46007bf89 100644
@@ -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
index 6f482a77b..df7c1c378 100644
@@ -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
index 7181e80a0..03030dd30 100644
@@ -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
index c96ab2021..4ab40a5c5 100644
@@ -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
index 3082ca110..57ffce837 100644
@@ -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
#3 lore raw

PATCH v2 3/5 Add fchmodat2 fallback definition

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

---
 include/lapi/stat.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
include/lapi/stat.h +13 -0
index 3606c9eb0..5e289d3ca 100644
@@ -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
#4 lore raw

PATCH v2 4/5 Add fchmodat2_01 test

In reply to Andrea Cervesato

From: 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
index 27eb9a86b..b4bb4f391 100644
@@ -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
new file mode 100644
index 000000000..47d5e2427
@@ -0,0 +1 @@
+fchmodat2_01
testcases/kernel/syscalls/fchmodat2/Makefile new file +7 -0
new file mode 100644
index 000000000..8cf1b9024
@@ -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
new file mode 100644
index 000000000..4d8449fe9
@@ -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
#5 lore raw

PATCH v2 5/5 Add fchmodat2_02 test

In reply to Andrea Cervesato

From: 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
index b4bb4f391..5cbcf3a4c 100644
@@ -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
index 47d5e2427..9f713198c 100644
@@ -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
#6 lore raw
In reply to Andrea Cervesato

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 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

---
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 · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp