From 7aaef1ee4f3d7ddee93a6e428a6a6338f665ce8c Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Fri, 5 Jul 2013 12:19:54 +0400 Subject: [PATCH] mount: don't destruct an external mount-namespace (v2) If a parent mount point is shared with exteranl mntns, a child will be umounted from the external mntns too. For example: $ mount -t tmpfs xxx /root/tmp/ $ mount --make-shared tmp $ mkdir tmp/xxx $ mount -t tmpfs xxx /root/tmp/xxx $ touch tmp/xxx/a $ unshare -m umount tmp/xxx $ ls -l tmp/xxx/a ls: cannot access tmp/xxx/a: No such file or directory This patch changes a parent mnt to private for umounting childrens. v2: exit if a mount point can not be marked ad private Signed-off-by: Andrey Vagin Signed-off-by: Pavel Emelyanov --- mount.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mount.c b/mount.c index 68ccd352a..74e7748f6 100644 --- a/mount.c +++ b/mount.c @@ -590,6 +590,11 @@ static int do_umount_one(struct mount_info *mi) if (!mi->parent) return 0; + if (mount("none", mi->parent->mountpoint, "none", MS_REC|MS_PRIVATE, NULL)) { + pr_perror("Can't mark %s as private", mi->parent->mountpoint); + return -1; + } + if (umount(mi->mountpoint)) { pr_perror("Can't umount at %s", mi->mountpoint); return -1;