code wiki / (root) / nx_lysis.nx

nx_lysis.nx source

↩ module page · 295 lines · 12890 B

1// nx_lysis.nx -- selective foreign-entity neutralization. 2// 3// Per [[feedback-unified-immune-architecture-three-tier]] item 3: 4// the user's specific question: "take how would you combat and 5// deactivate nano bots as if they were viruses or stuff like that, 6// would a giant magnet work or what is the equivalent that would 7// purge but not hurt the host think of the mechanisms of anti 8// parasites on things like ivermectin or whatever." 9// 10// THE UNIVERSAL PRINCIPLE: selective targeting via host-threat 11// biochemical/physical/electromagnetic/structural differences. 12// Ivermectin works because parasite ion channels differ from 13// mammalian; magnetic-particle hyperthermia works because 14// ferromagnetic threats heat in alternating fields while diamagnetic 15// tissue does not; chelation works because EDTA binds heavy metals 16// preferentially. 17// 18// SOFTWARE SUBSTRATE EQUIVALENT: neutralize the foreign entity by 19// exploiting a difference between FOREIGN and HOST that the host can 20// tolerate. We have several such differences available -- foreign 21// processes lack the substrate's capability tokens, foreign memory 22// pages lack the chromatin chain, foreign egress targets aren't on 23// the substrate's allowlist. Each difference = an attack vector 24// against the foreign entity that costs the host nothing. 25// 26// Mechanism catalog shipped V1 (each = one host-tolerant difference 27// the substrate can exploit): 28// CAPABILITY_REVOKE -- drop the brane capability tokens; foreign 29// loses access without affecting self 30// MEMORY_ZERO -- overwrite foreign memory region with zeros 31// (caller has already isolated the region) 32// NETWORK_BLACKHOLE -- route foreign egress to /dev/null; host 33// egress on other interfaces unaffected 34// PROCESS_PAUSE -- SIGSTOP foreign process (reversible; gathers 35// evidence while frozen) 36// PROCESS_TERMINATE -- SIGKILL foreign process (irreversible) 37// QUARANTINE -- isolate-but-preserve (no kill, no read, 38// operator review gates next step) 39// CRYPTO_REKEY -- rotate the substrate's master keys; any 40// foreign cached credentials become useless 41// PEER_MESH_EVICT -- publish "this peer is hostile" so other 42// Nishi nodes refuse the foreign entity 43// DECOY_PROMOTE -- replace the real asset with a decoy and let 44// the foreign entity continue reading garbage 45// 46// Selector picks based on: 47// - threat severity (PAMP confidence + intrusion_state) 48// - reversibility budget (operator may want evidence preserved) 49// - host-tolerance (does this mechanism harm legitimate workloads?) 50// 51// Per [[feedback-captain-moroni-doctrine]]: lysis is DEFENSIVE. 52// Never offensive. Never harm host. Never persist beyond the 53// duration the threat persists. Captain Moroni: minimum force. 54// 55// Composes: 56// nx_xenocell -- target of lysis (foreign-self) 57// nx_pamp -- detection severity informs mechanism choice 58// nx_crispr -- threat history informs lysis aggressiveness 59// nx_restriction -- IO-boundary refusal can recommend lysis 60// nx_abortive -- self-cell abortive composes with foreign-lysis 61// when the cell was COMPROMISED by foreign action 62// nx_evict_journal -- every lysis event logged loudly 63// 64// V1 ships sealed-enum mechanism catalog + selector function + 65// host-tolerance predicates. Actual SIGSTOP/SIGKILL wiring lives in 66// the integration layer (Linux signal sender, Windows 67// TerminateProcess); this primitive emits the INTENT. 68// 69// Gap list (V1 honest perf verdict): 70// - intent verbs only; OS wiring is integration layer's job 71// - no per-niche policy (a gameplay cell has different tolerance 72// than a financial cell; V2 makes selector niche-aware) 73// - severity heuristic is coarse (just three buckets); V2 uses 74// continuous Q10 confidence 75// - no automatic rollback if lysis turns out to be false-positive 76// (operator review during quarantine is the V1 safety) 77// 78// genealogy_id: cardinal_2026-05-19_unified_immune_architecture + 79// cardinal_2026-05-07_captain_moroni_doctrine + 80// biology_complement_mediated_lysis + clinical_ivermectin 81// lineage_id: substrate_lysis_v1 82// 83// nx_safety_envelope: 84// intended_use: "Selective foreign-entity neutralization 85// via host-tolerant mechanisms; DEFENSIVE, 86// minimum force, host-tolerance enforced" 87// sil_target: SIL3 88// evidence: [host_tolerance_per_mechanism_verified, 89// captain_moroni_minimum_force_aligned, 90// no_offensive_path] 91// hazard_register: [bug-tape-lysis-harms-legitimate-workload, 92// bug-tape-lysis-fires-on-false-positive] 93// verdict: NOT_YET_EVALUATED 94 95import "nx_syscalls.nx" 96import "nx_tier.nx" 97import "nx_budget.nx" 98import "nx_attention_class.nx" 99import "nx_evict_journal.nx" 100 101// ===== Sealed enum: NxLysisMechanism ============================== 102 103const NX_LYSIS_NONE: nx_int = 0 104const NX_LYSIS_CAPABILITY_REVOKE: nx_int = 1 105const NX_LYSIS_MEMORY_ZERO: nx_int = 2 106const NX_LYSIS_NETWORK_BLACKHOLE: nx_int = 3 107const NX_LYSIS_PROCESS_PAUSE: nx_int = 4 108const NX_LYSIS_PROCESS_TERMINATE: nx_int = 5 109const NX_LYSIS_QUARANTINE: nx_int = 6 110const NX_LYSIS_CRYPTO_REKEY: nx_int = 7 111const NX_LYSIS_PEER_MESH_EVICT: nx_int = 8 112const NX_LYSIS_DECOY_PROMOTE: nx_int = 9 113const NX_LYSIS_N_MECHANISMS: nx_int = 10 114 115// ===== Sealed enum: NxLysisSeverity =============================== 116// 117// Coarse three-bucket severity. V2 uses continuous Q10 confidence. 118 119const NX_LYSIS_SEV_LOW: nx_int = 0 // suspect; quarantine + observe 120const NX_LYSIS_SEV_MED: nx_int = 1 // confirmed probing; revoke caps 121const NX_LYSIS_SEV_HIGH: nx_int = 2 // active compromise; pause/kill 122const NX_LYSIS_N_SEVS: nx_int = 3 123 124// ===== Sealed enum: NxLysisVerdict ================================ 125 126const NX_LYSIS_OK: nx_int = 0 127const NX_LYSIS_ERR_BAD_MECHANISM: nx_int = 1 128const NX_LYSIS_ERR_BAD_SEVERITY: nx_int = 2 129const NX_LYSIS_ERR_HOST_INTOLERANT: nx_int = 3 // mechanism would harm host 130const NX_LYSIS_ERR_OPERATOR_GATED: nx_int = 4 // requires twin-key 131 132// ===== Struct: NxLysisAction ====================================== 133// 134// One emitted lysis intent. target_id is the cell_id or pid of the 135// foreign-self to neutralize. mechanism is which of the catalog 136// applies. ts_us + reason chain into nx_evict_journal for forensics. 137 138struct NxLysisAction { 139 target_id: nx_int, 140 mechanism: nx_int, 141 severity: nx_int, 142 ts_us: nx_size, 143 reversible: nx_int, // 1 = can be undone; 0 = permanent 144 operator_gated: nx_int, // 1 = requires twin-key approval 145} 146 147// ===== Validators ================================================ 148 149func nx_lysis_mechanism_is_valid(m: nx_int) -> nx_int { 150 if m < 0 { return 0 } 151 if m >= NX_LYSIS_N_MECHANISMS { return 0 } 152 return 1 153} 154 155func nx_lysis_severity_is_valid(s: nx_int) -> nx_int { 156 if s < 0 { return 0 } 157 if s >= NX_LYSIS_N_SEVS { return 0 } 158 return 1 159} 160 161// ===== nx_lysis_is_reversible ===================================== 162// 163// Which mechanisms can be undone? Operator may prefer reversible 164// mechanisms during evidence-gathering phase. Per Captain Moroni 165// minimum-force: prefer reversible until threat is HIGH severity. 166 167func nx_lysis_is_reversible(m: nx_int) -> nx_int { 168 if m == NX_LYSIS_CAPABILITY_REVOKE { return 1 } // can re-grant 169 if m == NX_LYSIS_PROCESS_PAUSE { return 1 } // SIGCONT 170 if m == NX_LYSIS_QUARANTINE { return 1 } // release later 171 if m == NX_LYSIS_NETWORK_BLACKHOLE { return 1 } // remove route 172 if m == NX_LYSIS_DECOY_PROMOTE { return 1 } // restore real 173 return 0 174} 175 176// ===== nx_lysis_is_host_tolerant ================================== 177// 178// Does this mechanism leave LEGITIMATE host workloads unaffected? 179// CRYPTO_REKEY for example MAY disrupt host-side cached connections 180// for a moment -- not strictly tolerant. The selector uses this to 181// score mechanism choices. 182 183func nx_lysis_is_host_tolerant(m: nx_int) -> nx_int { 184 if m == NX_LYSIS_CAPABILITY_REVOKE { return 1 } 185 if m == NX_LYSIS_MEMORY_ZERO { return 1 } // caller isolated 186 if m == NX_LYSIS_NETWORK_BLACKHOLE { return 1 } // target-specific route 187 if m == NX_LYSIS_PROCESS_PAUSE { return 1 } 188 if m == NX_LYSIS_PROCESS_TERMINATE { return 1 } // target-specific 189 if m == NX_LYSIS_QUARANTINE { return 1 } 190 if m == NX_LYSIS_CRYPTO_REKEY { return 0 } // brief host disruption 191 if m == NX_LYSIS_PEER_MESH_EVICT { return 1 } 192 if m == NX_LYSIS_DECOY_PROMOTE { return 1 } 193 return 1 194} 195 196// ===== nx_lysis_requires_operator ================================= 197// 198// Per Captain Moroni twin-key cardinal: irreversible high-force 199// actions require operator (or twin-key) authorization. 200// PROCESS_TERMINATE and CRYPTO_REKEY are gated; reversible 201// mechanisms are not. 202 203func nx_lysis_requires_operator(m: nx_int) -> nx_int { 204 if m == NX_LYSIS_PROCESS_TERMINATE { return 1 } 205 if m == NX_LYSIS_CRYPTO_REKEY { return 1 } 206 if m == NX_LYSIS_PEER_MESH_EVICT { return 1 } 207 return 0 208} 209 210// ===== nx_lysis_select ============================================ 211// 212// Pick mechanism based on severity + caller's reversibility budget. 213// Returns NX_LYSIS_NONE if no mechanism fits; otherwise the chosen 214// NX_LYSIS_* constant. 215// 216// Selector rules per Captain Moroni minimum-force: 217// LOW severity -> QUARANTINE (observe, preserve evidence) 218// MED severity -> CAPABILITY_REVOKE (drop access; reversible) 219// MED + network-active -> NETWORK_BLACKHOLE 220// HIGH severity -> PROCESS_PAUSE (freeze for evidence) 221// HIGH + persistent -> PROCESS_TERMINATE (operator-gated) 222// HIGH + key-leak -> CRYPTO_REKEY + caps revoke 223// reversible_only=1 -> never pick TERMINATE or CRYPTO_REKEY 224 225func nx_lysis_select(severity: nx_int, 226 network_active: nx_int, 227 persistent: nx_int, 228 key_leak: nx_int, 229 reversible_only: nx_int) -> nx_int { 230 if nx_lysis_severity_is_valid(severity) == 0 { return NX_LYSIS_NONE } 231 232 if severity == NX_LYSIS_SEV_LOW { 233 return NX_LYSIS_QUARANTINE 234 } 235 236 if severity == NX_LYSIS_SEV_MED { 237 if network_active == 1 { return NX_LYSIS_NETWORK_BLACKHOLE } 238 return NX_LYSIS_CAPABILITY_REVOKE 239 } 240 241 // SEV_HIGH 242 if key_leak == 1 { 243 if reversible_only == 1 { return NX_LYSIS_CAPABILITY_REVOKE } 244 return NX_LYSIS_CRYPTO_REKEY 245 } 246 if persistent == 1 { 247 if reversible_only == 1 { return NX_LYSIS_PROCESS_PAUSE } 248 return NX_LYSIS_PROCESS_TERMINATE 249 } 250 return NX_LYSIS_PROCESS_PAUSE 251} 252 253// ===== nx_lysis_emit ============================================== 254// 255// Construct a lysis action. Caller emits this; integration layer 256// reads and dispatches the corresponding OS call. Returns NULL if 257// the mechanism is invalid or host-intolerant when caller required 258// host-tolerant only. 259 260func nx_lysis_emit(target_id: nx_int, 261 mechanism: nx_int, 262 severity: nx_int, 263 ts_us: nx_size, 264 require_host_tolerant: nx_int) -> *NxLysisAction { 265 if nx_lysis_mechanism_is_valid(mechanism) == 0 { return (0 as i64) as *NxLysisAction } 266 if nx_lysis_severity_is_valid(severity) == 0 { return (0 as i64) as *NxLysisAction } 267 if require_host_tolerant == 1 { 268 if nx_lysis_is_host_tolerant(mechanism) == 0 { return (0 as i64) as *NxLysisAction } 269 } 270 let a: *NxLysisAction = (sys_mmap(48)) as *NxLysisAction 271 a.target_id = target_id 272 a.mechanism = mechanism 273 a.severity = severity 274 a.ts_us = ts_us 275 a.reversible = nx_lysis_is_reversible(mechanism) 276 a.operator_gated = nx_lysis_requires_operator(mechanism) 277 return a 278} 279 280// ===== nx_lysis_log =============================================== 281// 282// Append a lysis-event row to the eviction journal. Every lysis 283// event is logged loudly per Captain Moroni transparency discipline. 284 285func nx_lysis_log(action: *NxLysisAction, 286 j: *NxEvictJournal, 287 attention_class: nx_int, 288 displaced_by: nx_int) -> nx_int { 289 if (action as i64) == 0 { return NX_LYSIS_ERR_BAD_MECHANISM } 290 if (j as i64) == 0 { return NX_LYSIS_OK } // no journal supplied; OK to silent 291 nx_evict_log(j, action.ts_us, action.target_id, 292 NX_EVR_TERMINATED, NX_RES_CPU, 293 attention_class, displaced_by) 294 return NX_LYSIS_OK 295}