]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
switch_root: Add a sanity check
authorRichard Weinberger <richard@nod.at>
Sat, 9 Feb 2013 18:22:50 +0000 (19:22 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 13 Feb 2013 13:55:30 +0000 (14:55 +0100)
As switch_root basically does rm -Rf / we should make sure
that / is really an initramfs.

Signed-off-by: Richard Weinberger <richard@nod.at>
sys-utils/switch_root.c

index f0ef67745fcade5ae1cf9251b6a745f425ea53f5..f26f7dae4326163a0543428cbb167b49233a33e2 100644 (file)
@@ -174,7 +174,13 @@ static int switchroot(const char *newroot)
        if (cfd >= 0) {
                pid = fork();
                if (pid <= 0) {
-                       recursiveRemove(cfd);
+                       if (fstat(cfd, &sb) == 0) {
+                               if (sb.st_dev == makedev(0, 1))
+                                       recursiveRemove(cfd);
+                               else
+                                       warn(_("old root filesystem is not an initramfs"));
+                       }
+
                        if (pid == 0)
                                exit(EXIT_SUCCESS);
                }