Commit Graph

20 Commits

Author SHA1 Message Date
1c04ddf909 style: cargo fmt kernel crates 2026-10-26 19:07:54 +01:00
cbabe2abfe cleanup: replace magic 1024 page limit with ProcessMemory::DEFAULT_PAGE_LIMIT 2026-10-18 22:43:18 +02:00
06863c84fa fix: critical privilege escalation + resource leak hardening
CRITICAL — MapPage privilege escalation:
  handle_map_page allowed mapping kernel memory (VA >= 0x80000000)
  into userspace. Any process with a Process capability could read/
  write kernel data structures. Fixed: reject src_va >= USER_VA_LIMIT.

HIGH — resource leaks:
  handle_kill: leaked pages (used cleanup_threads directly instead
    of destroy_process). Now uses destroy_process for full cleanup.
  handle_create_process: orphaned process on cap grant failure.
    Now destroys process on rollback.
  handle_create_endpoint: orphaned endpoint on cap grant failure.
    Now destroys endpoint on rollback.
  Thread ID array: hardcoded [None; 4] replaced with
    [None; MAX_THREADS_PER_PROCESS] slice. cleanup_threads now
    takes &[Option<ThreadId>] slice.

MEDIUM — quality fixes:
  handle_request_pages: replaced unreachable!() with proper error
    return + page pool rollback.
2026-10-18 22:39:16 +02:00
d009818caf fix: kernel hardening pass 2 — page tracking, queue overflow, region tracking
Page lifecycle:
- ProcessMemory now tracks (PhysicalAddress, count) pairs for each
  allocation (up to 16). destroy_process iterates and frees all
  pages back to the pool. No more permanent page leaks on exit/fault.
- RequestPages re-adds MemoryRegion entries so ReleasePages works.
  Release test un-ignored, passes.
- RequestPages: VA allocation moved after pool allocation succeeds,
  preventing VA leak on OOM.

IPC hardening:
- WaitQueue overflow (>16 waiters): returns WouldBlock error instead
  of silently dropping the thread. Thread is not blocked if enqueue
  fails.
- debug_assert on pending_messages[sender].take() — invariant that
  a sender in wait queue must have a pending message.

Scheduler:
- remove() now clears current thread if the removed thread was
  current on its core.
- add() asserts push succeeded; bitmap bit only set if thread was
  actually added to RunList.

Cleanup:
- Priority::DEFAULT replaces Priority::new(16).unwrap() in
  spawn_thread and spawn_thread_in.

36 kernel tests pass, 0 ignored.
2026-10-18 22:31:16 +02:00
ea2ac5d1d9 fix: harden kernel — eliminate UB, proper process cleanup
Critical: kernel_ref() UB eliminated
- kernel_ref() returned &'static mut, creating aliasing mutable
  references across trap handler + boot code (13+ call sites)
- Replaced with kernel_ptr() -> *mut Kernel, each use site does
  explicit unsafe { &mut *kernel_ptr() }
- KernelCell: removed get_mut(), added as_ptr() -> *mut T
- UB is gone: raw pointer access makes the single-core invariant
  explicit at every use site

Important: process cleanup on exit/fault
- New destroy_process() method consolidates cleanup:
  - Removes all threads from scheduler and endpoints
  - Clears pending messages and results
  - Destroys process and frees ProcessMemory
- handle_exit and handle_fault both use destroy_process()
- handle_exit_thread uses destroy_process when last thread exits

IPC hardening:
- Added invariant comment on pending_messages[sender].take()
  (sender in wait queue must have a pending message)

handle_release_pages:
- Now uses translate_va to convert VA→PA (was treating VA as PA)
2026-10-18 22:22:48 +02:00
38f20cc3c4 feat: proper IPC-based boot — init loads servers from storage via IPC, VirtIO GPU driver
Complete microkernel boot pipeline: adapter loads only init + storage + display
from disk. Init bootstraps all other servers by reading binaries from the
storage server via IPC, parsing ELF, creating processes, mapping pages, and
spawning threads.

New syscalls:
- CreateEndpoint: userspace endpoint creation with full capability grant
- DebugPutchar: debug output to UART from userspace
- MapPage: cross-process page mapping (init loads binaries into children)
- SpawnThreadIn: spawn thread in another process via capability

Key fixes:
- Per-process L1 page tables for VPN[2]=0 (prevents cross-process corruption)
- Separate kernel_pt from page_tables[0] (init pid=0 overwrote kernel PT ref)
- Thread Running state set in switch_to_next (syscalls rejected without it)
- Pending IPC results applied during context switch
- SIE disabled during boot (timer can't preempt into unready processes)
- User heap VA starts at 0x40000 (avoids shared buffer at 0x30000)
- RequestPages maps at user VAs via per-process heap allocator

VirtIO GPU:
- Adapter probes for GPU device, initializes resource/scanout/backing
- Display server writes to mapped framebuffer, flushes via GPU virtqueue
- 640x480 BGRA framebuffer with transfer-to-host and resource-flush

Storage server:
- Userspace VirtIO block driver using pre-mapped MMIO and DMA pages
- FAT16 filesystem reader serving file-read requests via IPC
- Shared buffer protocol: init writes filename, storage writes file data

Echo app for IPC testing (adapter-loaded echo proved the pipeline end-to-end).
2026-10-18 13:02:30 +02:00
7724a5bd0a feat: implement context switching, SavedContext with pc/status fields, wire all syscall outcomes and timer preemption 2026-10-18 02:34:36 +02:00
66a730b2fe feat(adapter-riscv): IPC demo — two processes exchange a message on QEMU virt 2026-10-18 01:58:18 +02:00
192631d506 feat(kernel): implement generation-based capability revocation with proofs and tests 2026-10-18 01:11:24 +02:00
acc59830ff feat: add Kani proofs for delegation non-escalation across types, domain, and kernel 2026-10-18 00:55:52 +02:00
2c4a9dbadc refactor(kernel): move SyscallOutcome/Result to syscall module, move test helpers to tests module 2026-10-18 00:39:28 +02:00
b8c5090fe5 fix(kernel): fix kill wait-queue cleanup, RegionId tracking, ReleasePages ownership, and SwitchTo scheduler state 2026-10-18 00:31:05 +02:00
8912a944b8 feat(kernel): add WaitForInterrupt, AcknowledgeInterrupt, and WaitAny syscalls 2026-10-18 00:26:11 +02:00
e7835c0435 feat(kernel): add Send and Receive IPC syscalls with rendezvous 2026-10-18 00:24:09 +02:00
ae6023081a feat(kernel): add Delegate syscall for capability delegation 2026-10-18 00:22:37 +02:00
471d96b9a4 feat(kernel): add RequestPages and ReleasePages syscalls 2026-10-18 00:19:24 +02:00
95c023f286 feat(kernel): add handle_tick and handle_interrupt entry points 2026-10-18 00:17:55 +02:00
74b296a2bf feat(kernel): add Exit and ExitThread syscalls with process cleanup 2026-10-18 00:16:38 +02:00
d0a0ba788f feat(kernel): add Kernel struct, MockPlatform, and simple syscalls (GetTime, GetProcessId, Yield) 2026-10-18 00:15:40 +02:00
bb99c3001d init 2026-10-16 02:32:24 +02:00