@@ -264,6 +264,8 @@ fchmod06 fchmod06
fchmodat01 fchmodat01
fchmodat02 fchmodat02
+fchmodat2_01 fchmodat2_01
+
fchown01 fchown01
fchown01_16 fchown01_16
fchown02 fchown02
new file mode 100644
@@ -0,0 +1 @@
+fchmodat2_01
new file mode 100644
@@ -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
new file mode 100644
@@ -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
new file mode 100644
@@ -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
+ },
+};