public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v1] move_mount03: check allow to mount beneath top mount
@ 2023-09-13 10:15 Wei Gao via ltp
  2023-11-14  9:17 ` Richard Palethorpe
  2023-12-27  0:04 ` [LTP] [PATCH v2] " Wei Gao via ltp
  0 siblings, 2 replies; 17+ messages in thread
From: Wei Gao via ltp @ 2023-09-13 10:15 UTC (permalink / raw)
  To: ltp

Signed-off-by: Wei Gao <wegao@suse.com>
---
 include/lapi/fsmount.h                        |  4 ++
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/move_mount/.gitignore     |  1 +
 .../kernel/syscalls/move_mount/move_mount03.c | 63 +++++++++++++++++++
 4 files changed, 69 insertions(+)
 create mode 100644 testcases/kernel/syscalls/move_mount/move_mount03.c

diff --git a/include/lapi/fsmount.h b/include/lapi/fsmount.h
index 07eb42ffa..216e966c7 100644
--- a/include/lapi/fsmount.h
+++ b/include/lapi/fsmount.h
@@ -115,6 +115,10 @@ static inline int mount_setattr(int dirfd, const char *from_pathname, unsigned i
 }
 #endif /* HAVE_MOUNT_SETATTR */
 
+#ifndef MOVE_MOUNT_BENEATH
+#define MOVE_MOUNT_BENEATH 		0x00000200
+#endif /* MOVE_MOUNT_BENEATH */
+
 /*
  * New headers added in kernel after 5.2 release, create them for old userspace.
 */
diff --git a/runtest/syscalls b/runtest/syscalls
index b1125dd75..04b758fd9 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -824,6 +824,7 @@ mount_setattr01 mount_setattr01
 
 move_mount01 move_mount01
 move_mount02 move_mount02
+move_mount03 move_mount03
 
 move_pages01 move_pages01
 move_pages02 move_pages02
diff --git a/testcases/kernel/syscalls/move_mount/.gitignore b/testcases/kernel/syscalls/move_mount/.gitignore
index 83ae40145..ddfe10128 100644
--- a/testcases/kernel/syscalls/move_mount/.gitignore
+++ b/testcases/kernel/syscalls/move_mount/.gitignore
@@ -1,2 +1,3 @@
 /move_mount01
 /move_mount02
+/move_mount03
diff --git a/testcases/kernel/syscalls/move_mount/move_mount03.c b/testcases/kernel/syscalls/move_mount/move_mount03.c
new file mode 100644
index 000000000..071fd984c
--- /dev/null
+++ b/testcases/kernel/syscalls/move_mount/move_mount03.c
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2023 Wei Gao <wegao@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify allow to mount beneath top mount
+ *
+ */
+
+#include <stdio.h>
+
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+#include "lapi/sched.h"
+
+#define MNTPOINT "mntpoint"
+#define DIRA "LTP_DIR_A"
+
+static void run(void)
+{
+	int fd;
+
+	SAFE_UNSHARE(CLONE_NEWNS);
+	SAFE_MKDIR(DIRA, 0777);
+	SAFE_TOUCH(DIRA "/A", 0, NULL);
+	/* The parent mnt should be private if check MOVE_MOUNT_BENEATH */
+	SAFE_MOUNT("none", "/", "none", MS_REC | MS_PRIVATE, NULL);
+	SAFE_MOUNT(DIRA, DIRA, "none", MS_BIND, NULL);
+	fd = SAFE_OPEN(DIRA, O_RDONLY | O_DIRECTORY);
+
+	TST_EXP_PASS(move_mount(fd, "", AT_FDCWD, MNTPOINT,
+				MOVE_MOUNT_BENEATH | MOVE_MOUNT_F_EMPTY_PATH));
+
+	if (access(MNTPOINT "/A", F_OK) == 0)
+		tst_res(TFAIL, "mount beneath top mount failed");
+	else
+		tst_res(TPASS, "mount beneath top mount pass");
+
+	if (tst_is_mounted_at_tmpdir(MNTPOINT))
+		SAFE_UMOUNT(MNTPOINT);
+
+	if (access(MNTPOINT "/A", F_OK) == 0)
+		tst_res(TPASS, "mount beneath top mount pass");
+	else
+		tst_res(TFAIL, "mount beneath top mount failed");
+
+	remove(DIRA "/A");
+	SAFE_RMDIR(DIRA);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const []){"fuse", NULL},
+	.min_kver = "6.5.0"
+};
-- 
2.35.3


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

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

end of thread, other threads:[~2025-02-21 10:35 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-13 10:15 [LTP] [PATCH v1] move_mount03: check allow to mount beneath top mount Wei Gao via ltp
2023-11-14  9:17 ` Richard Palethorpe
2023-12-26 15:11   ` Wei Gao via ltp
2023-12-27  0:04 ` [LTP] [PATCH v2] " Wei Gao via ltp
2023-12-27 14:26   ` Petr Vorel
2023-12-28  2:53     ` Wei Gao via ltp
2023-12-28  2:55   ` [LTP] [PATCH v3] " Wei Gao via ltp
2024-03-06 17:24     ` Martin Doucha
2024-03-20  7:43       ` Petr Vorel
2024-03-20  9:25         ` Martin Doucha
2024-03-20  9:54           ` Petr Vorel
2024-03-21  4:46           ` Petr Vorel
2024-03-22 11:20     ` [LTP] [PATCH v4] " Wei Gao via ltp
2024-05-17 14:48       ` Martin Doucha
2024-06-03  7:38         ` Petr Vorel
2024-06-05 10:59       ` [LTP] [PATCH v5] " Wei Gao via ltp
2025-02-21 10:35         ` Petr Vorel

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