Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions kernel/kernel_core/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,8 @@ fn fork_prepare_child_state(
file_regions: child_file_regions,
sealed_ranges: child_sealed_ranges,
mbind_policies: child_mbind_policies,
// Linux io_setup(2): AIO contexts are NOT inherited across fork().
aio_contexts: mm::AdmittedVec::new(mm::HeapClass::CoreProcess),
elf_segments: child_elf_segments,

brk_start: parent_mm.brk_start,
Expand Down
5 changes: 5 additions & 0 deletions kernel/kernel_core/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,10 @@ pub struct MmState {
/// Inherited across `fork()` and cleared on `execve()`.
pub mbind_policies: mm::AdmittedVec<(usize, usize, u32)>,

/// Wave 11: Linux AIO contexts (`io_setup(206)` / `io_destroy(207)`).
/// Shared across `CLONE_VM` threads, NOT inherited across `fork()`, torn down on `execve()`/exit.
pub aio_contexts: mm::AdmittedVec<(u64, Arc<crate::syscall::AioContext>)>,

/// N3.3: Immutable page-aligned `[start, end)` spans of loaded ELF `PT_LOAD`
/// segments (main executable + optional `PT_INTERP` dynamic linker), shared
/// via `Arc` across `fork()` so RELRO `mprotect` visibility requires zero
Expand Down Expand Up @@ -2769,6 +2773,7 @@ impl MmState {
file_regions: mm::AdmittedMap::new(mm::HeapClass::CoreProcess),
sealed_ranges: mm::AdmittedMap::new(mm::HeapClass::CoreProcess),
mbind_policies: mm::AdmittedVec::new(mm::HeapClass::CoreProcess),
aio_contexts: mm::AdmittedVec::new(mm::HeapClass::CoreProcess),
elf_segments: None,
brk_start: 0,
brk: 0,
Expand Down
123 changes: 123 additions & 0 deletions kernel/kernel_core/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ mod sys;
mod time;
mod unix_sock;
mod wave10_p3;
mod wave11_p3;
mod wave9_p2;
mod xattr;

Expand Down Expand Up @@ -130,6 +131,8 @@ use unix_sock::*;
#[allow(unused_imports)]
use wave10_p3::*;
#[allow(unused_imports)]
use wave11_p3::*;
#[allow(unused_imports)]
use wave9_p2::*;
#[allow(unused_imports)]
use xattr::*;
Expand Down Expand Up @@ -229,6 +232,7 @@ pub use socket::{
};
pub use sys::ComplianceStatusBuf;
pub use time::run_startup_abi_self_test;
pub use wave11_p3::AioContext;
pub use wave9_p2::LandlockDomain;

/// R130-1 FIX: Maximum number of mmap regions per process.
Expand Down Expand Up @@ -3239,6 +3243,66 @@ fn syscall_dispatcher_full(
arg3 as usize,
arg4 as usize,
),
// Wave 11: Final 31 Linux x86-64 P3 syscalls (386/386 = 100% parity!)
Sc::IoSetup => sys_io_setup(arg0 as u32, arg1 as *mut u64),
Sc::IoDestroy => sys_io_destroy(arg0),
Sc::IoGetevents => sys_io_getevents(
arg0,
arg1 as i64,
arg2 as i64,
arg3 as *mut u8,
arg4 as *const u8,
),
Sc::IoSubmit => sys_io_submit(arg0, arg1 as i64, arg2 as *const usize),
Sc::IoCancel => sys_io_cancel(arg0, arg1 as *const u8, arg2 as *mut u8),
Sc::IoPgetevents => sys_io_pgetevents(
arg0,
arg1 as i64,
arg2 as i64,
arg3 as *mut u8,
arg4 as *const u8,
arg5 as *const u8,
),
Sc::ModifyLdt => sys_modify_ldt(arg0 as i32, arg1 as *mut u8, arg2 as usize),
Sc::SetThreadArea => sys_set_thread_area(arg0 as *mut u8),
Sc::GetThreadArea => sys_get_thread_area(arg0 as *mut u8),
Sc::InitModule => sys_init_module(arg0 as *const u8, arg1 as usize, arg2 as *const u8),
Sc::FinitModule => sys_finit_module(arg0 as i32, arg1 as *const u8, arg2 as i32),
Sc::DeleteModule => sys_delete_module(arg0 as *const u8, arg1 as u32),
Sc::KexecLoad => sys_kexec_load(
arg0 as usize,
arg1 as usize,
arg2 as *const u8,
arg3 as usize,
),
Sc::KexecFileLoad => sys_kexec_file_load(
arg0 as i32,
arg1 as i32,
arg2 as usize,
arg3 as *const u8,
arg4 as usize,
),
Sc::Quotactl => {
sys_quotactl(arg0 as u32, arg1 as *const u8, arg2 as u32, arg3 as *mut u8)
}
Sc::QuotactlFd => {
sys_quotactl_fd(arg0 as u32, arg1 as u32, arg2 as u32, arg3 as *mut u8)
}
Sc::Uretprobe => sys_uretprobe(),
Sc::Uprobe => sys_uprobe(),
Sc::Uselib => sys_uselib(),
Sc::Sysctl => sys_sysctl(),
Sc::CreateModule => sys_create_module(),
Sc::GetKernelSyms => sys_get_kernel_syms(),
Sc::QueryModule => sys_query_module(),
Sc::Nfsservctl => sys_nfsservctl(),
Sc::Getpmsg => sys_getpmsg(),
Sc::Putpmsg => sys_putpmsg(),
Sc::AfsSyscall => sys_afs_syscall(),
Sc::Tuxcall => sys_tuxcall(),
Sc::Security => sys_security(),
Sc::LookupDcookie => sys_lookup_dcookie(),
Sc::Vserver => sys_vserver(),
Sc::Getdents64 => sys_getdents64(
arg0 as i32,
arg1 as *mut u8,
Expand Down Expand Up @@ -4237,6 +4301,7 @@ mod r190_11_dispatch_parity_tests {
include_str!("unix_sock.rs"),
include_str!("ptrace.rs"),
include_str!("wave10_p3.rs"),
include_str!("wave11_p3.rs"),
];
let sig_priv = alloc::format!("\nfn {}(", handler);
let sig_pub_super = alloc::format!("\npub(super) fn {}(", handler);
Expand Down Expand Up @@ -5380,4 +5445,62 @@ mod wave5_syscall_tests {
assert_eq!(wave10_p3::validate_mpol_mode(2 | (1 << 15)), Ok(2));
assert_eq!(wave10_p3::validate_mpol_mode(99), Err(SyscallError::EINVAL));
}

#[test]
fn wave11_full_386_syscall_parity_and_abi_layouts() {
let wave11_nrs = [
134u64, 154, 156, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 205, 206,
207, 208, 209, 210, 211, 212, 236, 246, 313, 320, 333, 335, 336, 443,
];
assert_eq!(wave11_nrs.len(), 31);
for nr in wave11_nrs {
let spec = seccomp::syscall_table::lookup(nr).expect("wave11 syscall registered");
assert_eq!(
spec.dispatch,
seccomp::syscall_table::DispatchStatus::Dispatched
);
assert!(seccomp::syscall_table::DispatchedSyscall::from_nr(nr).is_some());
}
// Verify all 386 Linux x86-64 syscalls (0..=336 and 424..=472) are registered!
for nr in (0u64..=336).chain(424u64..=472) {
assert!(
seccomp::syscall_table::lookup(nr).is_some(),
"Linux x86-64 syscall {} missing from SYSCALL_TABLE",
nr
);
}
assert_eq!(core::mem::size_of::<wave11_p3::IoCb>(), 64);
assert_eq!(core::mem::size_of::<wave11_p3::IoEvent>(), 32);
}

#[test]
fn wave11_aio_context_queue_and_destroy_semantics() {
let ctx = wave11_p3::AioContext::try_new(2).unwrap();
let e1 = wave11_p3::IoEvent {
data: 0xaa,
obj: 0x1000,
res: 16,
res2: 0,
};
let e2 = wave11_p3::IoEvent {
data: 0xbb,
obj: 0x2000,
res: -9,
res2: 0,
};
assert_eq!(ctx.try_push_event(e1), Ok(()));
// Reserve second slot in-flight: third submitter must observe EAGAIN immediately.
assert_eq!(ctx.try_reserve_slot(), Ok(()));
assert_eq!(ctx.try_reserve_slot(), Err(SyscallError::EAGAIN));
ctx.complete_slot(Some(e2));
// Pop first event, simulate EFAULT rollback with zero allocation, verify FIFO order.
let p1 = ctx.pop_front().unwrap();
assert_eq!(p1, e1);
ctx.push_front_infallible(p1);
assert_eq!(ctx.pop_front(), Some(e1));
assert_eq!(ctx.pop_front(), Some(e2));
assert_eq!(ctx.pop_front(), None);
ctx.mark_destroyed();
assert_eq!(ctx.try_reserve_slot(), Err(SyscallError::EINVAL));
}
}
Loading