Skip to main content

Module kaslr

Module kaslr 

Source
Expand description

Kernel Address Space Layout Randomization (KASLR).

Generates per-boot random offsets for:

  • Userspace mmap base address
  • Userspace stack base address
  • ELF PIE loading base address

Offsets are generated once at boot from the entropy pool and remain constant for the lifetime of the boot. Each process receives its own randomized layout derived from these base offsets.

ยงEntropy requirements

init() calls entropy::fill_random() which blocks until the pool has accumulated at least 64 bytes of entropy. On a live system with keyboard/timer interrupts this takes < 1 ms. On QEMU without RDRAND the pool seeds from TSC and accumulates quickly via IRQ noise.

Staticsยง

INITIALIZED ๐Ÿ”’
Whether KASLR has been initialized.
MMAP_BASE_OFFSET ๐Ÿ”’
Randomized mmap base offset (added to MMAP_BASE).
PIE_BASE_OFFSET ๐Ÿ”’
Randomized PIE base offset (added to PIE_BASE_ADDR).
STACK_BASE_OFFSET ๐Ÿ”’
Randomized user stack base offset (added to USER_STACK_BASE).

Functionsยง

draw_stack_jitter
Draw a fresh per-image stack jitter: a page-aligned offset in 0..=255 pages (0..~1 MiB).
init
Initialize KASLR offsets from the entropy pool. Called once at boot.
mmap_base
Get the randomized mmap base address.
pie_base
Get the randomized PIE base address for ELF loading.
stack_base
Get the randomized user stack base address.
stack_base_with_jitter
Stack base for a specific process, adding its own jitter on top of the boot-randomized base. Use with draw_stack_jitter.
stack_guard
Get the guard page address below the user stack.
stack_top
Get the randomized user stack top address.
stack_top_for
Get the top of a stack of pages 4 KiB pages starting at base.