Gentoo Archives: gentoo-commits

From: William Hubbs <williamh@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/openrc:master commit in: init.d/
Date: Fri, 27 Feb 2015 16:21:57
Message-Id: 1425053684.7bbb73574b44972b0c1b364e24f71623068d7a1c.williamh@OpenRC
1 commit: 7bbb73574b44972b0c1b364e24f71623068d7a1c
2 Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
3 AuthorDate: Fri Feb 27 01:58:22 2015 +0000
4 Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
5 CommitDate: Fri Feb 27 16:14:44 2015 +0000
6 URL: http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=7bbb7357
7
8 bootmisc: clean_run safety improvements.
9
10 If /tmp or / are read-only, the clean_run function can fail in some very
11 bad ways.
12
13 1. dir=$(mktemp -d) returns an EMPTY string on error.
14 2. "mount -o bind / $dir", and don't check the result of that,
15 3. "rm -rf $dir/run/*", which removes the REAL /run contents
16 4. box gets very weird from this point forward
17
18 Signed-Off-By: Robin H. Johnson <robbat2 <AT> gentoo.org>
19 Signed-Off-By: Chip Parker <infowolfe <AT> gmail.com>
20 Reported-by: Chip Parker <infowolfe <AT> gmail.com>
21 Tested-by: Chip Parker <infowolfe <AT> gmail.com>
22
23 ---
24 init.d/bootmisc.in | 29 +++++++++++++++++++++++++----
25 1 file changed, 25 insertions(+), 4 deletions(-)
26
27 diff --git a/init.d/bootmisc.in b/init.d/bootmisc.in
28 index 2ec075f..dbd258e 100644
29 --- a/init.d/bootmisc.in
30 +++ b/init.d/bootmisc.in
31 @@ -119,11 +119,32 @@ clean_run()
32 {
33 [ "$RC_SYS" = VSERVER -o "$RC_SYS" = LXC ] && return 0
34 local dir
35 + # If / is still read-only due to a problem, this will fail!
36 + if ! checkpath -W /; then
37 + eerror "/ is not writable; unable to clean up underlying /run"
38 + return 1
39 + fi
40 + if ! checkpath -W /tmp; then
41 + eerror "/tmp is not writable; unable to clean up underlying /run"
42 + return 1
43 + fi
44 + # Now we know that we can modify /tmp and /
45 + # if mktemp -d fails, it returns an EMPTY string
46 + # STDERR: mktemp: failed to create directory via template ‘/tmp/tmp.XXXXXXXXXX’: Read-only file system
47 + # STDOUT: ''
48 + rc=0
49 dir=$(mktemp -d)
50 - mount --bind / $dir
51 - rm -rf $dir/run/*
52 - umount $dir
53 - rm -rf $dir
54 + if [ -n "$dir" -a -d $dir -a -w $dir ]; then
55 + mount --bind / $dir && rm -rf $dir/run/* || rc=1
56 + umount $dir
57 + rm -rf $dir
58 + else
59 + rc=1
60 + fi
61 + if [ $rc -ne 0 ]; then
62 + eerror "Could not clean up underlying /run on /"
63 + return 1
64 + fi
65 }
66
67 start()