public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/5] Add fchmodat2 testing suite
@ 2024-05-21  6:15 Andrea Cervesato
  2024-05-21  6:15 ` [LTP] [PATCH 1/5] Add SAFE_SYMLINKAT macro Andrea Cervesato
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Andrea Cervesato @ 2024-05-21  6:15 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().

- fchmodat2_01 tests AT_SYMLINK_NOFOLLOW on regular file
- fchmodat2_02 tests AT_SYMLINK_NOFOLLOW on symbolic file
- fchmodat2_03 tests AT_EMPTY_PATH

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>
---
Andrea Cervesato (5):
      Add SAFE_SYMLINKAT macro
      Add fchmodat2 syscall definitions
      Add fchmodat2_01 test
      Add fchmodat2_02 test
      Add fchmodat2_03 test

 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                                   |  4 ++
 testcases/kernel/syscalls/fchmodat2/.gitignore     |  3 ++
 testcases/kernel/syscalls/fchmodat2/Makefile       |  7 +++
 testcases/kernel/syscalls/fchmodat2/fchmodat2.h    | 32 +++++++++++
 testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c | 54 +++++++++++++++++++
 testcases/kernel/syscalls/fchmodat2/fchmodat2_02.c | 63 ++++++++++++++++++++++
 testcases/kernel/syscalls/fchmodat2/fchmodat2_03.c | 46 ++++++++++++++++
 28 files changed, 254 insertions(+)
---
base-commit: e644691d30c3948a9788b735c51e09ca849ea47f
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] 9+ messages in thread

* [LTP] [PATCH 1/5] Add SAFE_SYMLINKAT macro
  2024-05-21  6:15 [LTP] [PATCH 0/5] Add fchmodat2 testing suite Andrea Cervesato
@ 2024-05-21  6:15 ` Andrea Cervesato
  2024-05-21  6:15 ` [LTP] [PATCH 2/5] Add fchmodat2 syscall definitions Andrea Cervesato
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Andrea Cervesato @ 2024-05-21  6:15 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 8de8ef106..764affbd2 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.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 2/5] Add fchmodat2 syscall definitions
  2024-05-21  6:15 [LTP] [PATCH 0/5] Add fchmodat2 testing suite Andrea Cervesato
  2024-05-21  6:15 ` [LTP] [PATCH 1/5] Add SAFE_SYMLINKAT macro Andrea Cervesato
@ 2024-05-21  6:15 ` Andrea Cervesato
  2024-05-21  6:15 ` [LTP] [PATCH 3/5] Add fchmodat2_01 test Andrea Cervesato
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Andrea Cervesato @ 2024-05-21  6:15 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 2cb6c2d87..b2a8e5e8b 100644
--- a/include/lapi/syscalls/aarch64.in
+++ b/include/lapi/syscalls/aarch64.in
@@ -297,4 +297,5 @@ faccessat2 439
 epoll_pwait2 441
 quotactl_fd 443
 futex_waitv 449
+fchmodat2 452
 _sysctl 1078
diff --git a/include/lapi/syscalls/arc.in b/include/lapi/syscalls/arc.in
index 3e2ee9061..adc3e5e70 100644
--- a/include/lapi/syscalls/arc.in
+++ b/include/lapi/syscalls/arc.in
@@ -317,3 +317,4 @@ faccessat2 439
 epoll_pwait2 441
 quotactl_fd 443
 futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in
index 7bdbca533..c2cda553e 100644
--- a/include/lapi/syscalls/arm.in
+++ b/include/lapi/syscalls/arm.in
@@ -395,3 +395,4 @@ faccessat2 (__NR_SYSCALL_BASE+439)
 epoll_pwait2 (__NR_SYSCALL_BASE+441)
 quotactl_fd (__NR_SYSCALL_BASE+443)
 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 8ebdafafb..095261564 100644
--- a/include/lapi/syscalls/hppa.in
+++ b/include/lapi/syscalls/hppa.in
@@ -44,3 +44,4 @@ faccessat2 439
 epoll_pwait2 441
 quotactl_fd 443
 futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in
index 1472631c4..00d2a84d6 100644
--- a/include/lapi/syscalls/i386.in
+++ b/include/lapi/syscalls/i386.in
@@ -431,3 +431,4 @@ faccessat2 439
 epoll_pwait2 441
 quotactl_fd 443
 futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in
index 0ea6e9722..223ea2ee9 100644
--- a/include/lapi/syscalls/ia64.in
+++ b/include/lapi/syscalls/ia64.in
@@ -344,3 +344,4 @@ faccessat2 1463
 epoll_pwait2 1465
 quotactl_fd 1467
 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 e818c9d92..40fdeafb0 100644
--- a/include/lapi/syscalls/mips_n32.in
+++ b/include/lapi/syscalls/mips_n32.in
@@ -371,3 +371,4 @@ epoll_pwait2 6441
 mount_setattr 6442
 quotactl_fd 6443
 futex_waitv 6449
+fchmodat2 6452
diff --git a/include/lapi/syscalls/mips_n64.in b/include/lapi/syscalls/mips_n64.in
index 6e15f43b3..eae498659 100644
--- a/include/lapi/syscalls/mips_n64.in
+++ b/include/lapi/syscalls/mips_n64.in
@@ -347,3 +347,4 @@ epoll_pwait2 5441
 mount_setattr 5442
 quotactl_fd 5443
 futex_waitv 5449
+fchmodat2 5452
diff --git a/include/lapi/syscalls/mips_o32.in b/include/lapi/syscalls/mips_o32.in
index 921d5d331..c355fb9b3 100644
--- a/include/lapi/syscalls/mips_o32.in
+++ b/include/lapi/syscalls/mips_o32.in
@@ -417,3 +417,4 @@ epoll_pwait2 4441
 mount_setattr 4442
 quotactl_fd 4443
 futex_waitv 4449
+fchmodat2 4452
diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in
index 545d9d3d6..f4be8321b 100644
--- a/include/lapi/syscalls/powerpc.in
+++ b/include/lapi/syscalls/powerpc.in
@@ -424,3 +424,4 @@ faccessat2 439
 epoll_pwait2 441
 quotactl_fd 443
 futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in
index 545d9d3d6..f4be8321b 100644
--- a/include/lapi/syscalls/powerpc64.in
+++ b/include/lapi/syscalls/powerpc64.in
@@ -424,3 +424,4 @@ faccessat2 439
 epoll_pwait2 441
 quotactl_fd 443
 futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in
index 7213ac5f8..6c9c59d94 100644
--- a/include/lapi/syscalls/s390.in
+++ b/include/lapi/syscalls/s390.in
@@ -411,3 +411,4 @@ faccessat2 439
 epoll_pwait2 441
 quotactl_fd 443
 futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in
index 879012e2b..b4541ec5a 100644
--- a/include/lapi/syscalls/s390x.in
+++ b/include/lapi/syscalls/s390x.in
@@ -359,3 +359,4 @@ faccessat2 439
 epoll_pwait2 441
 quotactl_fd 443
 futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in
index 7d5192a27..65f8c5bfd 100644
--- a/include/lapi/syscalls/sh.in
+++ b/include/lapi/syscalls/sh.in
@@ -405,3 +405,4 @@ faccessat2 439
 epoll_pwait2 441
 quotactl_fd 443
 futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in
index 91d2fb1c2..05e32ff26 100644
--- a/include/lapi/syscalls/sparc.in
+++ b/include/lapi/syscalls/sparc.in
@@ -410,3 +410,4 @@ faccessat2 439
 epoll_pwait2 441
 quotactl_fd 443
 futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in
index 1f2fc59b7..59dc1ec4d 100644
--- a/include/lapi/syscalls/sparc64.in
+++ b/include/lapi/syscalls/sparc64.in
@@ -375,3 +375,4 @@ faccessat2 439
 epoll_pwait2 441
 quotactl_fd 443
 futex_waitv 449
+fchmodat2 452
diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in
index dc61aa56e..a9b523fdc 100644
--- a/include/lapi/syscalls/x86_64.in
+++ b/include/lapi/syscalls/x86_64.in
@@ -352,6 +352,7 @@ faccessat2 439
 epoll_pwait2 441
 quotactl_fd 443
 futex_waitv 449
+fchmodat2 452
 rt_sigaction 512
 rt_sigreturn 513
 ioctl 514

-- 
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 3/5] Add fchmodat2_01 test
  2024-05-21  6:15 [LTP] [PATCH 0/5] Add fchmodat2 testing suite Andrea Cervesato
  2024-05-21  6:15 ` [LTP] [PATCH 1/5] Add SAFE_SYMLINKAT macro Andrea Cervesato
  2024-05-21  6:15 ` [LTP] [PATCH 2/5] Add fchmodat2 syscall definitions Andrea Cervesato
@ 2024-05-21  6:15 ` Andrea Cervesato
  2024-07-11 12:12   ` Cyril Hrubis
  2024-05-21  6:15 ` [LTP] [PATCH 4/5] Add fchmodat2_02 test Andrea Cervesato
  2024-05-21  6:15 ` [LTP] [PATCH 5/5] Add fchmodat2_03 test Andrea Cervesato
  4 siblings, 1 reply; 9+ messages in thread
From: Andrea Cervesato @ 2024-05-21  6:15 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.h    | 32 +++++++++++++
 testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c | 54 ++++++++++++++++++++++
 5 files changed, 96 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index cf06ee563..0a28530ed 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -264,6 +264,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.h b/testcases/kernel/syscalls/fchmodat2/fchmodat2.h
new file mode 100644
index 000000000..676d491cf
--- /dev/null
+++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef FCHMODAT2_H
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "tst_safe_file_at.h"
+
+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;
+}
+
+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
diff --git a/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
new file mode 100644
index 000000000..9f4960a0c
--- /dev/null
+++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
@@ -0,0 +1,54 @@
+// 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 on regular files.
+ */
+
+#include "fchmodat2.h"
+#include "lapi/fcntl.h"
+
+#define MNTPOINT "mntpoint"
+#define FNAME "myfile"
+
+static int fd_dir = -1;
+
+static void run(void)
+{
+	SAFE_CHMOD(MNTPOINT"/"FNAME, 0640);
+
+	TST_EXP_PASS(fchmodat2(fd_dir, FNAME, 0700, AT_SYMLINK_NOFOLLOW));
+	verify_mode(fd_dir, FNAME, S_IFREG | 0700);
+}
+
+static void setup(void)
+{
+	fd_dir = SAFE_OPEN(MNTPOINT, O_PATH | O_DIRECTORY, 0640);
+
+	SAFE_TOUCH(MNTPOINT"/"FNAME, 0640, NULL);
+}
+
+static void cleanup(void)
+{
+	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.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 4/5] Add fchmodat2_02 test
  2024-05-21  6:15 [LTP] [PATCH 0/5] Add fchmodat2 testing suite Andrea Cervesato
                   ` (2 preceding siblings ...)
  2024-05-21  6:15 ` [LTP] [PATCH 3/5] Add fchmodat2_01 test Andrea Cervesato
@ 2024-05-21  6:15 ` Andrea Cervesato
  2024-07-11 12:16   ` Cyril Hrubis
  2024-05-21  6:15 ` [LTP] [PATCH 5/5] Add fchmodat2_03 test Andrea Cervesato
  4 siblings, 1 reply; 9+ messages in thread
From: Andrea Cervesato @ 2024-05-21  6:15 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 symbolic links.

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 | 63 ++++++++++++++++++++++
 3 files changed, 65 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index 0a28530ed..c3712da36 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -265,6 +265,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..4afe7f3f9
--- /dev/null
+++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2_02.c
@@ -0,0 +1,63 @@
+// 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 on symbolic links.
+ */
+
+#include "fchmodat2.h"
+#include "lapi/fcntl.h"
+
+#define MNTPOINT "mntpoint"
+#define FNAME "myfile"
+#define SNAME "symlink"
+
+static int fd_dir = -1;
+
+static void run(void)
+{
+	SAFE_CHMOD(MNTPOINT"/"FNAME, 0640);
+
+	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 setup(void)
+{
+	fd_dir = SAFE_OPEN(MNTPOINT, O_PATH | O_DIRECTORY, 0640);
+
+	SAFE_TOUCH(MNTPOINT"/"FNAME, 0640, NULL);
+	SAFE_SYMLINKAT(FNAME, fd_dir, SNAME);
+}
+
+static void cleanup(void)
+{
+	SAFE_UNLINKAT(fd_dir, SNAME, 0);
+
+	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.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 5/5] Add fchmodat2_03 test
  2024-05-21  6:15 [LTP] [PATCH 0/5] Add fchmodat2 testing suite Andrea Cervesato
                   ` (3 preceding siblings ...)
  2024-05-21  6:15 ` [LTP] [PATCH 4/5] Add fchmodat2_02 test Andrea Cervesato
@ 2024-05-21  6:15 ` Andrea Cervesato
  2024-07-11 12:18   ` Cyril Hrubis
  4 siblings, 1 reply; 9+ messages in thread
From: Andrea Cervesato @ 2024-05-21  6:15 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

This test verifies that fchmodat2() syscall is properly working with
AT_EMPTY_PATH.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                   |  1 +
 testcases/kernel/syscalls/fchmodat2/.gitignore     |  1 +
 testcases/kernel/syscalls/fchmodat2/fchmodat2_03.c | 46 ++++++++++++++++++++++
 3 files changed, 48 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index c3712da36..51b1ad535 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -266,6 +266,7 @@ fchmodat02 fchmodat02
 
 fchmodat2_01 fchmodat2_01
 fchmodat2_02 fchmodat2_02
+fchmodat2_03 fchmodat2_03
 
 fchown01 fchown01
 fchown01_16 fchown01_16
diff --git a/testcases/kernel/syscalls/fchmodat2/.gitignore b/testcases/kernel/syscalls/fchmodat2/.gitignore
index 9f713198c..c46387095 100644
--- a/testcases/kernel/syscalls/fchmodat2/.gitignore
+++ b/testcases/kernel/syscalls/fchmodat2/.gitignore
@@ -1,2 +1,3 @@
 fchmodat2_01
 fchmodat2_02
+fchmodat2_03
diff --git a/testcases/kernel/syscalls/fchmodat2/fchmodat2_03.c b/testcases/kernel/syscalls/fchmodat2/fchmodat2_03.c
new file mode 100644
index 000000000..a912b95c8
--- /dev/null
+++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2_03.c
@@ -0,0 +1,46 @@
+// 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_EMPTY_PATH.
+ */
+
+#include "fchmodat2.h"
+#include "lapi/fcntl.h"
+
+#define MNTPOINT "mntpoint"
+#define DNAME MNTPOINT "/mydir"
+
+static void run(void)
+{
+	int fd;
+	struct stat st;
+
+	SAFE_MKDIR(DNAME, 0640);
+	fd = SAFE_OPEN(DNAME, O_PATH | O_DIRECTORY, 0640);
+
+	TST_EXP_PASS(fchmodat2(fd, "", 0777, AT_EMPTY_PATH));
+
+	SAFE_FSTAT(fd, &st);
+	TST_EXP_EQ_LI(st.st_mode, S_IFDIR | 0777);
+
+	SAFE_CLOSE(fd);
+	SAFE_RMDIR(DNAME);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.min_kver = "6.6",
+	.mntpoint = MNTPOINT,
+	.format_device = 1,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const []) {
+		"fuse",
+		NULL
+	},
+};

-- 
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH 3/5] Add fchmodat2_01 test
  2024-05-21  6:15 ` [LTP] [PATCH 3/5] Add fchmodat2_01 test Andrea Cervesato
@ 2024-07-11 12:12   ` Cyril Hrubis
  0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2024-07-11 12:12 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> diff --git a/testcases/kernel/syscalls/fchmodat2/fchmodat2.h b/testcases/kernel/syscalls/fchmodat2/fchmodat2.h
> new file mode 100644
> index 000000000..676d491cf
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2.h
> @@ -0,0 +1,32 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +#ifndef FCHMODAT2_H

Missing #define FCHMODAT2_H

> +
> +#include "tst_test.h"
> +#include "lapi/syscalls.h"
> +#include "tst_safe_file_at.h"
> +
> +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;
> +}


This should probably go into lapi.

> +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
> diff --git a/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
> new file mode 100644
> index 000000000..9f4960a0c
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
> @@ -0,0 +1,54 @@
> +// 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 on regular files.
> + */
> +
> +#include "fchmodat2.h"
> +#include "lapi/fcntl.h"
> +
> +#define MNTPOINT "mntpoint"
> +#define FNAME "myfile"
> +
> +static int fd_dir = -1;
> +
> +static void run(void)
> +{
> +	SAFE_CHMOD(MNTPOINT"/"FNAME, 0640);
> +
> +	TST_EXP_PASS(fchmodat2(fd_dir, FNAME, 0700, AT_SYMLINK_NOFOLLOW));
> +	verify_mode(fd_dir, FNAME, S_IFREG | 0700);
> +}
> +
> +static void setup(void)
> +{
> +	fd_dir = SAFE_OPEN(MNTPOINT, O_PATH | O_DIRECTORY, 0640);
> +
> +	SAFE_TOUCH(MNTPOINT"/"FNAME, 0640, NULL);
> +}
> +
> +static void cleanup(void)
> +{
> +	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.35.3
> 
> 
> -- 
> 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] 9+ messages in thread

* Re: [LTP] [PATCH 4/5] Add fchmodat2_02 test
  2024-05-21  6:15 ` [LTP] [PATCH 4/5] Add fchmodat2_02 test Andrea Cervesato
@ 2024-07-11 12:16   ` Cyril Hrubis
  0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2024-07-11 12:16 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
This and the previous tests are quite simple, maybe it would be better
to keep all the NOFOLLOW tests in a single testcase. That would save us
some reformatting and mounting the loop devices.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH 5/5] Add fchmodat2_03 test
  2024-05-21  6:15 ` [LTP] [PATCH 5/5] Add fchmodat2_03 test Andrea Cervesato
@ 2024-07-11 12:18   ` Cyril Hrubis
  0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2024-07-11 12:18 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
Again this is quite simple, maybe all three tests should be just
subtests in a single testcase.

Also we are missing invalid flags tests, etc.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-07-11 12:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-21  6:15 [LTP] [PATCH 0/5] Add fchmodat2 testing suite Andrea Cervesato
2024-05-21  6:15 ` [LTP] [PATCH 1/5] Add SAFE_SYMLINKAT macro Andrea Cervesato
2024-05-21  6:15 ` [LTP] [PATCH 2/5] Add fchmodat2 syscall definitions Andrea Cervesato
2024-05-21  6:15 ` [LTP] [PATCH 3/5] Add fchmodat2_01 test Andrea Cervesato
2024-07-11 12:12   ` Cyril Hrubis
2024-05-21  6:15 ` [LTP] [PATCH 4/5] Add fchmodat2_02 test Andrea Cervesato
2024-07-11 12:16   ` Cyril Hrubis
2024-05-21  6:15 ` [LTP] [PATCH 5/5] Add fchmodat2_03 test Andrea Cervesato
2024-07-11 12:18   ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox