Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/kernel/svc/continuity_recovery.h # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / kernel / svc / continuity_recovery.h` 172 lines ยท 8644 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* continuity_recovery.h -- C port, cut 5: the Recovery Core over the sealed 18 * Store: read-only inspection, entry reasons, the one action each state admits, 19 * and the operator-authorised actions (contract section 4, INV-13..INV-18, 20 * MR-1..MR-9, K-3/K-4 notes). 21 * 22 * Contract: native/kernel/CONTINUITY_RECOVERY_CONTRACT.md. Oracle: the Rust 23 * kernel crates/aienos-kernel/src/recovery_core.rs (`inspect` :107-187, 24 * `applicable` :79-90, `challenge` :94-104, `repair_degraded_peer` :244-257, 25 * `provision_identity` :262-273). 26 * 27 * No model, no network, no clock. Inspection NEVER writes (INV-13): it reads 28 * units 0 and 1 of the Store region and opens the sealed Store, which does not 29 * write. Every write is an explicit operator action; each one re-inspects, requires 30 * rc_applicable() == action (else RC_NOT_APPLICABLE), then a verifying operator 31 * response (else RC_UNAUTHORISED), and only then writes (INV-16). 32 * 33 * The operator key is a parameter. The TEST-only key of the Rust qualification 34 * (0x0f x 32) is the caller's business; this file contains no key. 35 * 36 * Status: host PASS over the real sealed Store in a file. Not wired into the 37 * kernel; no QEMU run (M4_RECOVERY stays NOT_RUN). */ 38 #ifndef CK_CONTINUITY_RECOVERY_H 39 #define CK_CONTINUITY_RECOVERY_H 40 41 #include 42 #include 43 44 #include "continuity_commit.h" 45 #include "continuity_resolve_sealed.h" 46 47 /* TEST-only mutants for the host mutation run (Makefile continuity-mutants). 48 * MR-1 inspection writes (repairs on inspect), MR-5 applicable() treats a 49 * degraded mount as Unprovisioned (the `fe2c2bd` bug), MR-6 repair zeroes the 50 * active slot, MR-7 repair offered without a resolved identity, MR-9 operator 51 * provisioning writes source Qualification. */ 52 #if defined(CK_HARDWARE_STAGING) && \ 53 (defined(RC_MUTANT_INSPECT_WRITES) || defined(RC_MUTANT_DEGRADED_IS_UNPROVISIONED) || \ 54 defined(RC_MUTANT_REPAIR_ACTIVE) || defined(RC_MUTANT_REPAIR_NO_IDENTITY) || \ 55 defined(RC_MUTANT_PROVISION_QUALIFICATION)) 56 #error "continuity recovery mutants are TEST-only and refused under CK_HARDWARE_STAGING" 57 #endif 58 59 /* What one superblock slot holds (SlotView, recovery_core.rs:17-22). */ 60 enum { RC_SLOT_ZERO = 0, RC_SLOT_SUPERBLOCK = 1, RC_SLOT_UNDECODABLE = 2, RC_SLOT_READ_ERROR = 3 }; 61 62 /* Why the Recovery Core was entered (EntryReason, recovery_core.rs:25-33). 63 * RC_REASON_NONE: a normal boot may proceed. 64 * RC_SEALED_REFUSAL is C only (contract K-3/K-4): the sealed mount (keyed proof, 65 * anti-rollback anchor, envelope or transaction record) refused before continuity 66 * could run. It admits no action (INV-15). */ 67 enum { 68 RC_REASON_NONE = 0, 69 RC_STORE_UNFORMATTED, 70 RC_STORE_MOUNT, /* ST_M_* other than unformatted: record.mount_rc */ 71 RC_SEALED_REFUSAL, /* SS_E_*: record.mount_rc */ 72 RC_UNPROVISIONED, 73 RC_CONFLICT, 74 RC_CONTINUITY_CORRUPT, /* record.why */ 75 RC_DEGRADED, /* record.peer (ST_PEER_*) */ 76 }; 77 78 /* The read-only raw system record (SystemRecord, recovery_core.rs:61-73). */ 79 struct rc_record { 80 int slot[2]; /* RC_SLOT_* */ 81 uint64_t slot_generation[2]; /* valid when slot[i] == RC_SLOT_SUPERBLOCK */ 82 uint8_t state_digest[32]; /* SHA-256 over both raw units: binds challenges */ 83 int have_uuid; /* from the first decodable slot */ 84 uint8_t uuid[16]; 85 int have_mount; /* the sealed Store mounted */ 86 int mount_state; /* ST_VALID or ST_DEGRADED_RECOVERY */ 87 int peer; /* ST_PEER_* */ 88 uint64_t generation; 89 int reason; /* RC_* */ 90 int mount_rc; /* RC_STORE_MOUNT / RC_SEALED_REFUSAL: the error */ 91 const char *why; /* RC_CONTINUITY_CORRUPT: static text */ 92 int have_identity; /* continuity resolved (a view exists) */ 93 uint8_t agent_id[32]; 94 int have_catalog; 95 uint32_t n_roots, n_manifests, n_other; /* verified application objects (claims) */ 96 }; 97 98 /* Caller-owned environment. The Store is opened into `store` and stays open 99 * after rc_inspect (an action reuses it for provisioning). `view` receives the 100 * resolved continuity. */ 101 struct rc_env { 102 const st_dev *dev; /* Store region, 4096-byte units */ 103 const ts_device *anchor; /* anchor region device */ 104 uint64_t anchor_lba; 105 const ss_keys *keys; 106 ss_workspace *ws; 107 ss_store *store; 108 struct cr_work *w; 109 struct cr_txwork *tw; 110 struct cr_view *view; 111 }; 112 113 /* Inspect in place. Never writes (INV-13). Returns 0, or -1 for a NULL argument 114 * (record untouched). */ 115 int rc_inspect(const struct rc_env *e, struct rc_record *rec); 116 117 /* The action this state admits: CR_ACTION_REPAIR_DEGRADED_PEER, CR_ACTION_PROVISION_IDENTITY 118 * or 0 (INV-15). Fails toward preservation: 119 * - repair only a Malformed peer and only with a resolved identity (MR-7); 120 * - provision only on a Valid mount that reads Unprovisioned (MR-5): a degraded 121 * mount is never treated as unprovisioned; 122 * - everything else (sealed refusals, conflicts, corrupt continuity, unformatted 123 * stores, a CRC-valid newer root whose graph is broken) admits nothing. */ 124 int rc_applicable(const struct rc_record *rec); 125 126 /* Challenge for `action` on exactly this state (cr_challenge over the record's 127 * uuid, generation, action and state digest). 1 on success, 0 when the record 128 * has no uuid or no mount (recovery_core.rs:94-104). */ 129 int rc_challenge(const struct rc_record *rec, uint8_t action, uint8_t out[32]); 130 131 /* Action outcomes (RecoveryError, recovery_core.rs:199-207). */ 132 enum { 133 RC_OK = 0, 134 RC_NOT_APPLICABLE = 1, 135 RC_UNAUTHORISED = 2, 136 RC_IO = 3, 137 RC_CONTINUITY = 4, /* provisioning refused: *cr_outcome has the CR_* outcome */ 138 RC_E_ARG = 5, 139 }; 140 const char *rc_outcome_name(int rc); 141 142 /* Zero the INACTIVE superblock slot (1 - active, never the active one: MR-6) of 143 * a degraded store after the operator's response verifies, flush, re-inspect 144 * into *after (optional). Nothing is written unless authorisation passes. */ 145 int rc_repair_degraded_peer(const struct rc_env *e, const uint8_t operator_key[32], 146 const uint8_t response[32], struct rc_record *after); 147 148 /* Provision the one identity on a Valid, unprovisioned store after the 149 * operator's response verifies. Writes source Operator (INV-18, MR-9), with the 150 * Store uuid taken from the inspection. Entropy comes from rng (no fallback: 151 * cut 4). On RC_CONTINUITY, *cr_outcome, *why and *store_rc (all optional) say why. */ 152 int rc_provision_identity(const struct rc_env *e, const uint8_t operator_key[32], 153 const uint8_t response[32], struct ck_rng *rng, struct cr_view *out, 154 int *cr_outcome, const char **why, int *store_rc); 155 156 /* ---- serial markers (contract section 3; the Rust Debug spellings) ---- 157 * Write the NUL-terminated line, without newline; return its length, 0 when cap 158 * is too small. */ 159 const char *rc_peer_name(int peer); /* "Zero", "Valid", "Malformed", "GraphBadNewer", "GraphBadOlder" */ 160 /* "Degraded(Malformed)", "Unprovisioned", "ContinuityCorrupt(\"why\")", "StoreMount(rc)", 161 * "SealedRefusal(rc)" (C only), ... */ 162 size_t rc_reason_text(char *out, size_t cap, const struct rc_record *rec); 163 /* "RECOVERY_CORE: ENTERED reason=" or "RECOVERY_CORE: NOT_NEEDED". */ 164 size_t rc_marker_entry(char *out, size_t cap, const struct rc_record *rec); 165 /* "RECOVERY_CHALLENGE: action= challenge=<64 hex>" (0 when no challenge). */ 166 size_t rc_marker_challenge(char *out, size_t cap, const struct rc_record *rec, uint8_t action); 167 /* "RECOVERY_REFUSED ()>)". */ 168 size_t rc_marker_refused(char *out, size_t cap, int rc, int cr_outcome); 169 /* "RECOVERY_ACTION: DONE" (agent != NULL: " agent=<64 hex>"). */ 170 size_t rc_marker_done(char *out, size_t cap, uint8_t action, const uint8_t *agent); 171 172 #endif /* CK_CONTINUITY_RECOVERY_H */