public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Richard Weinberger <richard@nod.at>
To: kzak@redhat.com
Cc: util-linux@vger.kernel.org, Richard Weinberger <richard@nod.at>
Subject: [PATCH] [RFC] switch_root: Add a sanity check
Date: Sat,  9 Feb 2013 19:22:50 +0100	[thread overview]
Message-ID: <1360434170-27206-1-git-send-email-richard@nod.at> (raw)

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 |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/sys-utils/switch_root.c b/sys-utils/switch_root.c
index f0ef677..f26f7da 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);
 		}
-- 
1.7.7.3

             reply	other threads:[~2013-02-09 18:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-09 18:22 Richard Weinberger [this message]
2013-02-13 14:25 ` [PATCH] [RFC] switch_root: Add a sanity check Karel Zak
2013-02-13 14:52   ` Dave Reisner
2013-02-13 15:03     ` Richard Weinberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1360434170-27206-1-git-send-email-richard@nod.at \
    --to=richard@nod.at \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox