Skip to content

eBPF-based security platform

initrd: Remount sysroot read-write before bootstrap

Michi Mutsuzakid4a82bdea816
diff --git a/Documentation/initrd.rst b/Documentation/initrd.rst
index 826aaea5..2e6071a4 100644
--- a/Documentation/initrd.rst
+++ b/Documentation/initrd.rst
@@ -28,8 +28,9 @@ commands, `architecture <architecture.rst>`__ for the LSM flow and
static 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. Config
selections and cached bundles must be durable before PCR extension.
* ``systemd-pcrphase-initrd.service`` and its ``enter-initrd`` measurement
before Shirudo binds its upatch register. A direct QEMU kernel/initrd boot
diff --git a/builtin-init.c b/builtin-init.c
index 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.in
index 09513771..f955e711 100644
--- a/systemd/shirudo-initrd.service.in
+++ b/systemd/shirudo-initrd.service.in
@@ -34,6 +34,7 @@ Type=oneshot
LimitMEMLOCK=infinity
RemainAfterExit=yes
KeyringMode=inherit
+ExecStartPre=/usr/bin/mount -o remount,rw /sysroot
ExecStart=@bindir@/shirudo init
[Install]
diff --git a/tools/gen-initrd/module-setup.sh b/tools/gen-initrd/module-setup.sh
index 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 1
inst_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