eBPF-based security platform
init: remove every map pin a crashed attempt left before attaching
Daniel Borkmannee845bab3218
diff --git a/Documentation/internals/enforcement.rst b/Documentation/internals/enforcement.rstindex beaee46a..ea8f17cb 100644--- a/Documentation/internals/enforcement.rst+++ b/Documentation/internals/enforcement.rst@@ -266,7 +266,12 @@ admission gates. ``init`` itself passes every guard on the way becauseits bootstrap mark is in place before the first one attaches.When any step fails, ``init`` unpins every link it attached and removes-the map pins, so no partial enforcement survives a failed ``init``.+the map pins, so no partial enforcement survives a failed ``init``. A+crash skips that cleanup. When it came before the identity map was+pinned, the next ``init`` removes the map pins it left. When it came+later, every later ``init`` in the same boot refuses before it loads+anything, with ``init: authenticated image settings: <error>``, and the+guards attached so far stay until the next reboot.Order at run time-----------------diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 42f08073..18635faf 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -1937,8 +1937,12 @@ U11 The boot continues when init fails:Consequence: The initrd unit is wanted by ``initrd.target`` and hasconditions, so a failure or a skip lets the target bootunprotected. A first ``init`` from the root file system is not- refused and takes its settings from the root file system.- :Status: Confirmed in code.+ refused and takes its settings from the root file system. An+ ``init`` that crashes once it has pinned the identity map leaves+ the guards it attached so far, and every later ``init`` of that+ boot refuses, so enforcement stays partial until the next reboot.+ :Status: Confirmed in code; what a crash leaves is a code-path+ reading, not reproduced.:Meanwhile: Attest every target after every boot with the bind PCRspinned, and treat a missing keepalive as a signal. A deployer whoprefers a halted boot can add an ``OnFailure=`` drop-in todiff --git a/builtin-init.c b/builtin-init.cindex 462492bf..e69042b5 100644--- a/builtin-init.c+++ b/builtin-init.c@@ -619,21 +619,19 @@ static int init_lsm(void)shirudo_gate_guards[GUARD_BPF].pin);return 0;}- /* A pin without the links behind it is what a failed attempt leaves. */- if (unlink(IDENTITY_PIN) != 0 && errno != ENOENT) {- pr_err("unlink stale %s: %s", IDENTITY_PIN,- strerror(errno));- return -errno;- }- if (unlink(TAMPER_PIN) != 0 && errno != ENOENT) {- pr_err("unlink stale %s: %s", TAMPER_PIN,- strerror(errno));- return -errno;- }- if (unlink(INTEGRITY_PIN) != 0 && errno != ENOENT) {- pr_err("unlink stale %s: %s", INTEGRITY_PIN,- strerror(errno));- return -errno;+ /*+ * A failed attempt removes its own pins, a crash does not. Once the+ * identity map is pinned, image_bootstrap_load() refuses a re-run+ * before it gets here, so map pins are all a crash can have left.+ */+ for (i = 0; i < GUARD_MAP_COUNT; i++) {+ const char *pin = shirudo_guard_maps[i].pin;++ if (unlink(pin) != 0 && errno != ENOENT) {+ err = -errno;+ pr_err("unlink stale %s: %s", pin, strerror(-err));+ return err;+ }}if (!blob || !blob->data || !blob->size) {