// K2460 guest experiment: process kill vs physical power-loss separation // (`fault_matrix.physical_boundary`) in the product kernel runtime. Enforces // "SIGKILL fiziksel güç testi değildir": an EL0 negative actor // (`k2460-sigkillphysicalpass`) attempts to commit the physical power boundary // with host kill counted as a physical power PASS ("Host öldürme fiziksel PASS // sayılır"), SIGKILL conflated with physical power cut, hidden evidence // boundary or external requirement ("Kanıt sınırı ve dış deney gereği // görünür"), transient VM cut cases mismatch ("Geçici VM kesinti korpusu"), and // visible external boundary notes mismatch; all five are refused and // `committed_receipt()` remains None. Then EL0 `k2460-vmcutboundary` commits 4 // transient VM interruption cases with 2 visible external boundary notes, 1 // separate physical power gate, and 0 SIGKILL-counted-as-physical-PASS claims, // verifies the committed binding digest, refuses a duplicate commit, and // returns all user-space frames. use super::feature_el0 as el0; use turkos_kernel::runtime::fault_matrix_physical_boundary::{ compute_fault_matrix_physical_boundary_binding_digest, FaultMatrixPhysicalBoundaryCoordinator, FaultMatrixPhysicalBoundaryRequest, EXPECTED_SEPARATE_PHYSICAL_POWER_GATES, EXPECTED_SIGKILL_COUNTED_AS_PHYSICAL_PASS, EXPECTED_TRANSIENT_VM_CUT_CASES, EXPECTED_VISIBLE_EXTERNAL_BOUNDARY_NOTES, }; use core::arch::asm; use core::ptr::{addr_of, addr_of_mut, read_volatile, write_volatile}; #[unsafe(no_mangle)] static mut OS_K2460_EVIDENCE: [u64; 64] = [0; 64]; #[unsafe(no_mangle)] static mut OS_K2460_CAPTURE_GATE: u8 = 0; static SIGKILLPHYSICALPASS: &[u8] = include_bytes!("k2460-sigkillphysicalpass.bin"); static VMCUTBOUNDARY: &[u8] = include_bytes!("k2460-vmcutboundary.bin"); const MAGIC: u64 = 0x4b32_3436_305f_5042; // "K2460_PB" const SYS_EXIT: u64 = 1; const SYS_FAULT_MATRIX_PHYSICAL_BOUNDARY: u64 = 132; const SYS_FAULT_MATRIX_PHYSICAL_BOUNDARY_RECEIPT: u64 = 133; const REFUSED: u64 = 1 << 63; const PREVIOUS_PHYSICAL_BOUNDARY_EPOCH: u64 = 81; const PHYSICAL_BOUNDARY_EPOCH: u64 = 82; const PHYSICAL_BOUNDARY_CORPUS_DIGEST: u64 = 0x2460_464d_5048_5953; const SIGKILLPHYSICALPASS_ID: el0::Identity = el0::Identity { pid: 9, generation: 0x2460_0009, }; const VMCUTBOUNDARY_ID: el0::Identity = el0::Identity { pid: 1, generation: 0x2460_0001, }; struct State { coord: Option, user: Option, request: Option, calls: usize, base: usize, } static mut STATE: State = State { coord: None, user: None, request: None, calls: 0, base: 0, }; fn state() -> &'static mut State { unsafe { &mut *addr_of_mut!(STATE) } } fn word(i: usize, v: u64) { unsafe { write_volatile( addr_of_mut!(OS_K2460_EVIDENCE).cast::().add(i), v, ) } } #[inline(never)] fn checkpoint(stage: u64) { word(1, stage); unsafe { write_volatile(addr_of_mut!(OS_K2460_CAPTURE_GATE), 0) }; el0::write_fields("TURKOS/OS/K2460: CAPTURE", &[("STAGE", stage)]); while unsafe { read_volatile(addr_of!(OS_K2460_CAPTURE_GATE)) } == 0 { unsafe { asm!("yield", options(nomem, nostack, preserves_flags)) } } } #[inline(never)] fn setup_stage() -> Result<(u64, u64), &'static str> { let expected_binding = compute_fault_matrix_physical_boundary_binding_digest( EXPECTED_TRANSIENT_VM_CUT_CASES, EXPECTED_VISIBLE_EXTERNAL_BOUNDARY_NOTES, EXPECTED_SEPARATE_PHYSICAL_POWER_GATES, EXPECTED_SIGKILL_COUNTED_AS_PHYSICAL_PASS, PHYSICAL_BOUNDARY_EPOCH, PHYSICAL_BOUNDARY_CORPUS_DIGEST, ); let expected_receipt = expected_binding ^ 0x2460_ACE0_5048_5931; let request = FaultMatrixPhysicalBoundaryRequest { host_kill_counted_as_physical_power_pass: false, sigkill_conflated_with_physical_power_cut: false, evidence_boundary_and_external_need_visible: true, transient_vm_cut_cases: EXPECTED_TRANSIENT_VM_CUT_CASES, visible_external_boundary_notes: EXPECTED_VISIBLE_EXTERNAL_BOUNDARY_NOTES, separate_physical_power_gates: EXPECTED_SEPARATE_PHYSICAL_POWER_GATES, physical_boundary_epoch: PHYSICAL_BOUNDARY_EPOCH, previous_physical_boundary_epoch: PREVIOUS_PHYSICAL_BOUNDARY_EPOCH, physical_boundary_corpus_digest: PHYSICAL_BOUNDARY_CORPUS_DIGEST, physical_boundary_binding_digest: expected_binding, }; let coord = FaultMatrixPhysicalBoundaryCoordinator::new(); for (j, v) in [ EXPECTED_TRANSIENT_VM_CUT_CASES as u64, EXPECTED_VISIBLE_EXTERNAL_BOUNDARY_NOTES as u64, u64::from(coord.is_committed()), EXPECTED_SEPARATE_PHYSICAL_POWER_GATES as u64, EXPECTED_SIGKILL_COUNTED_AS_PHYSICAL_PASS as u64, PHYSICAL_BOUNDARY_EPOCH, expected_binding, expected_receipt, ] .into_iter() .enumerate() { word(4 + j, v); } let st = state(); st.request = Some(request); st.coord = Some(coord); Ok((expected_binding, expected_receipt)) } fn dispatch(_caller: el0::Identity, frame: &mut el0::Frame) -> el0::Step { let st = state(); let base_req = *st.request.as_ref().unwrap(); let coord = st.coord.as_mut().unwrap(); let r = match frame.number() { SYS_FAULT_MATRIX_PHYSICAL_BOUNDARY => match frame.arg(0) { 0 => match coord.commit_physical_power_boundary(&base_req) { Ok(rec) => rec.receipt_digest, Err(e) => REFUSED | (e as u64), }, 1 => { let mut req = base_req; req.host_kill_counted_as_physical_power_pass = true; match coord.commit_physical_power_boundary(&req) { Ok(rec) => rec.receipt_digest, Err(e) => REFUSED | (e as u64), } } 2 => { let mut req = base_req; req.sigkill_conflated_with_physical_power_cut = true; match coord.commit_physical_power_boundary(&req) { Ok(rec) => rec.receipt_digest, Err(e) => REFUSED | (e as u64), } } 3 => { let mut req = base_req; req.evidence_boundary_and_external_need_visible = false; match coord.commit_physical_power_boundary(&req) { Ok(rec) => rec.receipt_digest, Err(e) => REFUSED | (e as u64), } } 4 => { let mut req = base_req; req.transient_vm_cut_cases = 0; match coord.commit_physical_power_boundary(&req) { Ok(rec) => rec.receipt_digest, Err(e) => REFUSED | (e as u64), } } _ => { let mut req = base_req; req.visible_external_boundary_notes = 0; match coord.commit_physical_power_boundary(&req) { Ok(rec) => rec.receipt_digest, Err(e) => REFUSED | (e as u64), } } }, SYS_FAULT_MATRIX_PHYSICAL_BOUNDARY_RECEIPT => match coord.committed_receipt() { Some(_) => base_req.physical_boundary_binding_digest, None => 0, }, SYS_EXIT => return el0::Step::Exit(frame.arg(0)), _ => return el0::Step::Exit(0xbad), }; if st.calls < 8 { word(st.base + st.calls, r); st.calls += 1; } frame.ret(r); el0::Step::Resume } #[inline(never)] fn run_program( allocator: &mut super::memory::FrameAllocator, tables: &super::mmu::Tables, boot: &super::BootData, id: el0::Identity, image: &[u8], args: [u64; 2], base: usize, ) -> Result { let st = state(); st.user = Some( unsafe { tables.build_user_space(allocator, boot.hardware.ram_base, boot.hardware.ram_size) } .map_err(|_| "k2460-user")?, ); let user = st.user.as_ref().unwrap(); if !user.contract_valid(tables.root) { return Err("k2460-user-contract"); } unsafe { el0::load(user, image) }?; st.calls = 0; st.base = base; let mut handler = dispatch; let outcome = unsafe { el0::run(st.user.as_ref().unwrap(), id, args, &mut handler) }; let user = st.user.take().unwrap(); unsafe { user.release_after_tlbi(allocator, tables.root) }.map_err(|_| "k2460-release")?; Ok(outcome) } #[inline(never)] fn record_sigkillphysicalpass(sigkillphysicalpass: &el0::Outcome) { let coord = state().coord.as_ref().unwrap(); for (j, v) in [ sigkillphysicalpass.exit, sigkillphysicalpass.syscalls, sigkillphysicalpass.fault, coord.rejected_total(), u64::from(coord.is_committed()), coord.physical_boundary_refusals(), coord.boundary_accounting_refusals(), 0, ] .into_iter() .enumerate() { word(20 + j, v); } } #[inline(never)] fn finish_stage( sigkillphysicalpass: &el0::Outcome, vmcutboundary: &el0::Outcome, free_before: u64, free_after: u64, expected_binding: u64, expected_receipt: u64, ) -> Result<(), &'static str> { let coord = state().coord.as_ref().unwrap(); let rec = coord.committed_receipt().ok_or("k2460-missing-receipt")?; for (j, v) in [ vmcutboundary.exit, vmcutboundary.syscalls, vmcutboundary.fault, u64::from(rec.evidence_boundary_and_external_need_visible), u64::from(coord.is_committed()), rec.transient_vm_cut_cases as u64, rec.visible_external_boundary_notes as u64, rec.separate_physical_power_gates as u64, rec.sigkill_counted_as_physical_pass as u64, expected_binding, rec.receipt_digest, coord.physical_boundary_refusals(), coord.boundary_accounting_refusals(), 0, coord.rejected_total(), coord.committed_total(), rec.physical_boundary_epoch, ] .into_iter() .enumerate() { word(36 + j, v); } word(3, free_after); if free_after != free_before { return Err("k2460-frame-accounting"); } if sigkillphysicalpass.exit != 0x2459 || vmcutboundary.exit != 132 || !coord.is_committed() || !rec.evidence_boundary_and_external_need_visible || rec.transient_vm_cut_cases != EXPECTED_TRANSIENT_VM_CUT_CASES || rec.visible_external_boundary_notes != EXPECTED_VISIBLE_EXTERNAL_BOUNDARY_NOTES || rec.separate_physical_power_gates != EXPECTED_SEPARATE_PHYSICAL_POWER_GATES || rec.sigkill_counted_as_physical_pass != EXPECTED_SIGKILL_COUNTED_AS_PHYSICAL_PASS || rec.physical_boundary_epoch != PHYSICAL_BOUNDARY_EPOCH || rec.receipt_digest != expected_receipt || coord.physical_boundary_refusals() != 3 || coord.boundary_accounting_refusals() != 2 || coord.rejected_total() != 6 || coord.committed_total() != 1 { return Err("k2460-outcome"); } checkpoint(3); el0::write_fields( "TURKOS/OS/K2460-FAULT-MATRIX-PHYSICAL-BOUNDARY:", &[ ("COMMITTED", u64::from(coord.is_committed())), ("VM_CUTS", rec.transient_vm_cut_cases as u64), ("NOTES", rec.visible_external_boundary_notes as u64), ("GATES", rec.separate_physical_power_gates as u64), ("SIGKILL_PASS", rec.sigkill_counted_as_physical_pass as u64), ("EPOCH", rec.physical_boundary_epoch), ("BINDING", expected_binding), ("RECEIPT", rec.receipt_digest), ("REJECTED", coord.rejected_total()), ("FREE_EQUAL", 1), ], ); Ok(()) } #[inline(never)] fn run_inner( runtime: &mut super::OsK660Runtime, tables: &super::mmu::Tables, boot: &super::BootData, ) -> Result<(), &'static str> { let allocator = &mut runtime.memory_mut().map_err(|_| "k2460-memory")?.allocator; let free_before = allocator.remaining_pages() as u64; word(0, MAGIC); word(2, free_before); let (expected_binding, expected_receipt) = setup_stage()?; checkpoint(1); let sigkillphysicalpass = run_program( allocator, tables, boot, SIGKILLPHYSICALPASS_ID, SIGKILLPHYSICALPASS, [expected_binding, expected_receipt], 12, )?; record_sigkillphysicalpass(&sigkillphysicalpass); checkpoint(2); let vmcutboundary = run_program( allocator, tables, boot, VMCUTBOUNDARY_ID, VMCUTBOUNDARY, [expected_binding, expected_receipt], 28, )?; let free_after = allocator.remaining_pages() as u64; finish_stage( &sigkillphysicalpass, &vmcutboundary, free_before, free_after, expected_binding, expected_receipt, ) } extern "C" fn entry( runtime: *mut super::OsK660Runtime, tables: *const super::mmu::Tables, boot: *const super::BootData, out: *mut Result<(), &'static str>, ) { unsafe { *out = run_inner(&mut *runtime, &*tables, &*boot) } } #[inline(never)] pub fn run( runtime: &mut super::OsK660Runtime, tables: &super::mmu::Tables, boot: &super::BootData, ) -> Result<(), &'static str> { let mut out: Result<(), &'static str> = Ok(()); let top = (addr_of!(super::OS_K900_STACK) as u64 + 4096 + 65536 - 16) & !15; unsafe { asm!( "mov x9, sp", "mov sp, x4", "stp x9, x30, [sp, #-16]!", "blr x5", "ldp x9, x30, [sp], #16", "mov sp, x9", in("x0") runtime as *mut _, in("x1") tables as *const _, in("x2") boot as *const _, in("x3") &mut out as *mut _, in("x4") top, in("x5") entry as usize, clobber_abi("C"), ) }; out }