KASLR

Also known as: Kernel address space layout randomization

On this page 7

KASLR (kernel address space layout randomization) is an exploit mitigation that loads the operating system kernel at a randomly chosen memory address on every boot, so that an attacker cannot know in advance where kernel code and data reside. In OS security, it extends the ASLR idea from user processes to the kernel itself and is enabled by default in modern Linux, Windows and macOS builds.

KASLR does not remove vulnerabilities. It turns a reliable kernel exploit into a probabilistic one unless the attacker first obtains an address leak, which is why it is always combined with other defenses such as SMEP, SMAP and control-flow integrity.

How KASLR randomizes the kernel image

KASLR works by choosing a random offset, often called the kernel slide, early in the boot process and relocating the kernel image by that offset before execution begins. On Linux x86-64, the decompression stub picks both a physical and a virtual load address, using entropy from sources such as the RDRAND instruction, the timestamp counter and boot parameters, then applies relocation entries so that every absolute pointer matches the new location.

The offset is fixed for the lifetime of the boot. Every process on the system sees the same kernel layout until the next restart, which is a fundamental property: a single leaked pointer reveals the whole layout for the remaining uptime. Beyond the kernel text, many systems also randomize other regions, as the table below shows.

RegionWhat it holdsRandomized on Linux x86-64
Kernel textExecutable kernel codeYes, by default
Loadable modulesDriver and module codeYes, separate random base
Direct physical mapLinear mapping of all RAMYes, with memory randomization
vmalloc areaVirtually contiguous allocationsYes, with memory randomization
Per-CPU and stacksPer-processor data, task stacksPartly, depends on version
Kernel regions that can be randomized

Entropy and implementation across operating systems

The strength of KASLR is measured in bits of entropy, meaning the number of equally likely positions the kernel can occupy. Kernel entropy is much lower than user-space ASLR because the kernel must fit into a reserved part of the address space and is usually aligned to large pages. On Linux x86-64, the kernel text slides within roughly 1 GiB at 2 MiB alignment, which gives about 9 bits, or 512 possible positions.

The major desktop operating systems introduced the feature at different times and with different defaults.

Operating systemIntroducedDefault status and notes
LinuxKernel 3.14 (2014)On by default on x86 since 4.12; disabled with nokaslr
WindowsWindows VistaAlways on; kernel and drivers randomized per boot
macOSOS X Mountain Lion 10.8Always on; kernel slide chosen by the boot loader
FreeBSDPartial in recent releasesKernel ASLR for modules, limited for kernel text
KASLR in major desktop operating systems

Proposals for function-granular KASLR, which shuffles individual functions instead of moving the whole image, aim to make one leak less useful. Such schemes raise boot time and memory overhead and have not become a default in mainstream kernels.

KASLR addresses where code is located, while neighboring mitigations address what code may execute or be accessed. It is most effective against code-reuse attacks such as return-oriented programming, which need exact gadget addresses. It provides no protection against logic bugs that do not depend on addresses.

MitigationThreat addressedRelationship to KASLR
ASLRExploits targeting user processesSame principle in user space, higher entropy
SMEPKernel executing user-space codeForces attackers to reuse kernel code, so addresses matter
SMAPKernel reading user-space dataBlocks fake structures in user memory
Kernel page-table isolationMeltdown-style kernel readsHides kernel mappings, also hinders some layout leaks
Control-flow integrityHijacked indirect calls and returnsLimits damage even after a leak
KASLR and neighboring kernel defenses

The combination matters: with SMEP and SMAP enabled, an attacker cannot simply jump to user-controlled memory, so the exploit must reuse kernel code, and KASLR then hides where that code is. Each layer raises the cost of the next step in an exploit chain.

Bypass techniques and known weaknesses

In practice, KASLR is routinely bypassed through information disclosure, and serious kernel exploits almost always begin with a leak. The low entropy also means that brute force can succeed when a failed attempt does not crash the machine. The following table summarizes the main bypass classes.

Bypass classMechanismTypical countermeasure
Pointer leaksKernel addresses exposed in logs, files or APIskptr_restrict, dmesg_restrict, API privilege checks
Memory disclosure bugsUninitialized or out-of-bounds kernel readsZeroing allocations, bounds hardening
Timing side channelsPrefetch or TLB timing reveals mapped pagesKernel page-table isolation, patched microcode
Transient executionSpeculative reads, such as MeltdownHardware fixes and page-table isolation
Brute forceGuessing among few hundred slotsCrash on fault, rate limits, reboot monitoring
Main ways attackers defeat KASLR

Research such as the EntryBleed attack showed that timing differences on the system call entry path could reveal the kernel base on some Intel systems even with page-table isolation active. Such findings reinforce the common expert view that KASLR is a speed bump, not a barrier, against a determined local attacker.

Configuring and verifying KASLR

Administrators should keep KASLR enabled and close the leak channels around it. On Linux, the important settings are the absence of the nokaslr boot parameter, kernel.kptr_restrict set to 1 or 2, and kernel.dmesg_restrict set to 1, so that unprivileged users cannot read raw kernel pointers.

  • Compare the kernel symbol address of the same function across two reboots as root; a changing value confirms active randomization.
  • Avoid disabling KASLR for debugging on production systems; use crash dumps that record the slide instead.
  • Treat any kernel address in an unprivileged log as a security bug worth reporting.
  • Remember that virtual machines may expose weaker entropy if the hypervisor provides limited randomness at boot.

A non-technical view

The kernel is the core of an operating system, and attackers who find a flaw in it usually need to know exactly where its parts sit in memory. KASLR moves the kernel to a different, random spot every time the computer starts.

Imagine a vault whose location inside a large building changes every morning. A burglar with a stolen key still has to find the right room first. That makes break-ins harder, but if someone spots the vault once, the location stays the same until the next morning, which is why KASLR works best alongside other protections.

A concrete example

A university computing center runs shared Linux login servers for several hundred students. A security engineer learns of a newly disclosed use-after-free bug in a network driver that allows local privilege escalation, and the public exploit relies on a fixed kernel address taken from a common distribution build.

Because the servers boot with KASLR enabled, the hard-coded address is wrong on every machine, and test runs of the exploit simply crash the kernel instead of granting root. The engineer also confirms that kernel.kptr_restrict is set to 2 and kernel.dmesg_restrict to 1, so students cannot read kernel pointers from system logs or symbol files.

The result is a window of several days to schedule the vendor patch during a maintenance slot rather than in an emergency. The engineer still treats the bug as critical, since a second vulnerability that leaks a single kernel pointer would make the exploit reliable again.