summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXin Ouyang <Xin.Ouyang@windriver.com>2012-11-16 15:31:38 +0800
committerXin Ouyang <Xin.Ouyang@windriver.com>2012-11-19 11:06:05 +0800
commitd2711cfdb2d1872b9c12512112f086bf4561ffdd (patch)
tree73063f93222acd4deb51bf5fe32295c2b70fb906
parent43a177fe9706e9c6090b2924aa540db298ddf27a (diff)
downloadmeta-selinux-d2711cfdb2d1872b9c12512112f086bf4561ffdd.tar.gz
selinux-config: update the init script
Fix the hard-coded security type for /dev/null and /dev/console. Check rootfs if support xattrs before do relabel. Signed-off-by: Xin Ouyang <Xin.Ouyang@windriver.com>
-rw-r--r--recipes-security/selinux/selinux-config/selinux-init.sh50
-rw-r--r--recipes-security/selinux/selinux-config_0.1.bb2
2 files changed, 41 insertions, 11 deletions
diff --git a/recipes-security/selinux/selinux-config/selinux-init.sh b/recipes-security/selinux/selinux-config/selinux-init.sh
index 55c503f..1cdc3dd 100644
--- a/recipes-security/selinux/selinux-config/selinux-init.sh
+++ b/recipes-security/selinux/selinux-config/selinux-init.sh
@@ -2,20 +2,48 @@
2 2
3/usr/sbin/selinuxenabled 2>/dev/null || exit 0 3/usr/sbin/selinuxenabled 2>/dev/null || exit 0
4 4
5CHCON=/usr/bin/chcon
6MATCHPATHCON=/usr/sbin/matchpathcon
7FIXFILES=/sbin/fixfiles
8RESTORECON=/sbin/restorecon
9
10for i in ${CHCON} ${MATCHPATHCON} ${FIXFILES} ${RESTORECON} ; do
11 test -x $i && continue
12 echo "$i is missing in the system."
13 echo "Please add \"selinux=0\" in the kernel command line to disable SELinux."
14 exit 1
15done
16
17check_rootfs()
18{
19 ${CHCON} `${MATCHPATHCON} -n /` / >/dev/null 2>&1 && return 0
20 echo ""
21 echo "* SELinux requires the root '/' filesystem support extended"
22 echo " filesystem attributes (XATTRs). It does not appear that this"
23 echo " filesystem has extended attribute support or it is not enabled."
24 echo ""
25 echo " - To continue using SELinux you will need to enable extended"
26 echo " attribute support on the root device."
27 echo ""
28 echo " - To disable SELinux, please add \"selinux=0\" in the kernel"
29 echo " command line."
30 echo ""
31 echo "* Halting the system now."
32 /sbin/shutdown -f -h now
33}
34
5# Because /dev/console is not relabeled by kernel, many commands 35# Because /dev/console is not relabeled by kernel, many commands
6# would can not use it, including restorecon. 36# would can not use it, including restorecon.
7if [ -x /usr/bin/chcon ]; then 37${CHCON} -t `${MATCHPATHCON} -n /dev/null | cut -d: -f3` /dev/null
8 /usr/bin/chcon -t null_device_t /dev/null 38${CHCON} -t `${MATCHPATHCON} -n /dev/console | cut -d: -f3` /dev/console
9 /usr/bin/chcon -t console_device_t /dev/console
10fi
11 39
12 40
13# If /.autorelabel placed, the whole file system should be relabeled 41# If /.autorelabel placed, the whole file system should be relabeled
14test ! -x /sbin/fixfiles ||
15if [ -f /.autorelabel ]; then 42if [ -f /.autorelabel ]; then
16 echo "Checking SELinux security contexts:" 43 echo "Checking SELinux security contexts:"
44 check_rootfs
17 echo " * /.autorelabel placed, filesystem will be relabeled..." 45 echo " * /.autorelabel placed, filesystem will be relabeled..."
18 /sbin/fixfiles -F -f relabel 46 ${FIXFILES} -F -f relabel
19 /bin/rm -f /.autorelabel 47 /bin/rm -f /.autorelabel
20 echo " * Relabel done, rebooting the system." 48 echo " * Relabel done, rebooting the system."
21 /sbin/reboot -f 49 /sbin/reboot -f
@@ -23,17 +51,19 @@ fi
23 51
24# If first booting, the security context type of init would be 52# If first booting, the security context type of init would be
25# "kernel_t", and the whole file system should be relabeled. 53# "kernel_t", and the whole file system should be relabeled.
26test ! -x /sbin/restorecon ||
27if [ "`/usr/bin/secon -t --pid 1`" = "kernel_t" ]; then 54if [ "`/usr/bin/secon -t --pid 1`" = "kernel_t" ]; then
28 echo "Checking SELinux security contexts:" 55 echo "Checking SELinux security contexts:"
56 check_rootfs
29 echo " * First booting, filesystem will be relabeled..." 57 echo " * First booting, filesystem will be relabeled..."
30 test -x /etc/init.d/auditd && /etc/init.d/auditd start 58 test -x /etc/init.d/auditd && /etc/init.d/auditd start
31 /usr/sbin/setenforce 0 59 /usr/sbin/setenforce 0
32 /sbin/restorecon -R / 60 ${RESTORECON} -R /
33 /sbin/restorecon / 61 ${RESTORECON} /
34 echo " * Relabel done, rebooting the system." 62 echo " * Relabel done, rebooting the system."
35 /sbin/reboot -f 63 /sbin/reboot -f
36fi 64fi
37 65
38# Now, we should relabel /dev for most services. 66# Now, we should relabel /dev for most services.
39test ! -x /sbin/restorecon || /sbin/restorecon -R /dev 67${RESTORECON} -R /dev
68
69exit 0
diff --git a/recipes-security/selinux/selinux-config_0.1.bb b/recipes-security/selinux/selinux-config_0.1.bb
index 48b9362..9521dcf 100644
--- a/recipes-security/selinux/selinux-config_0.1.bb
+++ b/recipes-security/selinux/selinux-config_0.1.bb
@@ -8,7 +8,7 @@ This is the configuration files for SELinux on WRLinux system. \
8SECTION = "base" 8SECTION = "base"
9LICENSE = "MIT" 9LICENSE = "MIT"
10LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" 10LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
11PR = "r1" 11PR = "r2"
12 12
13SRC_URI = "file://selinux-init.sh" 13SRC_URI = "file://selinux-init.sh"
14 14