summaryrefslogtreecommitdiffstats
path: root/recipes-security
diff options
context:
space:
mode:
authorMark Asselstine <mark.asselstine@windriver.com>2019-08-23 14:19:53 -0400
committerJoe MacDonald <joe_macdonald@mentor.com>2019-08-28 10:28:06 -0400
commitb0d31db104d9a4e94bc1409c2ffcc1d82f4a780f (patch)
treeefd7892420692eea1e4d9217a082b1aa1b241161 /recipes-security
parenta41f48260654e0e444603c6a595444c450e6c3f5 (diff)
downloadmeta-selinux-b0d31db104d9a4e94bc1409c2ffcc1d82f4a780f.tar.gz
selinux-init: use systemd (re)labelling
Boot loops were being seen when booting with selinux enabled, when the init system in use is systemd. Once logs were retrieved from the failing system the error was found to be selinux-init.sh[284]: /sbin/restorecon: Could not set context for /sys/fs/cgroup/cpuacct: Read-only file system selinux-init.sh[284]: /sbin/restorecon: Could not set context for /sys/fs/cgroup/cpu: Read-only file system Systemd mounts /sys/fs/cgroup read-only and the (re)labelling code used by selinux-init.sh is unable to handle this. On top of this the system is basically presenting two methods of (re)labelling; using the built in systemd approach via selinux-autorelabel.service *and* the code we have in selinux-init.sh. This can get confusing especially given that most online resources will speak to the systemd approach using selinux-autorelabel.service and /.autorelabel. These changes leave the current approach in place when sysvinit is the init system used, but if systemd is being used we make use of it's internal (re)labelling functionality. Overall the workflow remains the same but we now avoid boot loops (systemd remounts /sys/fs/cgroup rw during the (re)labelling procedure). Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com> Signed-off-by: Joe MacDonald <joe_macdonald@mentor.com>
Diffstat (limited to 'recipes-security')
-rw-r--r--recipes-security/selinux/selinux-init/selinux-init.sh14
-rw-r--r--recipes-security/selinux/selinux-init/selinux-init.sh.sysvinit14
-rw-r--r--recipes-security/selinux/selinux-init_0.1.bb8
-rw-r--r--recipes-security/selinux/selinux-initsh.inc8
4 files changed, 28 insertions, 16 deletions
diff --git a/recipes-security/selinux/selinux-init/selinux-init.sh b/recipes-security/selinux/selinux-init/selinux-init.sh
index ead4f00..f93d231 100644
--- a/recipes-security/selinux/selinux-init/selinux-init.sh
+++ b/recipes-security/selinux/selinux-init/selinux-init.sh
@@ -33,18 +33,6 @@ check_rootfs()
33 /sbin/shutdown -f -h now 33 /sbin/shutdown -f -h now
34} 34}
35 35
36# If first booting, the security context type of init would be 36# sysvinit firstboot relabel placeholder HERE
37# "kernel_t", and the whole file system should be relabeled.
38if [ "`${SECON} -t --pid 1`" = "kernel_t" ]; then
39 echo "Checking SELinux security contexts:"
40 check_rootfs
41 echo " * First booting, filesystem will be relabeled..."
42 test -x /etc/init.d/auditd && /etc/init.d/auditd start
43 ${SETENFORCE} 0
44 ${RESTORECON} -RF /
45 ${RESTORECON} -F /
46 echo " * Relabel done, rebooting the system."
47 /sbin/reboot
48fi
49 37
50exit 0 38exit 0
diff --git a/recipes-security/selinux/selinux-init/selinux-init.sh.sysvinit b/recipes-security/selinux/selinux-init/selinux-init.sh.sysvinit
new file mode 100644
index 0000000..d4f3f71
--- /dev/null
+++ b/recipes-security/selinux/selinux-init/selinux-init.sh.sysvinit
@@ -0,0 +1,14 @@
1# Contents will be added to selinux-init.sh to support relabelling with sysvinit
2# If first booting, the security context type of init would be
3# "kernel_t", and the whole file system should be relabeled.
4if [ "`${SECON} -t --pid 1`" = "kernel_t" ]; then
5 echo "Checking SELinux security contexts:"
6 check_rootfs
7 echo " * First booting, filesystem will be relabeled..."
8 test -x /etc/init.d/auditd && /etc/init.d/auditd start
9 ${SETENFORCE} 0
10 ${RESTORECON} -RF /
11 ${RESTORECON} -F /
12 echo " * Relabel done, rebooting the system."
13 /sbin/reboot
14fi
diff --git a/recipes-security/selinux/selinux-init_0.1.bb b/recipes-security/selinux/selinux-init_0.1.bb
index 38b5900..78f571c 100644
--- a/recipes-security/selinux/selinux-init_0.1.bb
+++ b/recipes-security/selinux/selinux-init_0.1.bb
@@ -14,9 +14,11 @@ ${PN}_RDEPENDS = " \
14 policycoreutils-setfiles \ 14 policycoreutils-setfiles \
15" 15"
16 16
17SRC_URI = "file://${BPN}.sh \ 17SRC_URI = " \
18 file://${BPN}.service \ 18 file://${BPN}.sh \
19 " 19 file://${BPN}.sh.sysvinit \
20 file://${BPN}.service \
21"
20 22
21INITSCRIPT_PARAMS = "start 01 S ." 23INITSCRIPT_PARAMS = "start 01 S ."
22 24
diff --git a/recipes-security/selinux/selinux-initsh.inc b/recipes-security/selinux/selinux-initsh.inc
index bcdd449..8e31cda 100644
--- a/recipes-security/selinux/selinux-initsh.inc
+++ b/recipes-security/selinux/selinux-initsh.inc
@@ -17,9 +17,15 @@ inherit update-rc.d systemd
17 17
18SYSTEMD_SERVICE_${PN} = "${SELINUX_SCRIPT_SRC}.service" 18SYSTEMD_SERVICE_${PN} = "${SELINUX_SCRIPT_SRC}.service"
19 19
20FILES_${PN} += "/.autorelabel"
21
20do_install () { 22do_install () {
21 install -d ${D}${sysconfdir}/init.d/ 23 install -d ${D}${sysconfdir}/init.d/
22 install -m 0755 ${WORKDIR}/${SELINUX_SCRIPT_SRC}.sh ${D}${sysconfdir}/init.d/${SELINUX_SCRIPT_DST} 24 install -m 0755 ${WORKDIR}/${SELINUX_SCRIPT_SRC}.sh ${D}${sysconfdir}/init.d/${SELINUX_SCRIPT_DST}
25 # Insert the relabelling code which is only needed with sysvinit
26 sed -i -e '/HERE/r ${WORKDIR}/${SELINUX_SCRIPT_SRC}.sh.sysvinit' \
27 -e '/.*HERE$/d' -e '/.*Contents.*sysvinit/d' \
28 ${D}${sysconfdir}/init.d/${SELINUX_SCRIPT_DST}
23 29
24 install -d ${D}${systemd_unitdir}/system 30 install -d ${D}${systemd_unitdir}/system
25 install -m 0644 ${WORKDIR}/${SELINUX_SCRIPT_SRC}.service ${D}${systemd_unitdir}/system 31 install -m 0644 ${WORKDIR}/${SELINUX_SCRIPT_SRC}.service ${D}${systemd_unitdir}/system
@@ -27,6 +33,8 @@ do_install () {
27 if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then 33 if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then
28 install -d ${D}${bindir} 34 install -d ${D}${bindir}
29 install -m 0755 ${WORKDIR}/${SELINUX_SCRIPT_SRC}.sh ${D}${bindir} 35 install -m 0755 ${WORKDIR}/${SELINUX_SCRIPT_SRC}.sh ${D}${bindir}
36 sed -i -e '/.*HERE$/d' ${D}${bindir}/${SELINUX_SCRIPT_SRC}.sh
37 echo "# first boot relabelling" > ${D}/.autorelabel
30 fi 38 fi
31} 39}
32 40