[Bug 11636] New: switch_root: fix to zap initramfs's sub-directories for the mount point of new root file system

bugzilla at busybox.net bugzilla at busybox.net
Thu Jan 24 15:34:03 UTC 2019


https://bugs.busybox.net/show_bug.cgi?id=11636

            Bug ID: 11636
           Summary: switch_root: fix to zap initramfs's sub-directories
                    for the mount point of new root file system
           Product: Busybox
           Version: 1.30.x
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P5
         Component: Other
          Assignee: unassigned at busybox.net
          Reporter: abo_junghichi at yahoo.co.jp
                CC: busybox-cvs at busybox.net
  Target Milestone: ---

As Rob seid in the comment of util-linux/switch_root.c, current imprementation
doesn't rmdir() sub-directory for the mount point of new root-file-system.
This patch fixes this by zapping old root-file-system after remounting new
root-file-system to "/".
Since current process of "/" still points old root-file-system until chroot()
is initiated, we can still access and zap ititramfs after mount point of new
root-file-system is moved from sub-directory of initramfs.

diff -Naur busybox-1.30.0.org/util-linux/switch_root.c
busybox-1.30.0.fix/util-linux/switch_root.c
--- busybox-1.30.0.org/util-linux/switch_root.c 2018-12-31 00:14:20.000000000
+0900
+++ busybox-1.30.0.fix/util-linux/switch_root.c 2019-01-25 00:20:57.078879499
+0900
@@ -257,14 +257,14 @@
        }

        if (!dry_run) {
-               // Zap everything out of rootdev
-               delete_contents("/", rootdev);
-
                // Overmount / with newdir and chroot into it
                if (mount(".", "/", NULL, MS_MOVE, NULL)) {
                        // For example, fails when newroot is not a mountpoint
                        bb_perror_msg_and_die("error moving root");
                }
+
+               // Zap everything out of rootdev
+               delete_contents("/", rootdev);
        }
        xchroot(".");
        // The chdir is needed to recalculate "." and ".." links

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the busybox-cvs mailing list