Skip to content

eBPF-based security platform

testing: test a revocation against an archive that names no signer

John Fastabendd8153c5b6705
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index 85a3bba6..4e8adb42 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -490,6 +490,13 @@ signed config image.
next boot from the initrd: the signer is not enrolled, the archive
of the upatch it signed is purged and not restored, and a load it
signed is refused
+ * - ``t5107-verity-revocation-archive``
+ - In ``functional/image-reboot/``, with ``t5106``. An archive cut
+ short, which no signer can be read from: a live update with
+ revocation records refuses and changes nothing, before the boot
+ and after it; the boot that revokes completes ``init`` and leaves
+ the file, its upatch is not restored, and ``status`` and the
+ keepalive show the smaller loaded set without a condition for it
``tamperproof`` (6)
~~~~~~~~~~~~~~~~~~~
@@ -1215,7 +1222,8 @@ Coverage by area
``t6134``, ``t6135``, ``t6136``, ``t6137``
* - Keyrings
- ``t2101``, ``t2102``, ``t2103``, ``t5101``, ``t5104``,
- ``t5106``, ``t6004``, ``t6104``, ``t6112``, ``t6129``, ``t6140``
+ ``t5106``, ``t5107``, ``t6004``, ``t6104``, ``t6112``, ``t6129``,
+ ``t6140``
* - Signing keys and the trusted set
- ``t2001``, ``t2002``, ``t2003``, ``t2004``, ``t2005``,
``t5003``. Unit: ``io``
diff --git a/testing/functional/image-reboot/t5107-verity-revocation-archive.py b/testing/functional/image-reboot/t5107-verity-revocation-archive.py
new file mode 100644
index 00000000..8f564427
--- /dev/null
+++ b/testing/functional/image-reboot/t5107-verity-revocation-archive.py
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+
+import importlib.util
+import json
+import os
+from pathlib import Path
+import subprocess
+import sys
+
+spec = importlib.util.spec_from_file_location(
+ "revocation_boot_test",
+ Path(__file__).with_name("t5106-verity-revocation-boot.py"))
+boot = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(boot)
+revocation = boot.revocation
+config = boot.config
+require = config.require
+NAME = "shirudo-test-basic"
+UPATCH = Path(os.environ["SHIRUDO_TEST_FIXTURES_DIR"]) / (NAME + ".upatch")
+PIN = Path("/run/shirudo/bpffs/upatches") / NAME
+ARCHIVE = Path("/var/lib/shirudo/upatches") / (NAME + ".upatch")
+TORN_SIZE = 16
+REFUSAL = f"keys revoke: {NAME}.upatch names no signer"
+
+
+def keepalive():
+ return json.loads(config.run("keepalive", "status", "--keepalive"))
+
+
+def refused_update(label, name, keys):
+ """A live update with revocation records refuses and changes nothing."""
+ before = revocation.snapshot(label + "-before", keys)
+ result = subprocess.run(
+ [config.BINARY, "image", "update", str(config.IMAGES / name)],
+ capture_output=True, text=True, timeout=120)
+ (config.RESULTS / (label + ".stderr")).write_text(result.stderr)
+ require(result.returncode == 1,
+ f"the update was not refused: {result.returncode}\n{result.stderr}")
+ require(REFUSAL in result.stderr and "nothing revoked" in result.stderr,
+ f"the update did not name the archive: {result.stderr}")
+ require(before == revocation.snapshot(label + "-after", keys),
+ "a refused revocation changed state")
+
+
+def main():
+ mode = sys.argv[1]
+ if mode == "tear":
+ require(not PIN.exists() and not ARCHIVE.exists(), "stale upatch")
+ config.run("load", "upatch", "load", UPATCH, "--no-precheck")
+ require(PIN.is_dir() and ARCHIVE.is_file(), "upatch not installed")
+ require(keepalive()["count"] >= 1, "the keepalive counts no upatch")
+ subprocess.run([*config.fault_command(), "archive-truncate", NAME],
+ check=True)
+ require(ARCHIVE.stat().st_size == TORN_SIZE, "archive not cut short")
+ require(PIN.is_dir(), "cutting the archive unloaded the upatch")
+ elif mode == "live":
+ status = json.loads(config.run("stage-status", "image", "status",
+ "--json"))
+ if status["next_boot_root_hash"] != config.root(boot.STAGED):
+ config.run("stage", "image", "stage", config.IMAGES / boot.STAGED)
+ refused_update("live", boot.STAGED, 2)
+ status = json.loads(config.run("staged-status", "image", "status",
+ "--json"))
+ require(status["next_boot_root_hash"] == config.root(boot.STAGED),
+ "the refused update removed the stage")
+ require(PIN.is_dir() and ARCHIVE.stat().st_size == TORN_SIZE,
+ "the refused update touched the upatch")
+ elif mode == "booted":
+ status = json.loads(config.run("status", "status", "--json"))
+ require(status["lsm_attached"] is True, "LSM not attached")
+ require(status["tpm"]["bound_in"] == "initrd",
+ f"register not bound from the initrd: {status['tpm']}")
+ view = revocation.snapshot("booted", 1)
+ require(view["status"]["root_hash"] == config.root(boot.STAGED),
+ "the staged config is not active")
+ journal = boot.initrd_journal()
+ for line in (f"upatch purge: {NAME}.upatch names no signer",
+ f"keys revoke: {NAME}.upatch is left for boot-restore to ignore",
+ f"boot-restore: {NAME}.upatch is not an artifact"):
+ require(line in journal, f"the initrd did not log: {line}")
+ require(not PIN.exists(), "the upatch of the torn archive was restored")
+ require(ARCHIVE.stat().st_size == TORN_SIZE,
+ "the boot changed or removed the torn archive")
+ require(NAME not in [entry["name"]
+ for entry in boot.boot_init_event()["set"]],
+ "the init event counts the upatch of the torn archive")
+ elif mode == "reported":
+ status = json.loads(config.run("status", "status", "--json"))
+ measured = [cond for cond in status["conditions"]
+ if cond["type"] == "UpatchesMeasured"]
+ require(len(measured) == 1 and measured[0]["status"] == "OK",
+ f"status reports the torn archive: {measured}")
+ require(keepalive()["count"] == 0,
+ "the keepalive counts a upatch no boot restored")
+ elif mode == "live-again":
+ refused_update("live-again", "config-interrupted", 1)
+ require(ARCHIVE.stat().st_size == TORN_SIZE,
+ "the refused update touched the torn archive")
+ else:
+ raise ValueError(mode)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/testing/functional/image-reboot/t5107-verity-revocation-archive.sh b/testing/functional/image-reboot/t5107-verity-revocation-archive.sh
new file mode 100644
index 00000000..cca7314d
--- /dev/null
+++ b/testing/functional/image-reboot/t5107-verity-revocation-archive.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# t5107 -- an archive no signer can be read from, as a torn write leaves
+# one, and a config with revocation records. A live update refuses before
+# it changes anything, since it cannot tell whether the revoked key signed
+# what runs. The next boot enrolls no revoked key, so it goes on past the
+# file: init completes and the upatch of that archive is not restored.
+
+cd "$(dirname "$0")/../.."
+. ./integration-lib.sh
+target_guard
+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"
+: "${SHIRUDO_TEST_KEY_FIXTURES:?signed key fixtures are required}"
+: "${SHIRUDO_TEST_FIXTURES_DIR:?signed upatch fixtures are required}"
+: "${SHIRUDO_TEST_RESULTS:?results that outlive the reboot are required}"
+[ -x /run/shirudo/runtime/usr/bin/shirudo-image-fault ] ||
+ test_skip_all "the runtime image has no fault helper"
+work=$SHIRUDO_TEST_RESULTS/revocation-archive
+mkdir -p "$work"
+export SHIRUDO_BIN SHIRUDO_TEST_KEY_FIXTURES SHIRUDO_TEST_FIXTURES_DIR
+py=functional/image-reboot/t5107-verity-revocation-archive.py
+
+case ${SHIRUDO_TEST_BOOT:-1} in
+1)
+ test_expect_success 'a loaded upatch has its archive cut short' '
+ python3 "$py" tear "$work"
+ '
+ test_expect_success 'a live revocation refuses the archive and changes nothing' '
+ python3 "$py" live "$work"
+ '
+ ;;
+2)
+ test_expect_success 'the boot that revokes goes on past the archive' '
+ python3 "$py" booted "$work"
+ '
+ test_expect_success 'status and the keepalive show a loaded set without the upatch' '
+ python3 "$py" reported "$work"
+ '
+ test_expect_success 'a live revocation still refuses the archive after the boot' '
+ python3 "$py" live-again "$work"
+ '
+ ;;
+*)
+ test_expect_success 'the test knows the boot it runs in' 'false'
+ ;;
+esac
+test_done
diff --git a/testing/helper/image-fault.c b/testing/helper/image-fault.c
index 1e3a8162..cb591874 100644
--- a/testing/helper/image-fault.c
+++ b/testing/helper/image-fault.c
@@ -3,6 +3,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <linux/fs.h>
#include <stdio.h>
#include <string.h>
@@ -193,14 +194,41 @@ done:
return ret ? 1 : 0;
}
+/* Shorter than a .upatch header, as a torn write leaves an archive. */
+#define ARCHIVE_TORN_SIZE 16
+
+/*
+ * The seal lets only a task of the runtime image change an archive, which
+ * this helper is.
+ */
+static int archive_truncate(const char *name)
+{
+ char path[PATH_MAX];
+ int len;
+
+ len = snprintf(path, sizeof(path), "%s/%s.upatch", UPATCHES_DIR, name);
+ if (strchr(name, '/') || len < 0 || (size_t)len >= sizeof(path))
+ return 2;
+ if (truncate(path, ARCHIVE_TORN_SIZE)) {
+ fprintf(stderr, "archive truncate: %s: %s\n", path,
+ strerror(errno));
+ return 1;
+ }
+ return 0;
+}
+
int __wrap_main(int argc, const char **argv)
{
if (argc == 4 && !strcmp(argv[1], "config-root"))
return config_root_test(argv[2], argv[3]);
+ if (argc == 3 && !strcmp(argv[1], "archive-truncate"))
+ return archive_truncate(argv[2]);
if (argc != 4 || strcmp(argv[1], "image") ||
strcmp(argv[2], "update")) {
fprintf(stderr, "usage: shirudo-image-fault "
- "image update <prefix>\n");
+ "image update <prefix>\n"
+ " shirudo-image-fault "
+ "archive-truncate <upatch>\n");
return 2;
}
return __real_main(argc, argv);