mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
159 lines
5.7 KiB
Python
159 lines
5.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Observe original ACR parent allocation-boundary ABI in isolated private RAM."""
|
|
import argparse
|
|
from pathlib import Path
|
|
import struct
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / "tools"))
|
|
from _falcon_acr_oracle_elf import ( # noqa: E402
|
|
GPU,
|
|
TEXT,
|
|
OracleUnicornHarness,
|
|
discover_rm_object,
|
|
load_relocated_rm_object,
|
|
write_or_check_json,
|
|
)
|
|
|
|
|
|
def main(argv=None) -> int:
|
|
parser = argparse.ArgumentParser(
|
|
description="Run or verify ACR parent package allocation-boundary oracle."
|
|
)
|
|
parser.add_argument("--rm-object", type=Path, default=None)
|
|
parser.add_argument("--check", action="store_true")
|
|
opt = parser.parse_args(argv)
|
|
|
|
loaded = load_relocated_rm_object(discover_rm_object(opt.rm_object))
|
|
cpu_image = GPU + 0x30000
|
|
metadata = GPU + 0x50000
|
|
production = GPU + 0x51000
|
|
debug = GPU + 0x52000
|
|
patch = GPU + 0x53000
|
|
index = GPU + 0x54000
|
|
state = {"image_size": 0, "debug_mode": False, "observed": []}
|
|
|
|
def on_custom(harness, emu, name):
|
|
x86 = harness.x86
|
|
if name == "prepared_image_leaf":
|
|
destination = emu.reg_read(x86.UC_X86_REG_RCX)
|
|
info = bytearray(0x70)
|
|
struct.pack_into("<I", info, 0, state["image_size"])
|
|
struct.pack_into("<Q", info, 8, cpu_image)
|
|
struct.pack_into("<Q", info, 0x30, metadata)
|
|
struct.pack_into("<Q", info, 0x38, production)
|
|
struct.pack_into("<Q", info, 0x40, debug)
|
|
struct.pack_into("<Q", info, 0x48, patch)
|
|
struct.pack_into("<Q", info, 0x50, index)
|
|
struct.pack_into("<I", info, 0x58, 16)
|
|
struct.pack_into("<I", info, 0x5C, 1)
|
|
emu.mem_write(destination, bytes(info))
|
|
harness.ret()
|
|
return True
|
|
if name == "completed_wpr_gather_leaf":
|
|
harness.ret()
|
|
return True
|
|
if name == "debug_read_leaf":
|
|
harness.ret(int(state["debug_mode"]) << 20)
|
|
return True
|
|
if name == "descriptor_create_boundary":
|
|
sp = emu.reg_read(x86.UC_X86_REG_RSP)
|
|
args = [
|
|
emu.reg_read(r)
|
|
for r in (
|
|
x86.UC_X86_REG_RSI,
|
|
x86.UC_X86_REG_RDX,
|
|
x86.UC_X86_REG_RCX,
|
|
x86.UC_X86_REG_R8,
|
|
x86.UC_X86_REG_R9,
|
|
)
|
|
] + [int.from_bytes(emu.mem_read(sp + 8 + i * 8, 8), "little") for i in range(2)]
|
|
state["observed"].append(args)
|
|
harness.ret(7)
|
|
return True
|
|
return False
|
|
|
|
harness = OracleUnicornHarness(loaded, custom_handler=on_custom)
|
|
acr = GPU + 0x810000
|
|
selector = GPU + 0x820000
|
|
harness.uc.mem_map(acr, 0x2000)
|
|
harness.uc.mem_map(selector, 4096)
|
|
harness.uc.mem_write(selector + 0x10, struct.pack("<H", 35))
|
|
harness.uc.mem_write(selector + 0x30, struct.pack("<H", 2))
|
|
harness.call("_nv005947rm", [acr, selector])
|
|
harness.call("_nv005809rm", [acr, selector, selector + 0x20])
|
|
|
|
pmu = GPU + 0x8000
|
|
memory = GPU + 0x9000
|
|
harness.uc.mem_write(GPU + 0x2120, struct.pack("<Q", pmu))
|
|
harness.uc.mem_write(GPU + 0x22C8, struct.pack("<Q", memory))
|
|
harness.uc.mem_write(pmu + 0x3D8, struct.pack("<Q", TEXT + harness.defined["_nv052308rm"]))
|
|
for target, tag in (
|
|
(cpu_image, "26"),
|
|
(metadata, "1a"),
|
|
(production, "3d"),
|
|
(debug, "39"),
|
|
(patch, "3b"),
|
|
(index, "3a"),
|
|
):
|
|
harness.uc.mem_write(
|
|
target, (ROOT / f"analysis/acr-580/11430c8-{tag}.decoded").read_bytes()
|
|
)
|
|
for fn, hook_name in (
|
|
("_nv016905rm", "prepared_image_leaf"),
|
|
("_nv016753rm", "completed_wpr_gather_leaf"),
|
|
("_nv053907rm", "debug_read_leaf"),
|
|
("_nv043694rm", "descriptor_create_boundary"),
|
|
("_nv046747rm", "diagnostic_leaf"),
|
|
):
|
|
harness.hooks[TEXT + harness.defined[fn]] = hook_name
|
|
|
|
cases = []
|
|
for image_size in (18176, 18177, 256, 257):
|
|
for debug_mode in (False, True):
|
|
state["image_size"] = image_size
|
|
state["debug_mode"] = debug_mode
|
|
state["observed"] = []
|
|
status = harness.call("_nv016741rm", [GPU, acr, 1, 0])
|
|
if status != 7:
|
|
raise SystemExit(f"Expected status 7 at allocation boundary, got {status:#x}")
|
|
expected = [GPU, (image_size + 255) & ~255, 256, 1, 2, 1, 0]
|
|
if state["observed"] != [expected]:
|
|
raise SystemExit(
|
|
f"Unexpected create arguments {state['observed']}, expected {[expected]}"
|
|
)
|
|
cases.append(
|
|
{
|
|
"declared_image_bytes": image_size,
|
|
"debug_mode": debug_mode,
|
|
"original_create_arguments": state["observed"][0][1:],
|
|
"executed_status_at_allocation_boundary": 7,
|
|
}
|
|
)
|
|
|
|
report = {
|
|
"artifact_sha256": loaded["digest"],
|
|
"cases": cases,
|
|
"original_parent": "016741",
|
|
"required_preconditions_scripted": [
|
|
"already decoded mode1 image/metadata/signature owner016905",
|
|
"completed WPR gather016753",
|
|
],
|
|
"actual_original_signature_patch": "016965+052308+016945",
|
|
"purpose": "observe original complete argument ABI at first realFBMEM allocation call; NOT full bootstrap execution",
|
|
"physical_gpu_access": False,
|
|
}
|
|
write_or_check_json(
|
|
ROOT / "reports/gpu-acr-parent-package-oracle.json",
|
|
report,
|
|
opt.check,
|
|
"ACR parent package oracle report",
|
|
)
|
|
print(len(cases), "original parent allocation-boundary cases")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|