eBPF-based security platform
init: hold the register lock while a re-run checks the restore
Daniel Borkmann2112557a7978
diff --git a/Documentation/internals/measurement-register.rst b/Documentation/internals/measurement-register.rstindex c1bf808d..9c06112a 100644--- a/Documentation/internals/measurement-register.rst+++ b/Documentation/internals/measurement-register.rst@@ -282,7 +282,9 @@ a successful extension is reported as a desync for the operator toreconcile.``init`` binds the register and writes its record without taking this-lock.+lock, from the initrd, before any upatch command is admitted. Its run+from the root file system, which upatch commands can run beside, holds+the lock while it checks the archive against the pins.Lean 4 proves this protocol for every sequence of loads, unloads,purges, kills, failed steps, reboots and root's changes to unlabeleddiff --git a/builtin-init.c b/builtin-init.cindex 684a3962..77b74f79 100644--- a/builtin-init.c+++ b/builtin-init.c@@ -919,8 +919,8 @@ out:* into the archive since, or left behind by an unload cut short, and* either is for the operator to resolve.*/-static int boot_restore(bool recorded,- struct measured_upatch **out_set, size_t *out_n)+static int boot_restore_locked(bool recorded,+ struct measured_upatch **out_set, size_t *out_n){struct measured_upatch *set = NULL;struct measured_set *measured = NULL;@@ -1051,6 +1051,32 @@ next:return 0;}+/*+ * A run after the register was bound this boot runs beside the upatch+ * commands the completed activation admits, so it takes their lock: an+ * unload between the archive scan and the pin check is otherwise taken+ * for an archived upatch that is not loaded.+ */+static int boot_restore(bool recorded,+ struct measured_upatch **out_set, size_t *out_n)+{+ int lock = -1, ret;++ if (recorded) {+ lock = eventlog_lock();+ if (lock < 0) {+ pr_err("boot-restore: cannot take the register lock: %s",+ strerror(-lock));+ *out_set = NULL;+ *out_n = 0;+ return lock;+ }+ }+ ret = boot_restore_locked(recorded, out_set, out_n);+ eventlog_unlock(lock);+ return ret;+}+/* The binding a verifier needs to recompute the register's public area. */static int append_init_event(const struct measured_upatch *set,size_t n,