Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH v1] mount08.c: Restrict overmounting of ephemeral entities on /proc/<pid>/fd/<nr>
@ 2024-12-25 11:42 Wei Gao via ltp
  2025-02-19 13:27 ` Andrea Cervesato via ltp
  2025-03-19  4:47 ` [LTP] [PATCH v2] " Wei Gao via ltp
  0 siblings, 2 replies; 18+ messages in thread
From: Wei Gao via ltp @ 2024-12-25 11:42 UTC (permalink / raw)
  To: ltp

Signed-off-by: Wei Gao <wegao@suse.com>
---
 runtest/syscalls                           |  1 +
 testcases/kernel/syscalls/mount/.gitignore |  1 +
 testcases/kernel/syscalls/mount/mount08.c  | 56 ++++++++++++++++++++++
 3 files changed, 58 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mount/mount08.c

diff --git a/runtest/syscalls b/runtest/syscalls
index ded035ee8..d3abc8b85 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -852,6 +852,7 @@ mount04 mount04
 mount05 mount05
 mount06 mount06
 mount07 mount07
+mount08 mount08
 
 mount_setattr01 mount_setattr01
 
diff --git a/testcases/kernel/syscalls/mount/.gitignore b/testcases/kernel/syscalls/mount/.gitignore
index 80885dbf0..3eee5863a 100644
--- a/testcases/kernel/syscalls/mount/.gitignore
+++ b/testcases/kernel/syscalls/mount/.gitignore
@@ -6,3 +6,4 @@
 /mount05
 /mount06
 /mount07
+/mount08
diff --git a/testcases/kernel/syscalls/mount/mount08.c b/testcases/kernel/syscalls/mount/mount08.c
new file mode 100644
index 000000000..9b54ea835
--- /dev/null
+++ b/testcases/kernel/syscalls/mount/mount08.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 Wei Gao <wegao@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test check restrict overmounting on /proc/<pid>/fd/<nr>.
+ * It is based on the following kernel commit:
+ * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d80b065bb172
+ */
+
+#include "tst_test.h"
+#include <sys/mount.h>
+#include "tst_safe_file_at.h"
+
+#define MNTPOINT "mntpoint"
+#define FOO MNTPOINT "/foo"
+#define BAR MNTPOINT "/bar"
+
+static void run(void)
+{
+	char path[PATH_MAX];
+	int foo_fd, newfd, proc_fd;
+
+	foo_fd = SAFE_OPEN(FOO, O_RDONLY | O_NONBLOCK, 0640);
+	newfd = SAFE_DUP(foo_fd);
+	SAFE_CLOSE(foo_fd);
+
+	sprintf(path, "/proc/%d/fd/%d", getpid(), newfd);
+
+	proc_fd = SAFE_OPENAT(AT_FDCWD, path, O_PATH | O_NOFOLLOW);
+
+	sprintf(path, "/proc/%d/fd/%d", getpid(), proc_fd);
+
+	TST_EXP_FAIL(
+		mount(BAR, path, "", MS_BIND, 0),
+		ENOENT,
+		"mount() on proc failed expectedly"
+	);
+}
+
+static void setup(void)
+{
+	SAFE_CREAT(FOO, 0777);
+	SAFE_CREAT(BAR, 0777);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.mntpoint = MNTPOINT,
+	.min_kver = "6.12",
+};
-- 
2.35.3


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

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

end of thread, other threads:[~2025-07-25  0:55 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-25 11:42 [LTP] [PATCH v1] mount08.c: Restrict overmounting of ephemeral entities on /proc/<pid>/fd/<nr> Wei Gao via ltp
2025-02-19 13:27 ` Andrea Cervesato via ltp
2025-03-19  4:47 ` [LTP] [PATCH v2] " Wei Gao via ltp
2025-03-20 14:53   ` Andrea Cervesato via ltp
2025-03-21  3:42   ` [LTP] [PATCH v3] mount08.c: Restrict overmounting of ephemeral entities Wei Gao via ltp
2025-03-21 10:27     ` Ricardo B. Marli��re via ltp
2025-03-21 15:14       ` Wei Gao via ltp
2025-03-21 15:11     ` [LTP] [PATCH v4] " Wei Gao via ltp
2025-07-11 13:02       ` Cyril Hrubis
2025-07-21 20:04       ` [LTP] [PATCH v5] " Wei Gao via ltp
2025-07-22  6:40         ` Andrea Cervesato via ltp
2025-07-22 19:00           ` Wei Gao via ltp
2025-07-22 18:54         ` [LTP] [PATCH v6] " Wei Gao via ltp
2025-07-23 11:51           ` Andrea Cervesato via ltp
2025-07-23 12:42           ` Cyril Hrubis
2025-07-24 17:04           ` Petr Vorel
2025-07-24 17:10             ` Petr Vorel
2025-07-25 12:54               ` Wei Gao via ltp

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