From: Richard Weinberger Date: Sat, 9 Feb 2013 18:22:50 +0000 (+0100) Subject: switch_root: Add a sanity check X-Git-Tag: v2.23-rc1~227 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=07de470e437f204e3d40b8b0a85f57c1978ff9ed;p=thirdparty%2Futil-linux.git switch_root: Add a sanity check As switch_root basically does rm -Rf / we should make sure that / is really an initramfs. Signed-off-by: Richard Weinberger --- diff --git a/sys-utils/switch_root.c b/sys-utils/switch_root.c index f0ef67745f..f26f7dae43 100644 --- a/sys-utils/switch_root.c +++ b/sys-utils/switch_root.c @@ -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); }