Skip to content

eBPF-based security platform

keys: let a boot go on past an archive that names no signer

John Fastabendffcbbf6f62ac
diff --git a/Documentation/internals/config-images.rst b/Documentation/internals/config-images.rst
index c8939c51..572232b2 100644
--- a/Documentation/internals/config-images.rst
+++ b/Documentation/internals/config-images.rst
@@ -231,7 +231,12 @@ It then activates it:
At boot, ``init`` runs the same sequence as a boot event for the selected
config, but completes it only at the end of ``init``, after the restore
-and the register binding. :doc:`boot-flow` gives the boot order. Figure 1
+and the register binding. A live update refuses a config with revocation
+records, in step 1 and again in step 6, while the archive holds a file no
+signer can be read from. A boot enrolls no revoked key and leaves such a
+file for the restore to ignore, unless a pin directory or a jar of its
+name exists, as after an ``init`` run by hand in a boot that loaded
+upatches. :doc:`boot-flow` gives the boot order. Figure 1
shows the sequence, the two ways into it, and the span in which an
interruption leaves the selection pending.
diff --git a/Documentation/operate/maintain/keys.rst b/Documentation/operate/maintain/keys.rst
index 39317581..41e72325 100644
--- a/Documentation/operate/maintain/keys.rst
+++ b/Documentation/operate/maintain/keys.rst
@@ -457,7 +457,12 @@ Limits
``/var/lib/shirudo/upatches`` holds an archive no signer can be read
from. ``shirudo image update`` then prints ``keys revoke:
<name>.upatch names no signer: <error>; nothing revoked`` and changes
- nothing: no key is unlinked and nothing is measured.
+ nothing: no key is unlinked and nothing is measured. A boot does not
+ refuse: ``init`` logs ``keys revoke: <name>.upatch is left for
+ boot-restore to ignore`` and completes. An archive that does not parse
+ is then not restored, and ``shirudo status`` does not report it: the
+ node reads ``ok`` with a loaded set, in ``status`` and in the
+ keepalive, that is one upatch short.
- Vouches are historical authorizations. Revoking A does not
automatically revoke B merely because A vouched for it. After a
compromise, the config signer must explicitly revoke any certificate
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index ab750534..08659da1 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -1841,7 +1841,13 @@ R13 Revocation reaches a target only through a config
the config PCR and again before it unlinks the first key, and refuses
without changing anything while one is there. An error that the check
could not foresee still fails the purge part-way, and the activation
- stays pending.
+ stays pending. A boot activation does not make that check: it enrolls
+ no revoked key, so nothing such a key signed passes the signature
+ check of a restore, and an archive the purge cannot attribute is left
+ for the restore to ignore as long as nothing runs under its name. A
+ node boots with such an archive, less the upatch it held; a refusal
+ would fail ``init`` at every boot, with no command that removes the
+ file.
BPF loads require a complete CMS envelope, and the purge reads an
archived signature by the same rule.
At boot the revoked key is not enrolled, and the init event's
diff --git a/builtin-keys.c b/builtin-keys.c
index 95c9cd5f..42490208 100644
--- a/builtin-keys.c
+++ b/builtin-keys.c
@@ -886,8 +886,14 @@ int keys_revoke_check(void)
* would refuse to restore it at the next boot, and keeping it loaded
* would keep running what a key nobody trusts any more authorised. The
* rest are still tried when one fails.
+ *
+ * A boot enrolls no revoked key, so the kernel loads nothing one signed
+ * and boot-restore is left to ignore an archive that names no signer.
+ * Refusing it would fail every boot, with no command to remove the file.
+ * Live, the key was trusted until now and such an archive fails the
+ * revocation, as keys_revoke_check() says before anything changed.
*/
-static int purge_signed_by(const __u8 *der, size_t der_sz,
+static int purge_signed_by(const __u8 *der, size_t der_sz, bool boot,
size_t *unloaded)
{
struct cert cert = {};
@@ -922,6 +928,13 @@ static int purge_signed_by(const __u8 *der, size_t der_sz,
if (prc == UPATCH_PURGE_OTHER_SIGNER ||
prc == UPATCH_PURGE_NO_ARCHIVE)
continue;
+ if (prc == UPATCH_PURGE_NO_SIGNER && boot) {
+ pr_warn("keys revoke: %s.upatch is left for boot-restore to ignore",
+ name);
+ continue;
+ }
+ if (prc == UPATCH_PURGE_NO_SIGNER)
+ prc = -EBADMSG;
if (prc < 0) {
pr_err("keys revoke: purge %s: %s", name,
strerror(-prc));
@@ -969,7 +982,7 @@ int keys_revoke_image(const __u8 *der, size_t size, bool boot)
return ret;
}
}
- ret = purge_signed_by(der, size, &unloaded);
+ ret = purge_signed_by(der, size, boot, &unloaded);
return min(ret, 0);
}
diff --git a/builtin-upatch.c b/builtin-upatch.c
index 88de1265..e9003743 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -4100,6 +4100,44 @@ int upatch_purge_check(const char *name)
return ret;
}
+/*
+ * 1 when something may run under a name whose archive does not say what
+ * it is: its pin directory, or a jar. A reboot takes both away.
+ */
+static int purge_name_runs(const char *name)
+{
+ char jar[PATH_MAX];
+ struct stat st;
+ int ret;
+
+ ret = upatch_pinned(name);
+ if (ret)
+ return ret;
+ ret = java_agent_path(name, jar, sizeof(jar));
+ if (ret)
+ return ret;
+ if (!lstat(jar, &st))
+ return 1;
+ return errno == ENOENT ? 0 : -errno;
+}
+
+/*
+ * An archive no signer can be read from: err, unless nothing runs under
+ * its name, which leaves the revocation nothing to unload.
+ */
+static int purge_no_signer(const char *name, int err)
+{
+ int runs = purge_name_runs(name);
+
+ if (runs < 0)
+ return runs;
+ if (runs)
+ return err;
+ pr_warn("upatch purge: %s.upatch names no signer: %s", name,
+ strerror(-err));
+ return UPATCH_PURGE_NO_SIGNER;
+}
+
static int upatch_purge_locked(const char *name, const struct cert *signer,
const char *reason)
{
@@ -4113,14 +4151,18 @@ static int upatch_purge_locked(const char *name, const struct cert *signer,
UPATCHES_DIR, name) < 0)
return -ENAMETOOLONG;
ret = purge_archive_open(persisted, name, &u);
+ if (ret < 0)
+ return purge_no_signer(name, ret);
if (ret)
return ret;
ret = cms_signed_by(upatch_signature(&u), u.hdr.signature_len, signer);
memcpy(payload, u.hdr.payload_sha256, sizeof(payload));
type = u.hdr.type;
upatch_close(&u);
+ if (ret < 0)
+ return purge_no_signer(name, ret);
if (ret != 1)
- return ret < 0 ? ret : UPATCH_PURGE_OTHER_SIGNER;
+ return UPATCH_PURGE_OTHER_SIGNER;
/* As for unload: the event first, then the detach it describes. */
loaded = purge_is_loaded(name, type);
diff --git a/util/image_keys.c b/util/image_keys.c
index 34eb7496..fb05a67f 100644
--- a/util/image_keys.c
+++ b/util/image_keys.c
@@ -189,7 +189,7 @@ int keys_apply_image(int root_fd, bool boot)
int ret;
ret = keys_validate_image(root_fd);
- if (!ret)
+ if (!ret && !boot)
ret = keys_check_image_purge(root_fd);
return ret ? ret : revocations(root_fd, true, boot, &records);
}
diff --git a/util/image_runtime.c b/util/image_runtime.c
index 31319890..54e2d5ee 100644
--- a/util/image_runtime.c
+++ b/util/image_runtime.c
@@ -52,6 +52,8 @@
enum config_prepare {
CONFIG_PREPARE_BOOT,
+ /* The boot's activation event, of the config init just enrolled. */
+ CONFIG_PREPARE_BOOT_EVENT,
CONFIG_PREPARE_UPDATE,
CONFIG_PREPARE_STAGE,
};
@@ -613,16 +615,20 @@ static int remove_candidate(struct dm_verity *device)
return ret;
}
-static noinline_for_stack int candidate_keys(int fd, bool enrolled)
+static noinline_for_stack int candidate_keys(int fd,
+ enum config_prepare purpose)
{
struct trusted_set set = {};
int ret;
ret = keys_validate_image_set(RUNTIME_CERT_PATH, fd, &set);
- if (!ret && enrolled)
+ if (!ret && purpose != CONFIG_PREPARE_STAGE)
ret = keys_check_image_set(&set);
- /* Before the activation PCR is extended, which nothing takes back. */
- if (!ret && enrolled)
+ /*
+ * Before the activation PCR is extended, which nothing takes back.
+ * A boot enrolled no revoked key and purges what it can.
+ */
+ if (!ret && purpose == CONFIG_PREPARE_UPDATE)
ret = keys_check_image_purge(fd);
if (ret == -ENOKEY)
pr_err("image: BPF signer was not enrolled at boot; "
@@ -729,8 +735,7 @@ static int prepare_config(struct image_context *current,
if (!ret)
ret = image_config_validate(current->candidate_fd);
if (!ret && !trusted_boot)
- ret = candidate_keys(current->candidate_fd,
- purpose == CONFIG_PREPARE_UPDATE);
+ ret = candidate_keys(current->candidate_fd, purpose);
out:
if (ret && created) {
close_candidate();
@@ -781,6 +786,12 @@ static int prepare_update(void *ctx,
return prepare_config(ctx, target, CONFIG_PREPARE_UPDATE);
}
+static int prepare_boot_event(void *ctx,
+ const struct config_update_target *target)
+{
+ return prepare_config(ctx, target, CONFIG_PREPARE_BOOT_EVENT);
+}
+
static int activate_update(void *ctx,
const struct config_update_target *target)
{
@@ -807,7 +818,7 @@ static const struct config_update_ops boot_ops = {
.boot_identity = boot_identity,
.pcr_read = pcr_read,
.pcr_extend = pcr_extend,
- .prepare = prepare_update,
+ .prepare = prepare_boot_event,
.activate = activate_boot,
.seal = seal_fd,
};
diff --git a/util/upatch.h b/util/upatch.h
index 360a48af..02b60979 100644
--- a/util/upatch.h
+++ b/util/upatch.h
@@ -245,11 +245,14 @@ struct cert;
* that signed the upatch was revoked: 1 when the unload was measured,
* 0 when only the archive went, UPATCH_PURGE_OTHER_SIGNER when the archive
* stays because another key signed it, UPATCH_PURGE_NO_ARCHIVE when the
- * name has none, -errno on failure. An -ENOENT is a failure like any
- * other: the register lock or a pin was not there.
+ * name has none, UPATCH_PURGE_NO_SIGNER when it stays because no signer
+ * can be read from it and nothing runs under its name, -errno on
+ * failure. An -ENOENT is a failure like any other: the register lock or
+ * a pin was not there.
*/
#define UPATCH_PURGE_OTHER_SIGNER 2
#define UPATCH_PURGE_NO_ARCHIVE 3
+#define UPATCH_PURGE_NO_SIGNER 4
int upatch_purge(const char *name, const struct cert *signer,
const char *reason);