From: "Robin H. Johnson" <robbat2@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/openrc:openrc-0.13.x commit in: init.d/
Date: Fri, 27 Feb 2015 02:33:08 +0000 (UTC) [thread overview]
Message-ID: <1425004345.4d49bd051d64a69ddf647708af4845783c0cd249.robbat2@OpenRC> (raw)
commit: 4d49bd051d64a69ddf647708af4845783c0cd249
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Fri Feb 27 01:58:22 2015 +0000
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Fri Feb 27 02:32:25 2015 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=4d49bd05
bootmisc: clean_run safety improvements.
If /tmp or / are read-only, the clean_run function can fail in some very
bad ways.
1. dir=$(mktemp -d) returns an EMPTY string on error.
2. "mount -o bind / $dir", and don't check the result of that,
3. "rm -rf $dir/run/*", which removes the REAL /run contents
4. box gets very weird from this point forward
Signed-Off-By: Robin H. Johnson <robbat2 <AT> gentoo.org>
Signed-Off-By: Chip Parker <infowolfe <AT> gmail.com>
Reported-by: Chip Parker <infowolfe <AT> gmail.com>
Tested-by: Chip Parker <infowolfe <AT> gmail.com>
---
init.d/bootmisc.in | 33 +++++++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/init.d/bootmisc.in b/init.d/bootmisc.in
index 2ec075f..2f3feee 100644
--- a/init.d/bootmisc.in
+++ b/init.d/bootmisc.in
@@ -119,11 +119,36 @@ clean_run()
{
[ "$RC_SYS" = VSERVER -o "$RC_SYS" = LXC ] && return 0
local dir
+ # If / is stll read-only due to a problem, this will fail!
+ mountinfo -q --options-regex '^rw(,|$)' /
+ if [ $? -ne 0 ]; then
+ eerror "/ is not writable; unable to clean up underlying /run"
+ return 1
+ fi
+ # Get the mountpoint used by /tmp (it might be /tmp or /)
+ tmpmnt=`/usr/bin/stat -c '%m' /tmp`
+ mountinfo -q --options-regex '^rw(,|$)' $tmpmnt
+ if [ -n "$tmpmnt" -a $? -ne 0 ]; then
+ eerror "/tmp is not writable; unable to clean up underlying /run"
+ return 1
+ fi
+ # Now we know that we can modify /tmp and /
+ # if mktemp -d fails, it returns an EMPTY string
+ # STDERR: mktemp: failed to create directory via template ‘/tmp/tmp.XXXXXXXXXX’: Read-only file system
+ # STDOUT: ''
+ rc=0
dir=$(mktemp -d)
- mount --bind / $dir
- rm -rf $dir/run/*
- umount $dir
- rm -rf $dir
+ if [ -n "$dir" -a -d $dir -a -w $dir ]; then
+ mount --bind / $dir && rm -rf $dir/run/* || rc=1
+ umount $dir
+ rm -rf $dir
+ else
+ rc=1
+ fi
+ if [ $rc -ne 0 ]; then
+ eerror "Could not clean up underlying /run on /"
+ return 1
+ fi
}
start()
next reply other threads:[~2015-02-27 2:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-27 2:33 Robin H. Johnson [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-02-18 18:59 [gentoo-commits] proj/openrc:openrc-0.13.x commit in: init.d/ William Hubbs
2015-02-05 4:12 William Hubbs
2015-01-18 15:43 William Hubbs
2014-11-24 4:03 William Hubbs
2014-11-20 17:08 William Hubbs
2014-11-07 17:34 William Hubbs
2014-10-20 21:05 William Hubbs
2014-10-16 17:41 William Hubbs
2014-10-16 17:41 William Hubbs
2014-08-22 19:21 William Hubbs
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=1425004345.4d49bd051d64a69ddf647708af4845783c0cd249.robbat2@OpenRC \
--to=robbat2@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.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