capsule trust: a signed kernel refuses an unsigned capsule; the intermediate is the anchor (#139)

capsule_sig_refused(), the one decision at v4's boot and v3's three
births: INVALID always; MISSING and NO_ROOT_KEY on a signed build
(CAPSULE_SIGNED_BUILD, set exactly when the Makefiles sign). A
developer build warns and boots. test_capsule_sig, built both ways,
did not build without it; 4 checks each way now. nightly.sh
capsule-trust, a nightly step: signed, v4:centre.4th left unsigned
(test only), amd64 must refuse it -- CI's, as ruled, since only CI has
the key. No root check, as ruled; the step-4 trust model (blobs signed
by their authors, MANIFEST.md hashes, contributors' intermediates,
snakeoil) recorded as given. FABRIC-3 XLIX. Gates pass, POST 992/992.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
Claude
2026-11-20 22:37:25 +00:00
parent 5425d52cb1
commit 9db364f7c7
20 changed files with 1750 additions and 11 deletions
+7 -1
View File
@@ -249,6 +249,11 @@ MKARTEMIS_BIN = $(BUILD_DIR)/tools/mkartemis
# which boots with a warning per capsule. mkcapsule refuses a key that is not the certificate's.
SIGN_KEY ?=
SIGN_KEY_ARGS = $(if $(wildcard $(SIGN_KEY)),--sign-key $(SIGN_KEY),)
# #139: a kernel whose capsules are signed refuses an unsigned one (capsule_sig.h)
CAPSULE_SIGNED_DEF = $(if $(wildcard $(SIGN_KEY)),-DCAPSULE_SIGNED_BUILD=1,)
# For the test only (#139, scripts/qemu_session.py unsigned_capsule): a signed build with this one capsule's
# signature taken out after mkcapsule, which the kernel must refuse. Never set for a build that ships.
CAPSULE_TEST_UNSIGN ?=
CAPSULE_GENERATED = $(BUILD_DIR)/capsule_generated.c
CAPSULE_GENERATED_OBJ = $(BUILD_DIR)/capsule_generated.o
CAPSULE_GENERATED_KOBJ = $(KERNEL_OBJ_DIR)/capsule_generated.o
@@ -435,7 +440,7 @@ DOE_SEED ?= 12345
# production default (Kconfig.heartbeat's own default n, same decision).
$(eval $(call kconfig_bool,EMERGENCY_CONSOLE_ENABLED,0))
LOADER_CFLAGS := $(LOADER_BASE_CFLAGS) -I$(KERNEL_SRC)/vm
KERNEL_CFLAGS := $(COMMON_CFLAGS) -D__STARKERNEL__ -I$(KERNEL_SRC)/vm
KERNEL_CFLAGS := $(COMMON_CFLAGS) -D__STARKERNEL__ -I$(KERNEL_SRC)/vm $(CAPSULE_SIGNED_DEF)
# Linker flags
ifeq ($(ARCH),aarch64)
@@ -859,6 +864,7 @@ $(CAPSULE_GENERATED): $(MKCAPSULE_BIN) $(CAPSULE_SRCS)
@mkdir -p $(dir $@)
@echo " MKCAP $(CAPSULES_DIR) -> $@"
@$(MKCAPSULE_BIN) $(SIGN_KEY_ARGS) $(CAPSULES_DIR) $@
@$(if $(CAPSULE_TEST_UNSIGN),python3 scripts/capsule_unsign.py $@ $(CAPSULE_TEST_UNSIGN),:)
@echo " MKCAP $(CAPSULES_DIR) -> $(CAPSULES_DIR)/BLOCK_MAP.md"
@$(MKCAPSULE_BIN) --manifest $(SIGN_KEY_ARGS) $(CAPSULES_DIR) $(CAPSULES_DIR)/BLOCK_MAP.md
+18
View File
@@ -8,6 +8,14 @@
* signature/behavior stays untouched; this is a new, additive check
* called alongside it, not folded into it.
*
* Which results are refused is capsule_sig_refused()'s, the one decision every caller asks (#139,
* docs/v4.0.0/plans/2026-11-20-capsule-trust.md, ruled 2026-11-20): INVALID on every build; MISSING
* and NO_ROOT_KEY as well on a signed build (CAPSULE_SIGNED_BUILD 1, set by kernel/Makefile and
* v4/Makefile exactly when they sign the capsules). A developer build, without the key, warns of them
* and boots. The anchor is the signing certificate in the image (FABRIC-3 XLVI): it is not checked
* against the root CA (ruled 2026-11-20). Corrected 2026-11-20: until then, as below, only INVALID
* was refused on any build.
*
* Enforced ONLY on CAPSULE_SIG_INVALID (2026-08-26, after landing
* WARN-only and proving correct on all three architectures against both
* a valid and a deliberately-corrupted capsule -- see FABRIC-2.md's
@@ -31,6 +39,12 @@
* mkcapsule refuses to sign with a key that is not this certificate's. */
#define CAPSULE_SIGNING_CERT_NAME "pki:starshipos-intermediate.der"
/* 1 when the kernel is built with the signing key (kernel/Makefile, v4/Makefile): its capsules are
* signed, so an unsigned one, or no certificate to check by, is refused (#139). */
#ifndef CAPSULE_SIGNED_BUILD
#define CAPSULE_SIGNED_BUILD 0
#endif
typedef enum {
CAPSULE_SIG_OK = 0, /* has_sig=1, and it verifies */
CAPSULE_SIG_MISSING, /* has_sig=0 -- not signed at all */
@@ -58,4 +72,8 @@ CapsuleSigResult capsule_verify_signature(
* capsule_validate_result_str()'s existing shape. */
const char *capsule_sig_result_str(CapsuleSigResult result);
/* 1 if a capsule with this result is refused (#139): INVALID always; MISSING and NO_ROOT_KEY on a
* signed build (CAPSULE_SIGNED_BUILD). Every caller asks this rather than testing a result itself. */
int capsule_sig_refused(CapsuleSigResult result);
#endif /* STARKERNEL_CAPSULE_SIG_H */
+3 -3
View File
@@ -593,7 +593,7 @@ CapsuleRunResult capsule_birth_mama(
if (sr != CAPSULE_SIG_OK) {
log_message(LOG_WARN, "capsule sig: %s: %s",
names[idx].name, capsule_sig_result_str(sr));
if (sr == CAPSULE_SIG_INVALID) return CAPSULE_RUN_ERR_INVALID;
if (capsule_sig_refused(sr)) return CAPSULE_RUN_ERR_INVALID;
}
}
@@ -674,7 +674,7 @@ CapsuleRunResult capsule_birth_baby(
if (sr != CAPSULE_SIG_OK) {
log_message(LOG_WARN, "capsule sig: %s: %s",
names[idx].name, capsule_sig_result_str(sr));
if (sr == CAPSULE_SIG_INVALID) return CAPSULE_RUN_ERR_INVALID;
if (capsule_sig_refused(sr)) return CAPSULE_RUN_ERR_INVALID;
}
/* FABRIC-2.md §I.5: contrib trust tier -- see contrib_capsule_
* refused()'s own doc comment. */
@@ -940,7 +940,7 @@ CapsuleRunResult capsule_run_experiment(
if (sr != CAPSULE_SIG_OK) {
log_message(LOG_WARN, "capsule sig: %s: %s",
names[idx].name, capsule_sig_result_str(sr));
if (sr == CAPSULE_SIG_INVALID) return CAPSULE_RUN_ERR_INVALID;
if (capsule_sig_refused(sr)) return CAPSULE_RUN_ERR_INVALID;
}
/* FABRIC-2.md §I.5: contrib trust tier -- see contrib_capsule_
* refused()'s own doc comment. */
+11
View File
@@ -67,3 +67,14 @@ const char *capsule_sig_result_str(CapsuleSigResult result) {
default: return "unknown";
}
}
int capsule_sig_refused(CapsuleSigResult result)
{
switch (result) {
case CAPSULE_SIG_OK: return 0;
case CAPSULE_SIG_INVALID: return 1;
case CAPSULE_SIG_MISSING:
case CAPSULE_SIG_NO_ROOT_KEY: return CAPSULE_SIGNED_BUILD;
}
return 1; /* not a result this code knows: refused */
}
+5 -1
View File
@@ -19,7 +19,7 @@ CC ?= cc
CFLAGS := -std=c99 -Wall -Wextra -Werror -O2 -g -I$(HERE) -I$(ROOT)/kernel/include \
-I$(ROOT)/kernel/include/starkernel -I$(ROOT)/v3/include
TESTS := test_heartbeat test_gpt test_usb_config test_sk_v4_stop test_sk_v4_slots test_sk_v4_mint test_sk_v4_identity test_heartbeat_export test_ssm_jacquard test_physics_l2 test_stadium_node test_stadium_ops test_stadium_words
TESTS := test_capsule_sig test_capsule_sig_signed test_heartbeat test_gpt test_usb_config test_sk_v4_stop test_sk_v4_slots test_sk_v4_mint test_sk_v4_identity test_heartbeat_export test_ssm_jacquard test_physics_l2 test_stadium_node test_stadium_ops test_stadium_words
# the one adaptive heartbeat paces itself (plan 2026-11-17-one-adaptive-heartbeat): heartbeat.c, its Q48.16, and the
# v4 inference arithmetic its slope provider runs
SRC_test_heartbeat := $(ROOT)/kernel/src/heartbeat.c $(ROOT)/kernel/src/math/q48_16.c $(ROOT)/v4/system/inference.c
@@ -40,6 +40,10 @@ EXTRA_test_sk_v4_mint := -D__STARKERNEL__ -I$(ROOT)/v4/include
SRC_test_sk_v4_slots := $(ROOT)/kernel/src/v4/sk_v4_slots.c
SRC_test_sk_v4_stop := $(ROOT)/kernel/src/v4/sk_v4_stop.c
SRC_test_gpt := $(ROOT)/kernel/src/gpt.c
# #139: the signature results the kernel refuses, on a developer build and a signed one
SRC_test_capsule_sig := $(ROOT)/kernel/src/capsule/capsule_sig.c $(addprefix $(ROOT)/kernel/src/crypto/,x509_ed25519.c ed25519.c fe25519.c scalar25519.c sha512.c)
SRC_test_capsule_sig_signed := $(SRC_test_capsule_sig)
EXTRA_test_capsule_sig_signed := -DCAPSULE_SIGNED_BUILD=1
SRC_test_usb_config := $(ROOT)/kernel/src/usb/usb_config.c
define TEST_RULE
+27
View File
@@ -0,0 +1,27 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* test_capsule_sig.c -- which capsule signature results the kernel refuses (#139;
* docs/v4.0.0/plans/2026-11-20-capsule-trust.md, ruled 2026-11-20): capsule_sig_refused(), the one
* decision every caller asks. INVALID is refused on every build. A signed build (built with the
* signing key, CAPSULE_SIGNED_BUILD 1) also refuses MISSING and NO_ROOT_KEY; a build without the key
* warns of them and boots. Built twice: as here, unsigned, and as test_capsule_sig_signed.c.
*/
#include "harness.h"
#include "starkernel/capsule_sig.h"
#ifndef CAPSULE_SIGNED_BUILD
#define CAPSULE_SIGNED_BUILD 0
#endif
int main(void)
{
printf("capsule_sig_refused, a %s build\n", CAPSULE_SIGNED_BUILD ? "signed" : "developer (unsigned)");
CHECK(!capsule_sig_refused(CAPSULE_SIG_OK), "a good signature is never refused");
CHECK(capsule_sig_refused(CAPSULE_SIG_INVALID), "a signature that does not verify is always refused");
CHECK(capsule_sig_refused(CAPSULE_SIG_MISSING) == CAPSULE_SIGNED_BUILD,
"an unsigned capsule: refused on a signed build, warned of on a developer build");
CHECK(capsule_sig_refused(CAPSULE_SIG_NO_ROOT_KEY) == CAPSULE_SIGNED_BUILD,
"no signing certificate to check by: refused on a signed build, warned of on a developer build");
return DONE();
}
+6
View File
@@ -0,0 +1,6 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* test_capsule_sig_signed.c -- test_capsule_sig.c on a signed build (CAPSULE_SIGNED_BUILD 1, from the
* Makefile's EXTRA, as the kernel's build sets it with the signing key). */
#include "test_capsule_sig.c"