Skip to content

eBPF-based security platform

keys: list the dm-verity keyring and every link of both

Daniel Borkmann777fcb107adc
diff --git a/Documentation/contribute/test-coverage.rst b/Documentation/contribute/test-coverage.rst
index be186230..a65603c9 100644
--- a/Documentation/contribute/test-coverage.rst
+++ b/Documentation/contribute/test-coverage.rst
@@ -104,7 +104,8 @@ signed config image.
- Signer identification for a revocation purge, prediction of a
revoke event
* - ``t2101-keys``
- - Two enrolled certificates, a upatch signed by the second loads
+ - Two enrolled certificates, both keyrings as ``keys`` lists them,
+ a upatch signed by the second loads
* - ``t2102-keys-add``
- Live ``keys add`` is refused under a signed config
* - ``t2103-keys-revoke``
diff --git a/Documentation/operate/keys.rst b/Documentation/operate/keys.rst
index 9cc5250e..77d2c3d7 100644
--- a/Documentation/operate/keys.rst
+++ b/Documentation/operate/keys.rst
@@ -146,7 +146,7 @@ the config, and changing ``config.image`` has no effect.
Check what a target trusts
--------------------------
-1. Show the certificates, the trusted set and the ``.bpf`` keyring:
+1. Show the certificates, the trusted set and both keyrings:
.. code-block:: console
@@ -155,45 +155,61 @@ Check what a target trusts
Subject: /CN=shirudo
Issuer: /CN=shirudo (self-signed)
Public-key: ML-DSA-87
- Fingerprint: SHA256:d95db97ff4658b96b8b538afef41a25ca9f7a2c4d0abffdb26cbac7b0ba294b9
- SPKI fingerprint: SHA256:d1dc6624ee6bd0c277864fab0a8a15f8509308aa2338768cb772117c157f8d61
- Valid from: 2026-10-29T16:16:30Z
- Valid until: 2036-10-26T16:16:30Z
+ Fingerprint: SHA256:75171e034357238625311a1c810f7466835ac1dfbc73e9fbd383523439b24125
+ SPKI fingerprint: SHA256:7773eae1c45bc435d9591068da9c318afacfe486007f5386a70ade477f670d69
+ Valid from: 2026-10-29T21:50:28Z
+ Valid until: 2036-10-26T21:50:28Z
Expires in: 9y 364d
Signing key (/run/shirudo/runtime/keys/signing_key.pem):
Present: no (target host -- private key lives on the operator)
Trusted set (2 members, 0 revoked, 0 unvouched):
- 2edb279c05efee6b489a65ae07fd6d402a54b6e495be68f6d364544e9b5a37e2
- sha256 3702e8ffe817ade6151eea338194649cc3a5be1e0b940e462a1a75e52f7095d0
- vouched by d1dc6624ee6bd0c277864fab0a8a15f8509308aa2338768cb772117c157f8d61
- d1dc6624ee6bd0c277864fab0a8a15f8509308aa2338768cb772117c157f8d61 (primary)
- sha256 d95db97ff4658b96b8b538afef41a25ca9f7a2c4d0abffdb26cbac7b0ba294b9
+ 7773eae1c45bc435d9591068da9c318afacfe486007f5386a70ade477f670d69 (primary)
+ sha256 75171e034357238625311a1c810f7466835ac1dfbc73e9fbd383523439b24125
+ 4e4d8da3b0d1a69205a3767baca002c052e90af92bc9815d245f9b25dc1b7d9a
+ sha256 ba3d36544ecfe66b43ea2db498f8f8e50b09fd6f301952636d120c648f76a740
+ vouched by 7773eae1c45bc435d9591068da9c318afacfe486007f5386a70ade477f670d69
Keyring (.bpf):
- Serial: 420195959
- Frozen serial: 420195959 (matches)
+ Serial: 854623986
+ Frozen serial: 854623986 (matches)
Members (2):
- serial=410418068 type=asymmetric shirudo: d10a391a9f1067ed9f64e4ea9b738cf9258b478a
- serial=746517937 type=asymmetric shirudo: 6935ce2048ec5a5ed607db8f5ac1c005c29f32a4
+ serial=209590502 type=asymmetric shirudo: 08967f45330deb21bf31301e56bdf154283e2e58 (frozen)
+ serial=646964383 type=asymmetric shirudo: 8e781f2c1c0e9bccbba9d1d286129128e830e81f (frozen)
+
+ Keyring (.dm-verity):
+ Serial: 684706098
+ Frozen serial: 684706098 (matches)
+ Members (1):
+ serial=37657992 type=asymmetric shirudo: 08967f45330deb21bf31301e56bdf154283e2e58 (frozen)
``Cert`` is the runtime primary. The trusted set lists each member by
its SPKI fingerprint, with the SHA-256 of its DER and the member that
vouched for it. ``Keyring (.bpf)`` is what the kernel verifies signed
- loaders against: the serial init froze, and one key per
- member.
+ loaders against: the serial init froze, and one key per member.
+ ``Keyring (.dm-verity)`` holds the one key the kernel verifies config
+ roots with. ``(frozen)`` marks a member ``init`` recorded; a member
+ marked ``(NOT frozen)`` is trusted by the kernel all the same, and
+ ``shirudo status`` reports the target ``tampered``.
-2. Read the same counts from the status report:
+2. Read the same set from the status report, each certificate with the
+ key that holds it:
.. code-block:: console
target# shirudo status
...
Keyring (.bpf):
- Serial: 420195959
- Frozen serial: 420195959 (matches)
+ Serial: 854623986
+ Frozen serial: 854623986 (matches)
Certificates: 2 trusted, 0 revoked, 0 unvouched, 2 in the bpf keyring
+ 7773eae1c45bc435d9591068da9c318afacfe486007f5386a70ade477f670d69 (primary)
+ CN=shirudo, ML-DSA-87, valid 2026-10-29 to 2036-10-26
+ key 209590502 shirudo: 08967f45330deb21bf31301e56bdf154283e2e58 (frozen)
+ 4e4d8da3b0d1a69205a3767baca002c052e90af92bc9815d245f9b25dc1b7d9a
+ CN=shirudo, ML-DSA-87, valid 2026-10-29 to 2036-10-26
+ key 646964383 shirudo: 8e781f2c1c0e9bccbba9d1d286129128e830e81f (frozen)
...
``unvouched`` counts certificates under ``keys/trusted`` without a
diff --git a/Documentation/reference/cli/keys.rst b/Documentation/reference/cli/keys.rst
index 1a29eb97..748f00e6 100644
--- a/Documentation/reference/cli/keys.rst
+++ b/Documentation/reference/cli/keys.rst
@@ -44,8 +44,9 @@ Display
- the trusted set, when it has more than the primary certificate or
holds revoked or unvouched entries: each member's SPKI fingerprint, the
SHA-256 of its certificate and the certificate that vouched for it.
-- the ``.bpf`` keyring ``init`` froze: its serial, the frozen serial and
- the keys in it.
+- the ``.bpf`` and ``.dm-verity`` keyrings ``init`` froze: each one's
+ serial, the frozen serial and every member, whatever its type, marked
+ ``(frozen)`` when ``init`` recorded it and ``(NOT frozen)`` otherwise.
The keys directory is ``--keys-dir``, else ``$SHIRUDO_KEYS_DIR``, else
``/var/lib/shirudo/keys``. On a target with an active config image it is
@@ -189,28 +190,34 @@ Show the key material on a target:
Subject: /CN=shirudo
Issuer: /CN=shirudo (self-signed)
Public-key: ML-DSA-87
- Fingerprint: SHA256:d95db97ff4658b96b8b538afef41a25ca9f7a2c4d0abffdb26cbac7b0ba294b9
- SPKI fingerprint: SHA256:d1dc6624ee6bd0c277864fab0a8a15f8509308aa2338768cb772117c157f8d61
- Valid from: 2026-10-29T16:16:30Z
- Valid until: 2036-10-26T16:16:30Z
+ Fingerprint: SHA256:75171e034357238625311a1c810f7466835ac1dfbc73e9fbd383523439b24125
+ SPKI fingerprint: SHA256:7773eae1c45bc435d9591068da9c318afacfe486007f5386a70ade477f670d69
+ Valid from: 2026-10-29T21:50:28Z
+ Valid until: 2036-10-26T21:50:28Z
Expires in: 9y 364d
Signing key (/run/shirudo/runtime/keys/signing_key.pem):
Present: no (target host -- private key lives on the operator)
Trusted set (2 members, 0 revoked, 0 unvouched):
- 2edb279c05efee6b489a65ae07fd6d402a54b6e495be68f6d364544e9b5a37e2
- sha256 3702e8ffe817ade6151eea338194649cc3a5be1e0b940e462a1a75e52f7095d0
- vouched by d1dc6624ee6bd0c277864fab0a8a15f8509308aa2338768cb772117c157f8d61
- d1dc6624ee6bd0c277864fab0a8a15f8509308aa2338768cb772117c157f8d61 (primary)
- sha256 d95db97ff4658b96b8b538afef41a25ca9f7a2c4d0abffdb26cbac7b0ba294b9
+ 7773eae1c45bc435d9591068da9c318afacfe486007f5386a70ade477f670d69 (primary)
+ sha256 75171e034357238625311a1c810f7466835ac1dfbc73e9fbd383523439b24125
+ 4e4d8da3b0d1a69205a3767baca002c052e90af92bc9815d245f9b25dc1b7d9a
+ sha256 ba3d36544ecfe66b43ea2db498f8f8e50b09fd6f301952636d120c648f76a740
+ vouched by 7773eae1c45bc435d9591068da9c318afacfe486007f5386a70ade477f670d69
Keyring (.bpf):
- Serial: 420195959
- Frozen serial: 420195959 (matches)
+ Serial: 854623986
+ Frozen serial: 854623986 (matches)
Members (2):
- serial=410418068 type=asymmetric shirudo: d10a391a9f1067ed9f64e4ea9b738cf9258b478a
- serial=746517937 type=asymmetric shirudo: 6935ce2048ec5a5ed607db8f5ac1c005c29f32a4
+ serial=209590502 type=asymmetric shirudo: 08967f45330deb21bf31301e56bdf154283e2e58 (frozen)
+ serial=646964383 type=asymmetric shirudo: 8e781f2c1c0e9bccbba9d1d286129128e830e81f (frozen)
+
+ Keyring (.dm-verity):
+ Serial: 684706098
+ Frozen serial: 684706098 (matches)
+ Members (1):
+ serial=37657992 type=asymmetric shirudo: 08967f45330deb21bf31301e56bdf154283e2e58 (frozen)
Vouch for a second operator's certificate:
diff --git a/builtin-keys.c b/builtin-keys.c
index f6205671..dd57c2c6 100644
--- a/builtin-keys.c
+++ b/builtin-keys.c
@@ -306,90 +306,93 @@ static int keys_dump_disk_material(const char *cert_path,
return rc ? 1 : 0;
}
-struct list_row {
- key_serial_t serial;
- char *type;
- char *description;
+/* A keyring init froze: its serial and the keys it recorded in it. */
+struct keys_anchor {
+ const char *label;
+ key_serial_t (*serial)(void);
+ key_serial_t frozen; /* 0 when none was recorded */
+ const __s32 *keys;
+ size_t n_keys;
};
-#define LIST_ROW_CAP 256
+static bool keys_anchor_holds(const struct keys_anchor *a, key_serial_t key)
+{
+ size_t i;
-struct list_ctx {
- struct list_row rows[LIST_ROW_CAP];
- int count;
-};
+ for (i = 0; i < a->n_keys; i++)
+ if (a->keys[i] == key)
+ return true;
+ return false;
+}
-static void collect_key(key_serial_t serial, const char *type,
- const char *description, void *ud)
+/* Kernel descriptions carry certificate subjects: keep the terminal safe. */
+static void print_safe(const char *s)
{
- struct list_ctx *c = ud;
-
- if (c->count >= LIST_ROW_CAP)
- return;
- c->rows[c->count].serial = serial;
- c->rows[c->count].type = xstrdup(type);
- c->rows[c->count].description = xstrdup(description);
- c->count++;
+ for (; *s; s++)
+ putchar((__u8)*s < 0x20 || *s == 0x7f ? '?' : *s);
}
-static int keys_list_keyring(key_serial_t ring, const char *label,
- const struct shirudo_identity *id, int id_rc)
+static int keys_list_keyring(key_serial_t ring, const struct keys_anchor *a,
+ int id_rc)
{
- struct list_ctx c = {};
- int rc, i;
+ bool frozen = !id_rc && a->frozen > 0;
+ struct keyring_link *links = NULL;
+ size_t n = 0, i;
+ int rc;
- printf("Keyring (%s):\n", label);
+ printf("Keyring (%s):\n", a->label);
printf(" %-22s %d\n", "Serial:", (int)ring);
-
- if (id_rc == 0) {
- const char *match = id->keyring_serial == ring ?
- "matches" : "MISMATCH";
-
- printf(" %-22s %d (%s)\n", "Frozen serial:",
- (int)id->keyring_serial, match);
- if (id->keyring_serial != ring)
- pr_warn("keyring serial %d != frozen %d (swap?)",
- (int)ring, (int)id->keyring_serial);
- } else if (id_rc == -ENOENT) {
- printf(" %-22s %s\n", "Frozen serial:",
- "(none this boot)");
+ if (frozen) {
+ printf(" %-22s %d (%s)\n", "Frozen serial:", (int)a->frozen,
+ a->frozen == ring ? "matches" : "MISMATCH");
+ if (a->frozen != ring)
+ pr_warn("%s keyring serial %d != frozen %d (swap?)",
+ a->label, (int)ring, (int)a->frozen);
+ } else if (!id_rc || id_rc == -ENOENT) {
+ printf(" %-22s %s\n", "Frozen serial:", "(none this boot)");
} else {
printf(" %-22s unreadable: %s\n", "Frozen serial:",
strerror(-id_rc));
}
- rc = keyring_list(ring, collect_key, &c);
+ rc = keyring_links(ring, &links, &n);
if (rc) {
pr_err("keyring list: %s", strerror(-rc));
- goto out;
+ return 1;
}
- printf(" Members (%d):\n", c.count);
- if (c.count == 0)
+ printf(" Members (%zu):\n", n);
+ if (!n)
printf(" (empty)\n");
- for (i = 0; i < c.count; i++)
- printf(" serial=%-10d type=%-10s %s\n",
- (int)c.rows[i].serial,
- c.rows[i].type ? c.rows[i].type : "?",
- c.rows[i].description ? c.rows[i].description : "?");
-out:
- for (i = 0; i < c.count; i++) {
- xstrfree(c.rows[i].type);
- xstrfree(c.rows[i].description);
+ for (i = 0; i < n; i++) {
+ const struct keyring_link *l = &links[i];
+
+ printf(" serial=%-10d type=%-10s ", (int)l->serial,
+ l->err ? "?" : l->type);
+ if (l->err)
+ printf("(cannot describe: %s)", strerror(-l->err));
+ else
+ print_safe(l->description);
+ if (frozen)
+ printf(" (%s)", keys_anchor_holds(a, l->serial) ?
+ "frozen" : "NOT frozen");
+ printf("\n");
}
- return rc ? 1 : 0;
+ if (links)
+ xfree(links, n * sizeof(*links));
+ return 0;
}
-static void keyring_absent(const char *label, key_serial_t rc,
- const struct shirudo_identity *id, int id_rc)
+static void keyring_absent(const struct keys_anchor *a, key_serial_t rc,
+ int id_rc)
{
- printf("Keyring (%s):\n", label);
+ printf("Keyring (%s):\n", a->label);
if (rc != (key_serial_t)-ENOKEY)
printf(" %-22s lookup error: %s\n", "Present:",
strerror(-rc));
- else if (id_rc == 0)
+ else if (!id_rc && a->frozen > 0)
printf(" %-22s no (gone: init froze serial %d this boot)\n",
- "Present:", (int)id->keyring_serial);
- else if (id_rc == -ENOENT)
+ "Present:", (int)a->frozen);
+ else if (!id_rc || id_rc == -ENOENT)
printf(" %-22s %s\n", "Present:",
"no (operator host, or `shirudo init` not yet run)");
else
@@ -912,14 +915,12 @@ int cmd_keys(int argc, const char **argv)
static int keys_show(int argc, const char **argv)
{
const char *keys_dir_arg = NULL;
+ struct shirudo_identity id = {};
struct shirudo_trusted_set set;
- struct shirudo_identity id;
const char *keys_dir;
char pkey_path[PATH_MAX];
char cert_path[PATH_MAX];
bool shown = false;
- key_serial_t ring;
- const char *label;
int rc = 0, id_rc;
for (int i = 1; i < argc; i++) {
@@ -988,25 +989,41 @@ static int keys_show(int argc, const char **argv)
}
id_rc = identity_read(&id);
- label = ".bpf";
- ring = id_rc ? -ENOKEY : keyring_bpf_serial();
- if (ring >= 0) {
- if (shown)
- printf("\n");
- if (keys_list_keyring(ring, label, &id, id_rc))
- rc = 1;
- shown = true;
- } else if (ring == -ENOKEY && id_rc) {
- if (shown) {
- printf("\n");
- keyring_absent(label, ring, &id, id_rc);
+ {
+ const struct keys_anchor anchors[] = {
+ { ".bpf", keyring_bpf_serial, id.keyring_serial,
+ id.key_serials,
+ id.n_keys < SHIRUDO_IDENTITY_KEYS_MAX ?
+ id.n_keys : SHIRUDO_IDENTITY_KEYS_MAX },
+ { ".dm-verity", shirudo_keyring_dm_verity_serial,
+ id.dm_verity_ring, &id.dm_verity_key,
+ id.dm_verity_key > 0 },
+ };
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(anchors); i++) {
+ const struct keys_anchor *a = &anchors[i];
+ key_serial_t ring = id_rc ? -ENOKEY : a->serial();
+
+ if (ring >= 0) {
+ if (shown)
+ printf("\n");
+ if (keys_list_keyring(ring, a, id_rc))
+ rc = 1;
+ shown = true;
+ } else if (ring == -ENOKEY && id_rc) {
+ if (shown) {
+ printf("\n");
+ keyring_absent(a, ring, id_rc);
+ }
+ } else {
+ if (shown)
+ printf("\n");
+ keyring_absent(a, ring, id_rc);
+ shown = true;
+ rc = 1;
+ }
}
- } else {
- if (shown)
- printf("\n");
- keyring_absent(label, ring, &id, id_rc);
- shown = true;
- rc = 1;
}
if (!shown) {
diff --git a/testing/functional/signing/t2101-keys.sh b/testing/functional/signing/t2101-keys.sh
index cf9f1c5a..99ad4312 100755
--- a/testing/functional/signing/t2101-keys.sh
+++ b/testing/functional/signing/t2101-keys.sh
@@ -4,8 +4,9 @@
#
# t2101 -- the enrolled certificate set: the bundle's own-keyring
# certificate was installed as a second trusted certificate before
-# init, so the bpf keyring holds two keys and a upatch signed by either
-# loads.
+# init, so the bpf keyring holds two keys, keys lists them and the
+# dm-verity keyring's config key as init froze them, and a upatch signed
+# by either loads.
cd "$(dirname "$0")/../.."
. ./integration-lib.sh
@@ -52,6 +53,26 @@ test_expect_success 'the second certificate is a member by the primary vouch' '
[ -s "/var/lib/shirudo/keys/trusted/$OWN_FP.vouch" ]
'
+test_expect_success 'keys lists both keyrings, every member frozen' '
+ "$SHIRUDO_BIN" keys 2>/dev/null >"$W/keys" &&
+ python3 - "$W/keys" <<"PY"
+import re, subprocess, sys
+text = open(sys.argv[1], encoding="utf-8").read()
+for label, members in ((".bpf", 2), (".dm-verity", 1)):
+ section = text.split("Keyring (%s):\n" % label, 1)[1].split("\n\n", 1)[0]
+ ring = int(re.search(r"^ Serial: +(\d+)$", section, re.M).group(1))
+ assert re.search(r"^ Frozen serial: +%d \(matches\)$" % ring, section,
+ re.M), section
+ assert " Members (%d):\n" % members in section, section
+ listed = sorted(int(s) for s in re.findall(
+ r"^ serial=(\d+) .* \(frozen\)$", section, re.M))
+ out = subprocess.run(["keyctl", "rlist", str(ring)], check=True,
+ capture_output=True, text=True).stdout
+ assert listed == sorted(int(s) for s in out.split()), (label, listed, out)
+ assert "NOT frozen" not in section, section
+PY
+'
+
test_expect_success 'the init record covers the set' '
grep "\"type\":\"init\"" /var/lib/shirudo/eventlog | tail -1 |
python3 -c "