nx_reclaim_test.nx source
↩ module page · 101 lines · 4598 B
1// nx_reclaim_test.nx -- smoke for nx_reclaim composed operation.
2
3import "nx_syscalls.nx"
4import "nx_tier.nx"
5import "nx_budget.nx"
6import "nx_attention_class.nx"
7import "nx_evict_journal.nx"
8import "nx_attest_silicon.nx"
9import "nx_xenocell.nx"
10import "nx_organism.nx"
11import "nx_reclaim.nx"
12
13func main() -> i64 {
14 // 1: niche enum sealed
15 if NX_NICHE_N_NICHES != 8 { return 1 }
16 if nx_niche_is_valid(NX_NICHE_GAMEPLAY) != 1 { return 2 }
17 if nx_niche_is_valid(NX_NICHE_FINANCIAL) != 1 { return 3 }
18 if nx_niche_is_valid(-1) != 0 { return 4 }
19 if nx_niche_is_valid(8) != 0 { return 5 }
20
21 let name: *u8 = (sys_mmap(8)) as *u8
22 name[0] = 73 as u8
23
24 // 2: reclaim Intel ME with no mitigations -- low trust (Q10 205)
25 let env1: *NxSafetyEnvelope = nx_reclaim(NX_CHIP_INTEL_ME, name,
26 NX_MIT_NONE,
27 (0 as i64) as *NxOrganism,
28 16)
29 if env1.chip_family != NX_CHIP_INTEL_ME { return 6 }
30 if env1.effective_trust_q10 != 205 { return 7 }
31 // Below the 410 gameplay threshold:
32 if env1.safe_gameplay != 0 { return 8 }
33 if env1.safe_identity != 0 { return 9 }
34 if env1.safe_financial != 0 { return 10 }
35 // ME has 7 threat surfaces flagged
36 if env1.n_xenocells_spawned != 7 { return 11 }
37
38 // 3: reclaim Intel ME with ALL 7 applicable mitigations -- trust 921
39 let env2: *NxSafetyEnvelope = nx_reclaim(NX_CHIP_INTEL_ME, name,
40 NX_MIT_ME_CLEANER_HAP + NX_MIT_COREBOOT + NX_MIT_EGRESS_FILTER +
41 NX_MIT_MEMORY_HYGIENE + NX_MIT_DMA_DISCIPLINE +
42 NX_MIT_CRYPTO_COMPART + NX_MIT_SILICON_TRUST_ENF,
43 (0 as i64) as *NxOrganism, 16)
44 if env2.effective_trust_q10 != 921 { return 12 }
45 if env2.safe_gameplay != 1 { return 13 }
46 if env2.safe_content != 1 { return 14 }
47 if env2.safe_dev != 1 { return 15 }
48 if env2.safe_browsing != 1 { return 16 }
49 if env2.safe_family_comms != 1 { return 17 }
50 if env2.safe_identity != 1 { return 18 } // 921 >= 819
51 if env2.safe_health_pii != 1 { return 19 } // 921 >= 768
52 if env2.safe_financial != 1 { return 20 } // 921 >= 768
53
54 // 4: reclaim Qualcomm baseband (lower trust, kill switch only)
55 let env3: *NxSafetyEnvelope = nx_reclaim(NX_CHIP_QUALCOMM_BASEBAND, name,
56 NX_MIT_KILL_SWITCH + NX_MIT_EGRESS_FILTER + NX_MIT_DMA_DISCIPLINE,
57 (0 as i64) as *NxOrganism, 16)
58 // Base 205 + 819 * 3/8 = 205 + 307 = 512
59 if env3.effective_trust_q10 != 512 { return 21 }
60 if env3.safe_gameplay != 1 { return 22 } // 512 >= 410
61 if env3.safe_dev != 1 { return 23 } // 512 >= 512
62 if env3.safe_family_comms != 0 { return 24 } // 512 < 614
63 if env3.safe_identity != 0 { return 25 } // 512 < 819
64 if env3.safe_financial != 0 { return 26 } // 512 < 768
65 // baseband has 3 surfaces flagged (RADIO + DMA + NET_EGRESS)
66 if env3.n_xenocells_spawned != 3 { return 27 }
67
68 // 5: invalid chip family returns refuse-everything envelope
69 let env_bad: *NxSafetyEnvelope = nx_reclaim(99, name,
70 NX_MIT_NONE, (0 as i64) as *NxOrganism, 16)
71 if env_bad.effective_trust_q10 != 0 { return 28 }
72 if env_bad.safe_gameplay != 0 { return 29 }
73 if env_bad.safe_identity != 0 { return 30 }
74 if env_bad.n_xenocells_spawned != 0 { return 31 }
75
76 // 6: SOVEREIGN_NISHI -- every niche safe, no xenocells spawned
77 let env_sov: *NxSafetyEnvelope = nx_reclaim(NX_CHIP_SOVEREIGN_NISHI, name,
78 NX_MIT_NONE, (0 as i64) as *NxOrganism, 16)
79 if env_sov.effective_trust_q10 != 1024 { return 32 }
80 if env_sov.safe_gameplay != 1 { return 33 }
81 if env_sov.safe_identity != 1 { return 34 }
82 if env_sov.safe_health_pii != 1 { return 35 }
83 if env_sov.safe_financial != 1 { return 36 }
84 if env_sov.n_xenocells_spawned != 0 { return 37 } // no threat surface
85
86 // 7: can_run_niche dispatcher
87 if nx_reclaim_can_run_niche(env2, NX_NICHE_GAMEPLAY) != 1 { return 38 }
88 if nx_reclaim_can_run_niche(env1, NX_NICHE_IDENTITY) != 0 { return 39 }
89 if nx_reclaim_can_run_niche(env_sov, NX_NICHE_FINANCIAL) != 1 { return 40 }
90
91 // 8: applied_mitigations bitmask filtered to available set
92 // (caller can pass NX_MIT_KILL_SWITCH to ME but it gets dropped
93 // because ME doesn't have KILL_SWITCH in its available set)
94 let env_filt: *NxSafetyEnvelope = nx_reclaim(NX_CHIP_INTEL_ME, name,
95 NX_MIT_KILL_SWITCH + NX_MIT_ME_CLEANER_HAP,
96 (0 as i64) as *NxOrganism, 16)
97 if (env_filt.applied_mitigations & NX_MIT_KILL_SWITCH) != 0 { return 41 }
98 if (env_filt.applied_mitigations & NX_MIT_ME_CLEANER_HAP) == 0 { return 42 }
99
100 return 0
101}