Artemis genesis stamp: fix a BAM-corrupting offset before it ever ran (FABRIC-3.md §XXVI follow-on, Step 3)
Step 3: one-time artemis_sig_t genesis stamp, written once
kernel_main.c's virtio-blk path confirms Artemis's own disk, so the disk
image is later recognizable generically (repl.c's idle-loop USB-MSC scan,
built in the prior commit) regardless of which bus found it.
Correction made before this ever touched the real disk: the signature's
first design (committed in 29b6789) placed it at a fixed bottom-of-device
forth-block (4, devblock 1) -- copying homeblocks_sig_t's own convention,
which is safe for a raw identity thumbdrive but not for Artemis's own
disk. Artemis's disk is block_subsystem.c's own STFR/v2-formatted volume:
devblock 0 holds that format's header and devblock 1 is the FIRST
DEVBLOCK OF THE LIVE BAM (blk_compute_fresh_geometry(): bam_start = 1).
The original design would have overwritten Artemis's live allocation map
on the very first real boot. Caught via direct cross-reference against
block_subsystem.c before the genesis-stamp call site was ever run against
the real image -- no corruption occurred.
Fixed by moving the header to a fixed offset from the END of the device
instead (ARTEMIS_SIG_DEVBLOCK_FROM_TOP=64), the same top-of-device region
block_subsystem.c's own meta_fence_blocks reservation (128 devblocks)
already carves out for system metadata, and where Zuse's genesis marker/
eligibility list already live -- but computed independently via
blkio_info() rather than through blk_meta_zone_*(), since that accessor
needs an already-attached, format-detected slot, which is exactly the
state pre-attach generic discovery doesn't have yet. Picked well clear of
Zuse's two tenants (devblock_from_top 0 and 1+, open-ended) so the two
subsystems' independent math can never collide.
Also reordered kernel_main.c: rng_init() now runs before the Artemis
virtio-blk block (was after) -- the genesis stamp needs rng_get_bytes()
for disk_uuid, and the original order would have failed the stamp on
every boot.
Verified live: booted amd64 against the real disk/artemis.img twice --
first boot logs "Artemis: genesis signature stamped" (confirmed blank at
the target offset beforehand via a host-side read), second boot on the
now-stamped image logs no re-stamp (idempotent, CRC/read-back verified)
-- both boots and aarch64/riscv64 (against the same now-stamped image)
all still report "Artemis: 22998 data blocks" / "PASS: persist-read"
unchanged, confirming the BAM and data pool were never touched.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EXieurDfDSsDFdnSyusuWo
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
29b6789860
commit
61755fde78
@@ -63,6 +63,7 @@ EFI_RUNTIME_SERVICES *g_sk_runtime_services = NULL;
|
||||
#include "starkernel/capsule_loader.h"
|
||||
#include "starkernel/capsule_birth.h" /* capsule_birth_mama, capsule_find_mama_init */
|
||||
#include "starkernel/capsule_zuse_boot.h" /* capsule_zuse_boot_load_root_pubkey */
|
||||
#include "starkernel/artemis_sig.h" /* artemis_sig_check/genesis_stamp */
|
||||
#include "starkernel/kmalloc.h"
|
||||
#include "starkernel/repl.h"
|
||||
#include "starkernel/pci.h"
|
||||
@@ -589,6 +590,30 @@ static void kernel_main_deep(BootInfo *boot_info) {
|
||||
console_println("PCI: init...");
|
||||
pci_init(boot_info->acpi_table);
|
||||
|
||||
/* Phase 8: entropy. Real per-arch RNG doesn't cover all three
|
||||
* architectures (amd64 RDRAND, riscv64 Zkr, but aarch64 has neither in
|
||||
* QEMU's CPU models -- see vm_uuid.h's identical finding), so signing/
|
||||
* keygen entropy comes from the unified rng_get_bytes() layer, whose
|
||||
* v2.0.0 backend is the paravirtualized virtio-rng device. Unconditional
|
||||
* call site, same graceful-noop precedent as virtio_blk_find_artemis()
|
||||
* below -- boot proceeds either way, the device is only required once
|
||||
* something actually calls rng_get_bytes().
|
||||
*
|
||||
* FABRIC-3.md §XXVI follow-on, 2026-09-13: moved ahead of the Artemis
|
||||
* virtio-blk block below (was after it) -- artemis_sig_genesis_stamp()
|
||||
* needs rng_get_bytes() for disk_uuid, and calling it before rng_init()
|
||||
* ran would have failed the stamp on every single boot forever. Both
|
||||
* calls only need pci_init() above; this reordering has no other
|
||||
* dependency either way. */
|
||||
{
|
||||
int rrc = rng_init();
|
||||
if (rrc == 0) {
|
||||
console_println("entropy: ready");
|
||||
} else {
|
||||
console_println("entropy: not available (continuing without)");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
static blkio_dev_t artemis_dev;
|
||||
int vrc = virtio_blk_find_artemis(&artemis_dev);
|
||||
@@ -603,28 +628,40 @@ static void kernel_main_deep(BootInfo *boot_info) {
|
||||
* capsule_zuse_boot_load_root_pubkey()'s own doc comment for
|
||||
* why this is safe and separate from her live-session cert. */
|
||||
capsule_zuse_boot_load_root_pubkey((VM *)mama_vm);
|
||||
|
||||
/* FABRIC-3.md §XXVI follow-on, 2026-09-13: one-time
|
||||
* artemis_sig_t genesis stamp, so this exact disk image can
|
||||
* later be recognized generically (by content, not by which
|
||||
* bus/vendor-ID scan happened to find it -- see repl.c's own
|
||||
* idle-loop USB-MSC discovery, the reason this signature
|
||||
* format exists at all). Safe to attempt unconditionally
|
||||
* every boot: virtio_blk_find_artemis() only ever succeeds
|
||||
* against the one dedicated PCI device, so a BLANK read here
|
||||
* unambiguously means "never stamped," not "might be some
|
||||
* other blank drive" -- and artemis_sig_check() returning
|
||||
* anything other than BLANK (already stamped, or a version/
|
||||
* CRC mismatch worth leaving alone rather than overwriting)
|
||||
* skips the stamp. See artemis_sig.h's own doc comment for why
|
||||
* this lands at a fence-relative top-of-device offset now,
|
||||
* not a fixed bottom-of-device forth-block (that first attempt
|
||||
* would have overwritten Artemis's own live BAM -- caught
|
||||
* before ever being run against the real disk). */
|
||||
{
|
||||
artemis_sig_t asig;
|
||||
artemis_sig_result_t art_rc = artemis_sig_check(&artemis_dev, &asig);
|
||||
if (art_rc == ARTEMIS_SIG_BLANK) {
|
||||
if (artemis_sig_genesis_stamp(&artemis_dev) == 0) {
|
||||
console_println("Artemis: genesis signature stamped");
|
||||
} else {
|
||||
console_println("Artemis: genesis signature stamp FAILED");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console_println("Artemis: no virtio-blk disk (continuing without)");
|
||||
}
|
||||
}
|
||||
|
||||
/* Phase 8: entropy. Real per-arch RNG doesn't cover all three
|
||||
* architectures (amd64 RDRAND, riscv64 Zkr, but aarch64 has neither in
|
||||
* QEMU's CPU models -- see vm_uuid.h's identical finding), so signing/
|
||||
* keygen entropy comes from the unified rng_get_bytes() layer, whose
|
||||
* v2.0.0 backend is the paravirtualized virtio-rng device. Unconditional
|
||||
* call site, same graceful-noop precedent as virtio_blk_find_artemis()
|
||||
* above -- boot proceeds either way, the device is only required once
|
||||
* something actually calls rng_get_bytes(). */
|
||||
{
|
||||
int rrc = rng_init();
|
||||
if (rrc == 0) {
|
||||
console_println("entropy: ready");
|
||||
} else {
|
||||
console_println("entropy: not available (continuing without)");
|
||||
}
|
||||
}
|
||||
|
||||
/* Zuse identity: SUPERSEDED 2026-08-28 (FABRIC-2.md §F.20/§F.21).
|
||||
* The one-shot block-fence mint-or-load that used to run here is
|
||||
* gone -- Zuse is thumbdrive-resident now (her seed never touches
|
||||
|
||||
Reference in New Issue
Block a user