SLUB Internals: Freelist Poisoning and Heap Overflows


Kernel Exploitation: A CTF Study Path.

Instead of reclaiming with a victim object, attack the allocator itself. Corrupting a free object's next pointer makes SLUB hand out memory at an address you choose. Modern kernels obfuscate that pointer (SLAB_FREELIST_HARDENED) and randomize free lists, so you need leaks and careful heap grooming.

What you will learn

  • SLUB layout: slabs, per-CPU freelists, partial lists, the freelist pointer offset
  • Freelist poisoning on plain and hardened (XOR-obfuscated) freelists
  • Deterministic heap shaping with tiny caches (kmalloc-16/32) and isolated caches
  • Overflowing into adjacent objects in variable-size caches
  • Reverse engineering an unfamiliar module to find the real primitive

Prerequisites

Module 04.

References



Challenges

TCP1P CTF 2024 · difficulty ★★☆☆☆ · module: SLUB Internals: Freelist Poisoning and Heap Overflows

A note driver hands out freed objects of a size you pick; a classic intro to SLUB heap corruption.

Mitigations: SMEP, SMAP, KASLR, KPTI (kernel default; depends on the host CPU)

Running it

Run /challenge/run. It boots the original kernel and root filesystem in QEMU with the serial console on your terminal. Quit with Ctrl-A then X. Put a statically linked exploit at /home/hacker/exploit first; it appears in the VM as /exploit. The flag is /root/flag. The original's user-stage flag (/home/ctf/flag_user.txt, and the argument /home/ctf/run passes to interface) is a placeholder here.

The flag is put where the original challenge kept it, readable only by root in the VM (unless a note above says otherwise). Files in /challenge (kernel, initramfs, sources and the original launcher, where the CTF shipped them): bzImage, rootfs.cpio.gz, run.sh.

Original challenge

Description

F*cK it

The Attachment is the same as K

Connection: 

Points

661

Solves

4

Credits

  • Challenge author(s): rui, for TCP1P CTF 2024
  • Compiled by: mito753 in Kernel-Exploit-Dojo, which also has the original handout and writeups

InCTF 2020 · difficulty ★★★☆☆ · module: SLUB Internals: Freelist Poisoning and Heap Overflows

An XOR-style heap write past the end of a buffer; corrupt the allocator's own metadata to place objects where you want.

Mitigations: KASLR, no SMEP/SMAP (kvm64)

Also uses techniques from: Elastic Objects: msg_msg (06-msg-msg).

Running it

Run /challenge/run. It boots the original kernel and root filesystem in QEMU with the serial console on your terminal. Quit with Ctrl-A then X. Put a statically linked exploit at /home/hacker/exploit first; it appears in the VM as /exploit.

The flag is put where the original challenge kept it, readable only by root in the VM (unless a note above says otherwise). Files in /challenge (kernel, initramfs, sources and the original launcher, where the CTF shipped them): bzImage, rootfs.img, start.sh.

Original challenge

Description

Your secret is safe in ring0 -

Points

989

Solves

5

Credits

  • Challenge author(s): night_f0x, for InCTF 2020
  • Compiled by: mito753 in Kernel-Exploit-Dojo, which also has the original handout and writeups

Bauhinia CTF 2023 · difficulty ★★★☆☆ · module: SLUB Internals: Freelist Poisoning and Heap Overflows

A kernel password manager with a locking problem; beat a hardened freelist to reach a privileged write.

Mitigations: SMEP, SMAP, KPTI, KASLR, oops=panic, SLAB_FREELIST_HARDENED

Also uses techniques from: Races: Double Fetch, userfaultfd and FUSE (08-races).

Running it

Run /challenge/run. It boots the original kernel and root filesystem in QEMU with the serial console on your terminal. Quit with Ctrl-A then X. Put a statically linked exploit at /home/hacker/exploit first; it appears in the VM as /exploit.

The flag is put where the original challenge kept it, readable only by root in the VM (unless a note above says otherwise). Files in /challenge (kernel, initramfs, sources and the original launcher, where the CTF shipped them): bzImage, rootfs.cpio, run.sh.

Original challenge

Description

二百年後在一起 應該不怕旁人不服氣
團圓或者晚了廿個十年 仍然未捨棄
換個時代在一起 等荊棘滿途全枯死
這盼望很悠長 亦決心等到尾 等得起

https://www.youtube.com/watch?v=E9BgBB0JQ8E

I made a simple kernel module to manage my passwords, try it!

Attachment: kernpass_07b5e982ea8891d4d0faa738d3702adf.zip

Note: All pwn challenges are running on an Ubuntu 23.04 machine.

Points

430

Solves

10

Credits

  • Challenge author(s): not recorded (credit goes to the Bauhinia CTF 2023 organizers)
  • Compiled by: mito753 in Kernel-Exploit-Dojo, which also has the original handout and writeups

ASIS CTF Quals 2020 · difficulty ★★★☆☆ · module: SLUB Internals: Freelist Poisoning and Heap Overflows

A note driver terminates your data one byte too late; that single NUL byte lands on a free chunk's freelist pointer.

Mitigations: SMEP, KASLR, KPTI off (pti=off), no SMAP (qemu64)

Also uses techniques from: Arbitrary Read/Write: modprobe_path and Friends (03-arbitrary-rw).

Running it

Run /challenge/run. It boots the original kernel and root filesystem in QEMU with the serial console on your terminal. Quit with Ctrl-A then X. Put a statically linked exploit at /home/hacker/exploit first; it appears in the VM as /exploit.

The flag is put where the original challenge kept it, readable only by root in the VM (unless a note above says otherwise). Files in /challenge (kernel, initramfs, sources and the original launcher, where the CTF shipped them): bzImage, rootfs.cpio, start.sh.

Original challenge

Description

Well, we can tolerate it!

Points

334

Solves

7

Credits

  • Challenge author(s): ptr-yudai, for ASIS CTF Quals 2020
  • Compiled by: mito753 in Kernel-Exploit-Dojo, which also has the original handout and writeups

RCTF 2022 · difficulty ★★★★☆ · module: SLUB Internals: Freelist Poisoning and Heap Overflows

A small game driver mixes up object types; turn a tiny-slab bug into a full read/write primitive.

Mitigations: SMEP, SMAP, KASLR, KPTI (kernel default; depends on the host CPU), oops=panic

Running it

Run /challenge/run. It boots the original kernel and root filesystem in QEMU with the serial console on your terminal. Quit with Ctrl-A then X. Put a statically linked exploit at /home/hacker/exploit first; it appears in the VM as /exploit.

The flag is put where the original challenge kept it, readable only by root in the VM (unless a note above says otherwise). Files in /challenge (kernel, initramfs, sources and the original launcher, where the CTF shipped them): RCTF2022.c, RCTF2022.ko, bzImage, rootfs.cpio, start.sh.

Original challenge

Description

easy kernel pwn
https://share.weiyun.com/GZLRF9Kt
https://drive.google.com/file/d/1smjX_b-8uuikimQugasUx9dBRgNek7Rs/view?usp=sharing

Challenges Hints:
新增服务器

Points

Unknown

Solves

Unknown

Credits

  • Challenge author(s): not recorded (credit goes to the RCTF 2022 organizers)
  • Compiled by: mito753 in Kernel-Exploit-Dojo, which also has the original handout and writeups

nullcon HackIM 2022 · difficulty ★★★★☆ · module: SLUB Internals: Freelist Poisoning and Heap Overflows

A banking driver keeps a pointer it should have forgotten; bend the allocator to your will.

Mitigations: SMEP, no SMAP, KASLR, KPTI, oops=panic

Running it

Run /challenge/run. It boots the original kernel and root filesystem in QEMU with the serial console on your terminal. Quit with Ctrl-A then X. Put a statically linked exploit at /home/hacker/exploit first; it appears in the VM as /exploit.

The flag is put where the original challenge kept it, readable only by root in the VM (unless a note above says otherwise). Files in /challenge (kernel, initramfs, sources and the original launcher, where the CTF shipped them): bank.c, bzImage, initramfs.cpio.gz, run.sh.

Original challenge

Description

After recent security breaches we at ENO-Bank have decided to move our services into kernel land for higher security !

Points

500

Solves

Unknown

Credits

  • Challenge author(s): h0ps, for nullcon HackIM 2022
  • Compiled by: mito753 in Kernel-Exploit-Dojo, which also has the original handout and writeups

Azure Assassin Alliance CTF 2023 · difficulty ★★★★★ · module: SLUB Internals: Freelist Poisoning and Heap Overflows

A netlink-driven message board compresses your data into a buffer that is not always big enough.

Mitigations: SMEP, SMAP, KASLR, KPTI (kernel default; depends on the host CPU), oops=panic

Running it

Run /challenge/run. It boots the original kernel and root filesystem in QEMU with the serial console on your terminal. Quit with Ctrl-A then X. Put a statically linked exploit at /home/hacker/exploit first; it appears in the VM as /exploit. The handout has both /flag and /root/flag; both hold the real flag here.

The flag is put where the original challenge kept it, readable only by root in the VM (unless a note above says otherwise). Files in /challenge (kernel, initramfs, sources and the original launcher, where the CTF shipped them): bzImage, rootfs.cpio.gz, run.sh.

Original challenge

Description

Tired with the misc device driver? Let’s try something different.

Service

Points

952

Solves

2

Credits

  • Challenge author(s): f0rm2l1n, for Azure Assassin Alliance CTF 2023
  • Compiled by: mito753 in Kernel-Exploit-Dojo, which also has the original handout and writeups

30-Day Scoreboard:

This scoreboard reflects solves for challenges in this module after the module launched in this dojo.

Rank Hacker Badges Score