Heap UAF: Reclaiming Freed Objects


Kernel Exploitation: A CTF Study Path.

Kernel heap bugs become useful when the freed or overflowed memory is reused by a kernel object that contains pointers. Classic victims are tty_struct (opened via /dev/ptmx, kmalloc-1024) and seq_operations (opened via /proc/self/stat, kmalloc-32): leak their pointers to break KASLR, then overwrite them to hijack control flow or build a write primitive.

What you will learn

  • How kmalloc size classes work and which objects share a cache with your bug
  • Heap spraying and reclaiming a freed slot with a victim object
  • Leaking KASLR from function-pointer tables (tty_operations, seq_operations)
  • Fake vtables and turning a single indirect call into a write or a ROP pivot
  • Double frees and overlapping objects; data-only reclaim when there is no function pointer to hijack

Prerequisites

Modules 01-03.

References



Challenges

UIUCTF 2025 · difficulty ★☆☆☆☆ · module: Heap UAF: Reclaiming Freed Objects

Allocate, free, keep using: the friendliest UAF there is. Reclaim it with a tty_struct and take over its ops.

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 original /init writes a test flag to /flag.txt when its 9p flag share is missing (always, here); init.dojo skips that so your real flag stays.

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, init.dojo, initrd.cpio.gz, run.sh, vuln.c, vuln.ko.

Original challenge

Description

Points

95

Solves

53

Credits

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

TSJ CTF 2022 · difficulty ★☆☆☆☆ · module: Heap UAF: Reclaiming Freed Objects

A kernel clipboard frees buffers a bit too eagerly; a classic first heap-UAF challenge.

Mitigations: SMEP, SMAP, KASLR (kernel default), 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): bzImage, initramfs.cpio.gz, run.sh.

Original challenge

Description

Richard Stallman: Created the GNU Project and developed some of the most widely used software including GCC, GDB, GNU Emacs.

Linux Torvalds: Main developer of the Linux kernel and created the Git version control system.

Terry Davis: Created a lightweight operating system TempleOS including an original compiler, language, kernel, and graphics library.

Me: Spent two weeks creating a shitty clipboard kernel module, which contains a vulnerability that allows a local attacker to escalate privileges and execute arbitrary code.

Hint

I don't play ticktock. I play tocttou.

Points

469

Solves

2

Credits

  • Challenge author(s): @wxrdnx, for TSJ CTF 2022
  • Compiled by: mito753 in Kernel-Exploit-Dojo, which also has the original handout and writeups

N1CTF 2025 · difficulty ★☆☆☆☆ · module: Heap UAF: Reclaiming Freed Objects

Logic bugs let the kernel write where it should not; the target may be closer to userland than you expect.

Mitigations: SMEP, SMAP, KPTI, KASLR, dmesg_restrict, kptr_restrict

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. /home/hacker/exploit is not copied into this VM. There is no shell: the console runs the menu program /home/ctf/user as ctf, which keeps its data in the ktou kernel module. Unlike most challenges here the goal is not root: /home/ctf/flag links to the flag disk /dev/vda, which the boot script makes readable by ctf, so code execution inside the menu program is enough. Your only input is the menu on the console: there is no file upload. The root filesystem is an ext4 disk (rootfs.img.gz, decompressed into a private copy at every start; the original is 128 MiB, over the size limit for a repository file); disk changes are discarded when the VM stops.

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, ktou.ko, rootfs.img.gz, run.sh.

Original challenge

Description

It's still simple, but where's the difference?

Points

126

Solves

38

Credits

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

zer0pts CTF 2020 · difficulty ★★☆☆☆ · module: Heap UAF: Reclaiming Freed Objects

A memo driver that reads and writes a little past its buffer; find a juicy neighbouring object.

Mitigations: SMEP, SMAP, KASLR

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, memo.c, rootfs.cpio, start.sh.

Original challenge

Description

$ echo Jot down your ideas > /dev/memo && cat /dev/memo 

Points

732

Solves

9

Credits

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

Union CTF 2021 · difficulty ★★☆☆☆ · module: Heap UAF: Reclaiming Freed Objects

A size calculation that goes negative in the wrong place; use heap neighbours for both a leak and a write.

Mitigations: SMEP, SMAP, KASLR

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, initramfs.cpio, start.sh.

Original challenge

Description

My favourite part of a nut? The kernel.

Points

884

Solves

10

Credits

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

PatriotCTF 2025 · difficulty ★★☆☆☆ · module: Heap UAF: Reclaiming Freed Objects

A switchboard driver forgets to hang up dangling connections; a gentle introduction to reclaiming a freed small object.

Mitigations: SMEP, SMAP, KASLR, KPTI

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, initramfs.cpio.gz, launch.sh, switchboard.c.

Original challenge

Description

Your standard SLAB notetaking app!

Points

453

Solves

53

Credits

  • Challenge author(s): Dylan Knoff, for PatriotCTF 2025
  • Compiled by: mito753 in Kernel-Exploit-Dojo, which also has the original handout and writeups

GACTF 2020 · difficulty ★★☆☆☆ · module: Heap UAF: Reclaiming Freed Objects

A driver that lets you free things on your terms; reclaim the freed memory with a kernel object that holds function pointers.

Mitigations: SMEP, KASLR

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 VM powers off 120 seconds after boot, as in the original.

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, forest.diff, rootfs.img, start.sh.

Original challenge

Description

Do you want to challenge Boss?Yeah, you must get out of this forest,
and I am the king of the forest.

hint:
cve-2018-5333

URL
China:119.3.156.29 9876
Overseas:149.248.16.204 9876

Points

1000

Solves

1

Credits

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

TFC CTF 2025 · difficulty ★★☆☆☆ · module: Heap UAF: Reclaiming Freed Objects

Slots of a size you choose can be used after free; a classic kernel object is waiting to take their place.

Mitigations: KASLR, SLUB freelist random, SLUB freelist hardened

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. slot_machine.ko reads /flag when it is loaded and /init then deletes the file, so the flag only lives in kernel memory.

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, config, initramfs.cpio.gz, run.sh, vmlinux.gz.

Original challenge

Description

gambling cha ching

Points

155

Solves

28

Credits

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

CrewCTF 2022 · difficulty ★★★☆☆ · module: Heap UAF: Reclaiming Freed Objects

A driver whose internal state can drift out of sync; make the allocator hand out the same memory twice.

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

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, service.sh.

Original challenge

Description

I heard you like kernel pwn?

Points

957

Solves

6

Credits

  • Challenge author(s): K4Fr#7740, for CrewCTF 2022
  • Compiled by: mito753 in Kernel-Exploit-Dojo, which also has the original handout and writeups

Hack.lu CTF 2021 · difficulty ★★★☆☆ · module: Heap UAF: Reclaiming Freed Objects

A custom socket option on a stock Ubuntu kernel; race its lifetime handling to call a function of your choice.

Mitigations: KASLR, no SMEP/SMAP (default CPU), flag at /mnt/flag in the initramfs (the original mounted a flag disk there)

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 your payload at /home/hacker/exploit first; it is attached to the VM as a raw disk, as in the original challenge. There is no shell. Your exploit is a 'bot' (a script or static ELF, at most 10 MiB): it is copied to /bot and run as nobody; its output is all you see, and the VM powers off when it exits. The flag is /mnt/flag. The flag is put at /mnt/flag in the initramfs (the original mounted a flag disk there), so the boot message mount: mounting /dev/sda on /mnt failed: Invalid argument is expected: /dev/sda is an empty placeholder disk.

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): build.sh, initramfs.cpio.gz, module/Makefile, module/dockerfile, module/stonks_socket.c, module/stonks_socket.ko, run_chall.sh, vmlinuz-5.11.0-38-generic.

Original challenge

Description

The bigo hedge fund Whiterock is testing it's new trading bot cloud and we got exclusive beta access. Big news is the addition of extra "secürety" features for TCP connections. We could "convince" one of their employees to provide the source code for the new features.

Access is available at flu.xxx 20020

Points

353

Solves

12

Credits

  • Challenge author(s): Diff-fusion, for Hack.lu CTF 2021
  • Compiled by: mito753 in Kernel-Exploit-Dojo, which also has the original handout and writeups

HITCON CTF 2020 · difficulty ★★★★☆ · module: Heap UAF: Reclaiming Freed Objects

A graph driver that links nodes without counting references; reclaim a freed node and abuse the shortest-path query.

Mitigations: KASLR, no SMEP/SMAP (qemu64)

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 shell is killed 60 seconds after boot, as in the original.

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, demo.c, demo.gz, initramfs.cpio.gz, run.sh, spark.ko.

Original challenge

Description

Shortest Path AlgoRithm in Kernel!

Points

334

Solves

10

Credits

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

ASIS CTF Quals 2025 · difficulty ★★★★☆ · module: Heap UAF: Reclaiming Freed Objects

A driver lets you read and set the private_data pointer of any regular file you have open. Find a file whose kernel code trusts that pointer.

Mitigations: SMEP, SMAP, KASLR, slab_nomerge, 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. /home/hacker/exploit is not copied into this VM. The root filesystem is an ext4 disk, so there is no initramfs to add files to: transfer your exploit over the console (for example base64). The flag is the raw disk /dev/sdb (root only); disk changes are discarded when the VM stops.

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): Dockerfile, bzImage, rootfs.ext4, run.sh, vuln.c.

Original challenge

Description

Files can be numbered using this kernel module! Also download the vulnerable code!


Special thanks to the author, ptr-Yudai!

Points

316

Solves

8

Credits

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

THJCC CTF 2026 · difficulty ★★★★☆ · module: Heap UAF: Reclaiming Freed Objects

Make a contract with one out-of-bounds byte; the file permission check is not the only thing guarding a file.

Mitigations: SMEP, SMAP, KPTI, panic_on_warn=1

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 your payload at /home/hacker/exploit first; it is attached to the VM as a raw disk, as in the original challenge. /init copies it to /tmp/e (padded with zeros to whole 512-byte sectors).

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, initramfs.cpio, run.sh.

Original challenge

Description

Do you like QB?! ~ ☆

(Please solve this challenge locally before connecting to the remote server.)

Notice

The main files to focus on for this challenge are located in the src/challenge/ directory. When you connect to the server, it will require solving a PoW. The PoW solver script is located at solver/solve_pow.py. After solving PoW, the server will ask if you want to upload your exploit — provide the URL of your exploit file to do so. When QEMU startup, you can find your exploit at /tmp/e. If you have any problem about linux kernel challenge environment, please refer to the challenge others source code.

Points

500

Solves

3

Credits

  • Challenge author(s): naup96321, for THJCC CTF 2026
  • 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