⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

Module kaslr

Module kaslr 

Source
Expand description

Kernel Address Space Layout Randomization (KASLR)

Provides address randomization for kernel text, heap, stack, and module load addresses. Uses architecture-specific hardware entropy sources (RDRAND on x86_64, RNDR on AArch64) with an xorshift64 PRNG fallback for RISC-V and other architectures.

§Design

KASLR offsets are computed once during boot and stored in a global KaslrState protected by a RwLock. The state includes:

  • text_offset: Randomized slide for kernel text/code
  • heap_offset: Randomized base offset for the kernel heap
  • stack_offset: Default per-thread stack randomization quantum
  • module_base: Randomized base for driver/module loading

Runtime re-randomization can refresh offsets for long-running systems, though the kernel text offset is typically fixed at boot.

§Entropy Sources

ArchitecturePrimary SourceFallback
x86_64RDRANDxorshift64 (TSC seed)
AArch64RNDRxorshift64 (CNTPCT seed)
RISC-VN/Axorshift64 (cycle seed)

Structs§

KaslrState
Current KASLR offsets and PRNG state.

Functions§

get_heap_offset
Get the kernel heap base randomization offset.
get_module_base
Get a randomized module/driver load base address.
get_offsets
Get a snapshot of current KASLR offsets for diagnostics.
get_text_offset
Get the kernel text randomization offset.
init
Initialize the KASLR subsystem.
is_active
Check if KASLR is initialized and active.
randomize_stack
Randomize a thread’s stack base by subtracting a random offset.
rerandomize
Re-randomize non-text KASLR offsets.
rerandomize_count
Get the number of re-randomizations performed.