]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
selinux: bail out if policy could not be loaded and selinux=0 not
authorHarald Hoyer <harald@redhat.com>
Mon, 21 Sep 2009 15:44:14 +0000 (17:44 +0200)
committerHarald Hoyer <harald@redhat.com>
Mon, 21 Sep 2009 15:44:14 +0000 (17:44 +0200)
specified

modules.d/99base/selinux-loadpolicy.sh
test/TEST-10-RAID/test.sh
test/TEST-11-LVM/test.sh
test/TEST-12-RAID-DEG/test.sh
test/TEST-13-ENC-RAID-LVM/test.sh
test/TEST-14-IMSM/test.sh
test/TEST-20-NFS/test.sh
test/TEST-30-ISCSI/test.sh
test/TEST-40-NBD/test.sh

index 8285b51b4bb39f6ed6d22bd028b9bbac3af10fbc..9e95b8de95e925f44fca81c44b135edd048de2d2 100755 (executable)
@@ -1,24 +1,60 @@
 #!/bin/sh
 # FIXME: load selinux policy.  this should really be done after we switchroot 
 
-if [ -x "$NEWROOT/usr/sbin/load_policy" -o -x "$NEWROOT/sbin/load_policy" ]; then
-    ret=0
-    info "Loading SELinux policy"
-    {
-        # load_policy does mount /proc and /selinux in libselinux,selinux_init_load_policy()
-        if [ -x "$NEWROOT/sbin/load_policy" ]; then
-            chroot "$NEWROOT" /sbin/load_policy -i
-            ret=$?
-        else
-            chroot "$NEWROOT" /usr/sbin/load_policy -i
-            ret=$?
-        fi
-    } 2>&1 | vinfo
-
-    if [ $ret -eq 3 ]; then
-       warn "Initial SELinux policy load failed and enforcing mode requested."
+rd_load_policy()
+{
+
+    SELINUX="enforcing"
+    [ -e "$NEWROOT/etc/selinux/config" ] && . "$NEWROOT/etc/selinux/config"
+
+    # If SELinux is disabled exit now 
+    getarg "selinux=0" > /dev/null
+    if [ $? -eq 0 -o "$SELINUX" = "disabled" ]; then
+       return 0
+    fi
+
+    # Check whether SELinux is in permissive mode
+    permissive=0
+    getarg "enforcing=0" > /dev/null
+    if [ $? -eq 0 -o "$SELINUX" = "permissive" ]; then
+       permissive=1
+    fi
+
+    # Attempt to load SELinux Policy
+    if [ -x "$NEWROOT/usr/sbin/load_policy" -o -x "$NEWROOT/sbin/load_policy" ]; then
+       ret=0
+       info "Loading SELinux policy"
+       {
+            # load_policy does mount /proc and /selinux in 
+            # libselinux,selinux_init_load_policy()
+            if [ -x "$NEWROOT/sbin/load_policy" ]; then
+               chroot "$NEWROOT" /sbin/load_policy -i
+               ret=$?
+            else
+               chroot "$NEWROOT" /usr/sbin/load_policy -i
+               ret=$?
+            fi
+       } 2>&1 | vinfo
+
+       if [ $ret -eq 0 -o $ret -eq 2 ]; then
+           return 0
+       fi
+
+       warn "Initial SELinux policy load failed."
+       if [ $ret -eq 3 -o $permissive -eq 0 ]; then
+           warn "Machine in enforcing mode."
+           warn "Not continuing"
+           sleep 100d
+           exit 1
+       fi
+       return 0
+    elif [ $permissive -eq 0 ]; then
+       warn "Machine in enforcing mode and cannot execute load_policy."
+       warn "To disable selinux, add selinux=0 to the kernel command line."
        warn "Not continuing"
        sleep 100d
        exit 1
     fi
-fi
+}
+
+rd_load_policy
index 7d793d3c82c8a16fe2160ab04a2ca52399b3e0fd..0e7fed58830c695667d2e32f1636a621a5944c9a 100755 (executable)
@@ -9,7 +9,7 @@ KVERSION=${KVERSION-$(uname -r)}
 test_run() {
     $testdir/run-qemu -hda root.ext2 -m 256M -nographic \
        -net none -kernel /boot/vmlinuz-$KVERSION \
-       -append "root=/dev/dracut/root rw quiet console=ttyS0,115200n81 rdshell $DEBUGFAIL" \
+       -append "root=/dev/dracut/root rw quiet console=ttyS0,115200n81 selinux=0 rdshell $DEBUGFAIL" \
        -initrd initramfs.testing
     grep -m 1 -q dracut-root-block-success root.ext2 || return 1
 }
@@ -53,7 +53,7 @@ test_setup() {
     # Invoke KVM and/or QEMU to actually create the target filesystem.
     $testdir/run-qemu -hda root.ext2 -m 256M -nographic -net none \
        -kernel "/boot/vmlinuz-$kernel" \
-       -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81" \
+       -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81 selinux=0" \
        -initrd initramfs.makeroot  || return 1
     grep -m 1 -q dracut-root-block-created root.ext2 || return 1
     (
index 9747e1589cbd3982c905d77348017c01a49c2cc7..0bc9b9fc36f20ca772672315ffcc83e5f88ef557 100755 (executable)
@@ -9,7 +9,7 @@ KVERSION=${KVERSION-$(uname -r)}
 test_run() {
     $testdir/run-qemu -hda root.ext2 -m 256M -nographic \
        -net none -kernel /boot/vmlinuz-$KVERSION \
-       -append "root=/dev/dracut/root rw quiet rdinfo console=ttyS0,115200n81 rdshell $DEBUGFAIL" \
+       -append "root=/dev/dracut/root rw quiet rdinfo console=ttyS0,115200n81 selinux=0 rdshell $DEBUGFAIL" \
        -initrd initramfs.testing
     grep -m 1 -q dracut-root-block-success root.ext2 || return 1
 }
@@ -52,7 +52,7 @@ test_setup() {
     # Invoke KVM and/or QEMU to actually create the target filesystem.
     $testdir/run-qemu -hda root.ext2 -m 256M -nographic -net none \
        -kernel "/boot/vmlinuz-$kernel" \
-       -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81" \
+       -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81 selinux=0" \
        -initrd initramfs.makeroot  || return 1
     grep -m 1 -q dracut-root-block-created root.ext2 || return 1
     (
index 25c9634140c43d4161a9dfa50e0bc90894077c78..43592532922ca9ddc24ae1d1f707cec7cb0f7a88 100755 (executable)
@@ -10,7 +10,7 @@ client_run() {
     echo "CLIENT TEST START: $@"
     $testdir/run-qemu -hda root.ext2 -m 256M -nographic \
        -net none -kernel /boot/vmlinuz-$KVERSION \
-       -append "$@ root=LABEL=root rw quiet rdinfo console=ttyS0,115200n81 rdshell $DEBUGFAIL " \
+       -append "$@ root=LABEL=root rw quiet rdinfo console=ttyS0,115200n81 selinux=0 rdshell $DEBUGFAIL " \
        -initrd initramfs.testing
     if ! grep -m 1 -q dracut-root-block-success root.ext2; then
        echo "CLIENT TEST END: $@ [FAIL]"
@@ -87,7 +87,7 @@ test_setup() {
     # Invoke KVM and/or QEMU to actually create the target filesystem.
     $testdir/run-qemu -hda root.ext2 -m 256M -nographic -net none \
        -kernel "/boot/vmlinuz-$kernel" \
-       -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81" \
+       -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81 selinux=0" \
        -initrd initramfs.makeroot  || return 1
     grep -m 1 -q dracut-root-block-created root.ext2 || return 1
     eval $(grep --binary-files=text -m 1 MD_UUID root.ext2)
index 86ae48298f97765243136fc6e1a1523039f8b5dc..55af484a17872e61e153ac2bb3b876ae210c426b 100755 (executable)
@@ -9,7 +9,7 @@ KVERSION=${KVERSION-$(uname -r)}
 test_run() {
     $testdir/run-qemu -hda root.ext2 -m 256M -nographic \
        -net none -kernel /boot/vmlinuz-$KVERSION \
-       -append "root=/dev/dracut/root rw quiet rdinfo console=ttyS0,115200n81 rdshell $DEBUGFAIL" \
+       -append "root=/dev/dracut/root rw quiet rdinfo console=ttyS0,115200n81 selinux=0 rdshell $DEBUGFAIL" \
        -initrd initramfs.testing
     grep -m 1 -q dracut-root-block-success root.ext2 || return 1
 }
@@ -52,7 +52,7 @@ test_setup() {
     # Invoke KVM and/or QEMU to actually create the target filesystem.
     $testdir/run-qemu -hda root.ext2 -m 256M -nographic -net none \
        -kernel "/boot/vmlinuz-$kernel" \
-       -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81" \
+       -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81 selinux=0" \
        -initrd initramfs.makeroot  || return 1
     grep -m 1 -q dracut-root-block-created root.ext2 || return 1
     (
index 623546beec97ca27f0a266e6cd577c1942c87889..be33ac325f8be11891ac659a89fcd752d17f3fa7 100755 (executable)
@@ -10,7 +10,7 @@ client_run() {
     echo "CLIENT TEST START: $@"
     $testdir/run-qemu -hda root.ext2 -hdb disk1 -hdc disk2 -m 256M -nographic \
        -net none -kernel /boot/vmlinuz-$KVERSION \
-       -append "$@ root=LABEL=root rw quiet rdinfo console=ttyS0,115200n81 rdshell $DEBUGFAIL" \
+       -append "$@ root=LABEL=root rw quiet rdinfo console=ttyS0,115200n81 selinux=0 rdshell $DEBUGFAIL" \
        -initrd initramfs.testing
     if ! grep -m 1 -q dracut-root-block-success root.ext2; then
        echo "CLIENT TEST END: $@ [FAIL]"
@@ -74,7 +74,7 @@ test_setup() {
     # Invoke KVM and/or QEMU to actually create the target filesystem.
     $testdir/run-qemu -hda root.ext2 -hdb disk1 -hdc disk2 -m 256M -nographic -net none \
        -kernel "/boot/vmlinuz-$kernel" \
-       -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81" \
+       -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81 selinux=0" \
        -initrd initramfs.makeroot  || return 1
     grep -m 1 -q dracut-root-block-created root.ext2 || return 1
     (
index cd8142414a680b203628f4d016992ad0efbbdeaa..8072cf0b00ee24db58fcb1a4a276d7474546f464 100755 (executable)
@@ -15,7 +15,7 @@ run_server() {
        -net socket,mcast=230.0.0.1:1234 \
        -serial udp:127.0.0.1:9999 \
        -kernel /boot/vmlinuz-$KVERSION \
-       -append "root=/dev/sda rw quiet console=ttyS0,115200n81" \
+       -append "root=/dev/sda rw quiet console=ttyS0,115200n81 selinux=0" \
        -initrd initramfs.server -pidfile server.pid -daemonize || return 1
     sudo chmod 644 server.pid || return 1
 
@@ -46,7 +46,7 @@ client_test() {
        -net nic,macaddr=$mac,model=e1000 \
        -net socket,mcast=230.0.0.1:1234 \
        -kernel /boot/vmlinuz-$KVERSION \
-       -append "$cmdline $DEBUGFAIL rdshell ro quiet console=ttyS0,115200n81" \
+       -append "$cmdline $DEBUGFAIL rdshell ro quiet console=ttyS0,115200n81 selinux=0" \
        -initrd initramfs.testing
 
     if [[ $? -ne 0 ]] || ! grep -m 1 -q nfs-OK client.img; then
index 1b10c7ef277e2c869687234512ae07d090f6cea6..dc32775bbf79af6da33b496ae965752fa614d168 100755 (executable)
@@ -14,7 +14,7 @@ run_server() {
        -net socket,mcast=230.0.0.1:1235 \
        -serial udp:127.0.0.1:9999 \
        -kernel /boot/vmlinuz-$KVERSION \
-       -append "root=/dev/sda rw quiet console=ttyS0,115200n81" \
+       -append "root=/dev/sda rw quiet console=ttyS0,115200n81 selinux=0" \
        -initrd initramfs.server -pidfile server.pid -daemonize || return 1
     sudo chmod 644 server.pid || return 1
 
@@ -37,7 +37,7 @@ run_client() {
        -net nic,macaddr=52:54:00:12:34:00,model=e1000 \
        -net socket,mcast=230.0.0.1:1235 \
        -kernel /boot/vmlinuz-$KVERSION \
-       -append "root=dhcp rw quiet console=ttyS0,115200n81 rdshell $DEBUGFAIL" \
+       -append "root=dhcp rw quiet console=ttyS0,115200n81 selinux=0 rdshell $DEBUGFAIL" \
        -initrd initramfs.testing
     grep -m 1 -q iscsi-OK client.img || return 1
 }
@@ -102,7 +102,7 @@ test_setup() {
     # Invoke KVM and/or QEMU to actually create the target filesystem.
     $testdir/run-qemu -hda root.ext2 -hdb client.img -m 256M -nographic -net none \
        -kernel "/boot/vmlinuz-$kernel" \
-       -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81" \
+       -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81 selinux=0" \
        -initrd initramfs.makeroot  || return 1
     grep -m 1 -q dracut-root-block-created client.img || return 1
     rm client.img
index b3a580f14d47604c0b81b99aa5bd606ce80c01d9..1dfa03294d43ce385faa570d6817cbbfa86acd9b 100755 (executable)
@@ -16,7 +16,7 @@ run_server() {
        -net socket,mcast=230.0.0.1:1236 \
        -serial udp:127.0.0.1:9999 \
        -kernel /boot/vmlinuz-$KVERSION \
-       -append "root=/dev/sda rw quiet console=ttyS0,115200n81" \
+       -append "root=/dev/sda rw quiet console=ttyS0,115200n81 selinux=0" \
        -initrd initramfs.server -pidfile server.pid -daemonize || return 1
     sudo chmod 644 server.pid || return 1
 
@@ -50,7 +50,7 @@ client_test() {
        -net nic,macaddr=$mac,model=e1000 \
        -net socket,mcast=230.0.0.1:1236 \
        -kernel /boot/vmlinuz-$KVERSION \
-       -append "$cmdline $DEBUGFAIL rdshell ro quiet console=ttyS0,115200n81" \
+       -append "$cmdline $DEBUGFAIL rdshell ro quiet console=ttyS0,115200n81 selinux=0" \
        -initrd initramfs.testing
 
     if [[ $? -ne 0 ]] || ! grep -m 1 -q nbd-OK flag.img; then
@@ -207,7 +207,7 @@ make_encrypted_root() {
     $testdir/run-qemu -hda flag.img -hdb encrypted.ext2 -m 256M \
        -nographic -net none \
        -kernel "/boot/vmlinuz-$kernel" \
-       -append "root=/dev/dracut/root rw quiet console=ttyS0,115200n81" \
+       -append "root=/dev/dracut/root rw quiet console=ttyS0,115200n81 selinux=0" \
        -initrd initramfs.makeroot  || return 1
     grep -m 1 -q dracut-root-block-created flag.img || return 1
 }