Kernel Exploit Mitigations
Kernel Exploitation · Advanced Exploitation track
8 min read
In this module
Defence in Depth at Ring 0
Kernel exploitation is a high-stakes game, and defenders have layered up. No single mitigation is perfect — together they raise the bar considerably. Understanding these defences matters both for appreciating how difficult modern kernel exploitation has become and for building systems that don't fold immediately under attack.
KASLR: Kernel Address Space Layout Randomisation
Just as ASLR randomizes the addresses of user-space libraries and executables, KASLR randomizes the base address where the kernel is loaded in memory. On each boot, the kernel's code, data, and module addresses are shifted by a random offset.
Without KASLR, the kernel is always loaded at a known address (like 0xffffffff81000000 on x86-64 Linux). An attacker can precalculate the addresses of every function and gadget. With KASLR, those addresses change every boot, and the attacker needs an information leak - a separate vulnerability that reveals a kernel pointer - before they can construct a working exploit.
Without KASLR: commit_creds always at 0xffffffff81056a30
With KASLR (offset = 0x1e00000 this boot): commit_creds at 0xffffffff82e56a30 (different on next boot)KASLR's weakness is that it applies a single offset to the entire kernel. Leak any one kernel pointer and you've got the offset — which hands you every kernel address. The leak doesn't even have to be a bug: EntryBleed (CVE-2022-4543) times prefetch instructions against candidate kernel addresses and recovers the KASLR base on Intel parts in about a second, KPTI or not. Despite this, KASLR is genuinely useful: it forces the attacker to find a separate info leak before they can proceed, and that's an extra hurdle many exploits can't clear.
Kernel Address Space Layout Randomisation (KASLR) randomizes the kernel's load address on each boot. This prevents attackers from hardcoding kernel addresses in exploits. It is defeated by information leaks that reveal any kernel pointer, but it still adds a significant hurdle to exploitation.
KPTI: Kernel Page Table Isolation
KPTI (Kernel Page Table Isolation), originally developed as the KAISER patch, is a defence that maintains two separate sets of page tables for each process:
- Kernel page tables: Contain mappings for both kernel and user-space memory. Used when the CPU is in ring 0.
- User page tables: Contain mappings for user-space memory and only a minimal stub of kernel code (just enough to handle the system call entry and switch to the full kernel page tables). Used when the CPU is in ring 3.
This means that when user-space code is running, the vast majority of kernel memory is not mapped in the page tables at all. Even if an attacker finds a way to read arbitrary virtual memory from user space (as the Meltdown attack did), the kernel pages simply do not exist in the current address space.
User Page Tables: Kernel Page Tables:┌────────────────┐ ┌────────────────┐│ User memory │ │ User memory ││ (full mapping) │ │ (full mapping) │├────────────────┤ ├────────────────┤│ Kernel stub │ │ Full kernel ││ (entry/exit │ │ (all code, ││ only) │ │ data, modules)│└────────────────┘ └────────────────┘KPTI was deployed primarily in response to the Meltdown vulnerability, but it has broader benefits: it reduces the kernel information available to user-space side-channel attacks and makes certain exploitation techniques harder.
The cost of KPTI is performance: switching page tables on every syscall entry and exit requires flushing the TLB, which adds overhead to system calls. Modern CPUs with PCID (Process Context Identifiers) reduce this cost significantly.
Control Flow Integrity (CFI)
CFI restricts where indirect branches (calls through function pointers and returns) can target. Instead of allowing any address, CFI validates that each indirect branch goes to a legitimate function entry point.
The Linux kernel supports several CFI mechanisms:
- Clang CFI (kCFI in current kernels): The compiler instruments every indirect call site with a type check. If the target function's type signature does not match what the call site expects, the kernel stops with an oops instead of making the call.
- FineIBT (Fine-Grained Indirect Branch Tracking): Uses Intel's hardware IBT (Indirect Branch Tracking) feature combined with software checks to validate indirect call targets.
- Shadow Call Stack: Maintains a separate, hidden copy of return addresses. On function return, the kernel checks that the return address on the regular stack matches the shadow copy. This is primarily used on ARM64.
CFI is arguably the sharpest defence against kernel ROP and function pointer overwrite attacks. Even if an attacker corrupts a function pointer, CFI limits where it can actually jump.
Hardware Help: CET, PAC, BTI and MTE
CPU vendors now ship features aimed squarely at these attacks, and kernels are adopting them:
- Intel CET: Linux uses its indirect branch tracking half in the kernel (
CONFIG_X86_KERNEL_IBT, the hardware under FineIBT). Its shadow stack half is used by Linux only for user space so far. Windows goes further and offers a kernel-mode shadow stack ("Kernel-mode Hardware-enforced Stack Protection"), which requires HVCI. - Arm PAC and BTI: on arm64, Linux can sign return addresses with pointer authentication (
CONFIG_ARM64_PTR_AUTH_KERNEL), so an overwritten return address fails its check, and mark valid indirect-branch targets with BTI (CONFIG_ARM64_BTI_KERNEL). - Arm MTE: memory tagging gives each allocation and each pointer a small tag and faults on a mismatch. Linux uses it in-kernel through hardware-tag KASAN (
CONFIG_KASAN_HW_TAGS), cheap enough to catch use-after-free and overflows in production builds.
Windows has its own set of kernel defences. HVCI (memory integrity) uses the hypervisor to keep kernel code pages read-only and only allow signed code to become executable, so even a ring 0 write primitive can't inject new code. kCFG is Control Flow Guard for the kernel's indirect calls, and PatchGuard (Kernel Patch Protection) periodically checks that critical kernel structures and code haven't been modified.
seccomp: Reducing the Attack Surface
seccomp (secure computing mode) is not a mitigation against exploitation itself, but a way to dramatically reduce the kernel attack surface available to a process.
A process can install a seccomp filter (using BPF rules) that restricts which system calls it is allowed to make. For example, a sandboxed process might only be allowed to use read, write, exit, and sigreturn. Any other system call is blocked.
This matters for kernel exploitation because most kernel vulnerabilities are reachable through specific system calls or interfaces. If a sandboxed process cannot call ioctl on a vulnerable device or mount a crafted filesystem, it cannot reach the vulnerable code.
Without seccomp: Process can call any of several hundred syscallsWith seccomp: Process can call only the 10 it was allowedThat's a count of entry points, not a measure of risk: the 10 that remain might include the buggy one, and a single syscall like ioctl fans out into thousands of driver handlers. What the filter reliably does is take whole subsystems off the table.
Chrome, Docker, and Android all use seccomp extensively to sandbox processes and limit kernel exposure.
Slab Hardening
Since many kernel exploits target the slab allocator (especially for use-after-free and heap overflow attacks), the kernel has added several slab hardening features:
- CONFIG_SLAB_FREELIST_RANDOM: Randomises the order of objects in slab caches, making it harder for attackers to predict which memory will be reused after a free.
- CONFIG_SLAB_FREELIST_HARDENED: Adds integrity checks to the freelist pointers, detecting corruption from heap overflows.
- CONFIG_INIT_ON_FREE_DEFAULT_ON: Zeros memory when objects are freed, preventing information leaks from freed objects and making use-after-free exploitation harder.
- Dedicated caches: Critical structures like cred structs can be placed in their own slab caches, isolated from attacker-controllable allocations.
Stack Protections
The kernel uses stack protections similar to user-space programs:
- Stack canaries: A random value placed between local variables and the return address. Checked before function return.
- CONFIG_VMAP_STACK: Allocates kernel stacks using vmalloc with guard pages, so a stack overflow hits an unmapped page and faults instead of silently overwriting adjacent memory.
- Separate stacks: The kernel uses separate stacks for interrupts and exceptions, preventing stack corruption in one context from affecting another.
The Layered Defence Model
No single mitigation is sufficient. KASLR falls to an info leak. SMEP falls to kernel ROP. CFI can sometimes be bypassed with type-confused pointers that satisfy the expected signature check. Each defence forces the attacker to find one more capability, and the cumulative weight makes exploitation genuinely hard.
Lay the mitigations against the stages of an exploit and you can see why one bug rarely gets you there. Each box names the defence that guards a stage and the bypass attackers usually reach for.
A modern kernel exploit typically has to navigate KASLR, SMEP, SMAP, KPTI, CFI, and slab hardening — often requiring multiple chained vulnerabilities. That's why kernel exploit development remains one of the most technically punishing areas of security research.