linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mount: fix duplicate mounts using the new mount API
@ 2025-10-25  2:49 GuangFei Luo
  2025-10-25  3:36 ` Al Viro
  2025-10-29  3:06 ` kernel test robot
  0 siblings, 2 replies; 7+ messages in thread
From: GuangFei Luo @ 2025-10-25  2:49 UTC (permalink / raw)
  To: viro; +Cc: brauner, jack, linux-fsdevel, linux-kernel, GuangFei Luo, stable

When using the new mount API, invoking the same mount command multiple
times such as:
mount /dev/mapper/mydevice /mnt/mydisk2
results in multiple identical mount entries being created:
/dev/mapper/mydevice on /mnt/mydisk2 type ext4 (rw,relatime)
/dev/mapper/mydevice on /mnt/mydisk2 type ext4 (rw,relatime)
/dev/mapper/mydevice on /mnt/mydisk2 type ext4 (rw,relatime)
...

Fixes: 2db154b3ea8e ("vfs: syscall: Add move_mount(2) to move mounts around")
Signed-off-by: GuangFei Luo <luogf2025@163.com>
Cc: <stable@vger.kernel.org> # 5.2+
---
 fs/namespace.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fs/namespace.c b/fs/namespace.c
index d82910f33dc4..9436471955ce 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -4427,6 +4427,7 @@ SYSCALL_DEFINE5(move_mount,
 {
 	struct path to_path __free(path_put) = {};
 	struct path from_path __free(path_put) = {};
+	struct path path __free(path_put) = {};
 	struct filename *to_name __free(putname) = NULL;
 	struct filename *from_name __free(putname) = NULL;
 	unsigned int lflags, uflags;
@@ -4472,6 +4473,14 @@ SYSCALL_DEFINE5(move_mount,
 			return ret;
 	}
 
+	ret = user_path_at(AT_FDCWD, to_pathname, LOOKUP_FOLLOW, &path);
+	if (ret)
+		return ret;
+
+	/* Refuse the same filesystem on the same mount point */
+	if (path.mnt->mnt_sb == to_path.mnt->mnt_sb && path_mounted(&path))
+		return -EBUSY;
+
 	uflags = 0;
 	if (flags & MOVE_MOUNT_F_EMPTY_PATH)
 		uflags = AT_EMPTY_PATH;
-- 
2.43.0


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

end of thread, other threads:[~2025-11-05 11:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-25  2:49 [PATCH] mount: fix duplicate mounts using the new mount API GuangFei Luo
2025-10-25  3:36 ` Al Viro
2025-10-25  6:02   ` GuangFei Luo
2025-10-31 12:54     ` Christian Brauner
2025-10-31 18:48       ` Al Viro
2025-11-05 11:54         ` Christian Brauner
2025-10-29  3:06 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).