eBPF-based security platform
initrd: Remount sysroot read-write before bootstrap
Michi Mutsuzakid4a82bdea816
diff --git a/Documentation/initrd.rst b/Documentation/initrd.rstindex 826aaea5..2e6071a4 100644--- a/Documentation/initrd.rst+++ b/Documentation/initrd.rst@@ -28,8 +28,9 @@ commands, `architecture <architecture.rst>`__ for the LSM flow andstatic SHA-256 PCR for config measurements. See`requirements <requirements.rst>`__ for the exact kernel requirements,including disabled 32-bit compatibility.-* ``/sysroot/var/lib/shirudo`` mounted writable before Shirudo starts. If- state is on a separate filesystem, mount it in the initrd too. Config+* ``/sysroot/var/lib/shirudo`` mounted writable before Shirudo starts.+ ``shirudo-initrd.service`` remounts ``/sysroot`` read-write; if state is on+ a separate filesystem, mount it read-write in the initrd too. Configselections and cached bundles must be durable before PCR extension.* ``systemd-pcrphase-initrd.service`` and its ``enter-initrd`` measurementbefore Shirudo binds its upatch register. A direct QEMU kernel/initrd bootdiff --git a/builtin-init.c b/builtin-init.cindex 5cd79b20..bc824587 100644--- a/builtin-init.c+++ b/builtin-init.c@@ -1312,8 +1312,15 @@ static int initrd_enter(void)strerror(errno));return -errno;}- rc = statvfs(SHIRUDO_VAR_LIB, &state) ? -errno :- (state.f_flag & ST_RDONLY ? -EROFS : 0);+ if (statvfs(SHIRUDO_VAR_LIB, &state)) {+ rc = -errno;+ pr_err("initrd: statvfs %s: %s", src, strerror(-rc));+ } else if (state.f_flag & ST_RDONLY) {+ rc = -EROFS;+ pr_err("initrd: %s is read-only", src);+ } else {+ rc = 0;+ }if (rc) {umount2(SHIRUDO_VAR_LIB, MNT_DETACH);return rc;diff --git a/systemd/shirudo-initrd.service.in b/systemd/shirudo-initrd.service.inindex 09513771..f955e711 100644--- a/systemd/shirudo-initrd.service.in+++ b/systemd/shirudo-initrd.service.in@@ -34,6 +34,7 @@ Type=oneshotLimitMEMLOCK=infinityRemainAfterExit=yesKeyringMode=inherit+ExecStartPre=/usr/bin/mount -o remount,rw /sysrootExecStart=@bindir@/shirudo init[Install]diff --git a/tools/gen-initrd/module-setup.sh b/tools/gen-initrd/module-setup.shindex 7a07f8f2..e107b335 100755--- a/tools/gen-initrd/module-setup.sh+++ b/tools/gen-initrd/module-setup.sh@@ -97,6 +97,7 @@ install() {fi[[ -r $conf ]] || return 1inst_simple "$conf" /etc/shirudo/shirudo.conf || return 1+ inst_multiple mount || return 1# dracut keeps the owner of what it copies, and init refuses keys# and configuration another user could change.chown -R 0:0 "$initdir/etc/shirudo" || return 1