aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoruser <user@clank>2026-09-23 16:04:23 +0200
committeruser <user@clank>2026-09-23 16:04:23 +0200
commite9a5ba68b8a647c22d46cf4bcbdf56c890e1513d (patch)
tree9e338bfa344d8a49e78c3914156b6511c97cf0dd
parentAdd the card's own TAs and show HDCP/DTM findings reproduce on them (diff)
downloadamd-psp-re-e9a5ba68b8a647c22d46cf4bcbdf56c890e1513d.tar.gz
amd-psp-re-e9a5ba68b8a647c22d46cf4bcbdf56c890e1513d.tar.xz
amd-psp-re-e9a5ba68b8a647c22d46cf4bcbdf56c890e1513d.zip
Cover ASD on the card's build: resolve its dispatcher and validate_ptr
ASD needed two things HDCP/DTM did not, because it is not a GP TA. Dispatcher. Its trampoline is ARM code carrying the RPC dispatcher pointer at +0x1C with the Thumb bit set, not a create/invoke pair at +0xA0/+0xB0 -- which is exactly why the generic resolver returned zeros and ASD was left uncovered. resolve_asd() handles it. Checked across all 12 ASD builds in psp_out/elf: the trampoline moves from 0xD125D4 to 0xD19868, the four stub words are identical every time, and the dispatcher is 0xD013B8 in every single one, referenced once per image. It is still READ from the image rather than hardcoded, so a build that moves it gets detected instead of silently mis-driven, and a corrupted stub is refused (negative control included). asd_validate_ptr. fuzz_asd hardcoded 0xD12E90, so pointing it at any other build fetched from address 0 -- the first attempt at the card's ASD died exactly that way. It now resolves by signature with a UNIQUE-match requirement: one hit in each of the 12 builds, 0xD0FF08 on the card's 33.0.0.217, and 0xD12E90 recovered for the default image, which the harness now prints as an explicit agreement check so a resolver regression is visible. Worth recording: I first typed that signature into the source by hand and it matched ZERO builds, including the one I copied it from. The unique-match rule turned a transcription error into a loud refusal rather than a silent mis-resolution; had it taken "first hit" or fallen back to the hardcoded value, it would have looked like it worked. The bytes are now taken from the image programmatically. Results against the card's ASD 33.0.0.217 (ours is 33.0.1.21, a different branch), each gated on the trampoline read from the emulator's own memory: fuzz_asd 938 -> 967 blocks, identical 395 ok / 5 scalar_deref_noise asd_rpc same return values (0x0/0x2/0x103), 30 -> 31 blocks load_asd 76 blocks, 2/2 negative controls still reject load_asd is the strongest: it takes the card's SIGNED 0x2F100 container straight from the firmware blob, runs it through the firmware's own loader, and the RSA signature verification passes while both bit-flip controls are still rejected. The card's real ASD verifies and executes, entering at the same 0xD01188/0xD011A8/0xD013B8 sequence as ours. All four TAs the card loads are now covered. Suite green.
-rw-r--r--psp_emu/README.md2
-rw-r--r--psp_emu/harness/fuzz_asd.py20
-rw-r--r--psp_emu/pspemu/ta_entries.py80
-rw-r--r--psp_out/HW-TA-VERSION-REPRODUCTION.md42
4 files changed, 138 insertions, 6 deletions
diff --git a/psp_emu/README.md b/psp_emu/README.md
index c77dd32..72500d4 100644
--- a/psp_emu/README.md
+++ b/psp_emu/README.md
@@ -249,7 +249,7 @@ result.
| sOS gate semantics | **region validation modelled and validated** (`pspemu/gate.py`, `harness/sos_gate.py`); **DACR switch was already modelled** — the old "not modelled" claim is retracted; async dispatch still absent | `sos_check_user_ptr` (FA 0x178C) and `sos_check_user_range` (FA 0x191C) are reimplemented and differentially tested against the firmware: **292/292 cases agree**, and the differential is shown to catch a deliberately wrong model (the old always-succeed behaviour is caught on 18/84 pointer cases). The gate is enforced in the RPC path, not inert: out-of-window request pointers get the firmware's own 0xA and the service never runs, while a real HDCP invoke has 0 of its own requests rejected. `config['gate']=False` restores the old behaviour, `config['proc_type']=4` models a privileged caller. `check_range` is validated to the same standard but deliberately **not** applied generically — knowing which request fields are buffers is service-specific, and guessing would invent semantics; on the one path where the layout is known (SYS_DRV RPC) the firmware's own `sub_E0DEF4` and `sub_E0AB44` run unpatched in `sysdrv_bridge.py`, so range checking there is faithful by execution. **DACR**: the row used to claim no domain switch. That was a stale restatement of a claim FIDELITY-NOTES.md had already retracted — the MMU is enabled and domains are live. Measured both ways: the emulator really enforces domains (domain=no-access faults, client+AP=0 faults, manager reads — positive control passes), and sOS's own `mcr p15,0,rX,c3,c0,0` sites execute **3944 times in a bounded boot** (86501/86500 paired entry/exit in a full run). **Async dispatch**: also measured rather than assumed, and the old "not modelled" claim is retracted for the full-system harnesses — sOS's own scheduler runs there, creating **22 tasks** with **24008 reschedules** and **8 stacks busy enough to carry >1000 blocks each**, which is real context switching, not one thread. It remains genuinely absent *component-level*, where there is no sOS and an SVC completes synchronously inside the handler. All four properties are re-checked on every `harness/sos_gate.py` run, each with a failure mode that reports NOT REPORTABLE rather than a vacuous pass. |
| persistence | **modelled** — `fuzz_hdcp` keeps TA state across iterations by default (`HDCP_PERSIST=0` restores the old wipe); still a fresh `Component` per *harness run* | hardware keeps TA globals for a whole boot, which is exactly what the cmd 0x0F latch exploits. Measured over 1500 iterations: persistence gains ~9% HDCP coverage (767 -> 839 distinct blocks) and the run now ends with sessions genuinely latched (`err_state` 7), reproducing the one-shot behaviour. CANARY_SMASH drops 46 -> 7 because the latch stops subcmd12 being reached — that is the latch being modelled, not lost bug-finding. |
| DTM / RAS | **DTM driven** (`harness/dtm_ras.py`): commands 2/3/4 through the real GP invoke entry, with negative controls. **RAS blocked** on an init gate | DTM could not have been driven before: `loader.resolve` picked `elf/dtm2.elf`, which carries the full image (0x2100, header+body) but declares the body-only base `p_vaddr=0x400100`, so everything landed 0x100 high and all five GP entry points resolved into the container header's zero padding. Now uses `elf/dtm.elf` (same build, correct base). RAS gates every command on a byte at 0x4060e0. Traced: the only store to it is inside `TA_OpenSessionEntryPoint`, guarded on an inner call chain that bottoms out in **SVC 0xF2 service 1 -- the SYS_DRV RPC** (opcodes 0x0001/0x000d/0x0002/0x1077, measured). So RAS is blocked on SYS_DRV RPC *responses*, not a mystery flag; component-level, service 1 is bound to CryptoService, the wrong service. Routing it into a real SYS_DRV the way `Bus.route_asd` does for ASD is the fix, and is now tractable because `sysdrv_env` opens SYS_DRV's own init gate for real. Command coverage explicitly not reported until then. |
-| TA image versions vs silicon | **RAS matches the card byte-for-byte; HDCP/DTM/ASD do not** | Checked against an RX 7900 XTX's `psp_13_0_0_ta.bin`. Our `ras2.elf` body is bit-identical to the card's RAS 27.0.2.5 (`db2ed53e...b58385`), so RAS findings apply to that silicon directly. The card runs HDCP **23.0.0.63**, DTM 18.0.0.22, ASD 33.0.0.217 — none of which are the images in this tree (we do not hold .63 at all; `vdiff` has .49/.70/.82). **Caveat now discharged for HDCP and DTM**: the card's own builds were extracted into `elf/hdcp_23.0.0.63_edab4e4f.elf`, `elf/dtm_18.0.0.22_adbf8c8b.elf`, `elf/asd_33.0.0.217_c4c1e5bc.elf`, and re-running `hdcp_cmd0f`, `hdcp_subcmd12` and `dtm_ras` against them gives **identical output** except the PC of one sentinel fault (`0x40433c` → `0x4042b4`, same code at a different link address). `fuzz_hdcp` runs comparably (817 vs 815 blocks). Entry points are resolved from the image by `pspemu/ta_entries.py` (validated 3/3 against known builds) rather than hardcoded. **ASD is not covered** — the resolver does not handle its header layout. Not in SPI flash, incidentally: `spi_parse.py` finds no TA entries at all, and the PSP images that are there are `enc_option=1` encrypted. See `psp_out/HW-VALIDATION-RX7900XTX.md` and `psp_out/HW-TA-VERSION-REPRODUCTION.md`. |
+| TA image versions vs silicon | **RAS matches the card byte-for-byte; HDCP/DTM/ASD do not** | Checked against an RX 7900 XTX's `psp_13_0_0_ta.bin`. Our `ras2.elf` body is bit-identical to the card's RAS 27.0.2.5 (`db2ed53e...b58385`), so RAS findings apply to that silicon directly. The card runs HDCP **23.0.0.63**, DTM 18.0.0.22, ASD 33.0.0.217 — none of which are the images in this tree (we do not hold .63 at all; `vdiff` has .49/.70/.82). **Caveat now discharged for HDCP and DTM**: the card's own builds were extracted into `elf/hdcp_23.0.0.63_edab4e4f.elf`, `elf/dtm_18.0.0.22_adbf8c8b.elf`, `elf/asd_33.0.0.217_c4c1e5bc.elf`, and re-running `hdcp_cmd0f`, `hdcp_subcmd12` and `dtm_ras` against them gives **identical output** except the PC of one sentinel fault (`0x40433c` → `0x4042b4`, same code at a different link address). `fuzz_hdcp` runs comparably (817 vs 815 blocks). Entry points are resolved from the image by `pspemu/ta_entries.py` (validated 3/3 against known builds) rather than hardcoded. **ASD now covered too**: `resolve_asd()` reads its dispatcher from trampoline `+0x1C` (validated across 12 builds, all 0xD013B8, corrupted stub refused), and `fuzz_asd` resolves `asd_validate_ptr` by unique-match signature instead of the hardcoded 0xD12E90 that made it fetch from 0 on other builds. Against the card's ASD 33.0.0.217: `fuzz_asd` 967 vs 938 blocks with the same 395 ok / 5 noise split, `asd_rpc` same return values, and `load_asd` puts the card's **signed** container through the firmware's own loader — RSA check passes, 76 blocks, both bit-flip controls still rejected. Not in SPI flash, incidentally: `spi_parse.py` finds no TA entries at all, and the PSP images that are there are `enc_option=1` encrypted. See `psp_out/HW-VALIDATION-RX7900XTX.md` and `psp_out/HW-TA-VERSION-REPRODUCTION.md`. |
| ring status codes vs silicon | **7/9 exact** | `GET_FW_ATTESTATION`→0x0, unknown ids (0x00/0x55/0x99/0xfe/0x1000)→0x100, `INVOKE_CMD`→0x117 all match hardware exactly. `LOAD_TA` (hw 0x5 vs emu 0x116) and `UNLOAD_TA` (hw 0x117 vs emu 0x11a) differ, but those are the only state-dependent paths and the ring harness has no TMR or loaded TAs — **not** reportable as firmware divergence. Inputs were equalised first. |
| timing / concurrency | **task scheduling is modelled** in the full-system harnesses (retracting "none"); *timing* fidelity is still approximate | "no preemption or task scheduling" was wrong in the same way the DACR row was: sOS's own scheduler executes, and `harness/sos_gate.py` measures it every run — 22 tasks created, 24008 `svc_60_reschedule` calls, 8 busy stacks. A timer FIQ is installed and does interrupt execution, so tasks that sleep genuinely wake. What is *not* claimed: the scheduler is cooperative in sOS's own design, so this is not evidence of preemptive time-slicing, and **timing remains approximate** — `TIMER_PERIOD` defaults to 200 rather than hardware's 2000, which makes the emulated CPU slower relative to guest time (pin `TIMER_PERIOD=2000` if a finding depends on timing). Component-level harnesses remain single-threaded and synchronous. |
| SVC permission gate | **modelled and validated** — `gate.check_svc`, enforced in `SvcDispatcher` | `sos_svc_dispatch` (FA 0x587C) is not a bare jump table: it checks the SVC against the calling process's entry in the same table `check_ptr` uses and denies with **0xE** before any handler runs. Rule: `svc <= 0xDF` denied if `(proc_byte & 0xF)` is 5 or 6 and `svc != 0x75`; `0xE0..0xEF` denied unless `proc_byte & 0x20`; `> 0xEF` unchecked. Differentially tested against the real dispatcher with handler bodies stopped at entry so no side effects confuse it: **140/140 agree, 46 of them actual denials**. Live in the dispatcher: an ordinary process has 0 of 279 SVCs denied, a type-5 process 47 of 167. `config['proc_byte']` selects the class; `config['svc_gate']=False` restores the old unconditional behaviour. |
diff --git a/psp_emu/harness/fuzz_asd.py b/psp_emu/harness/fuzz_asd.py
index 770da40..6833310 100644
--- a/psp_emu/harness/fuzz_asd.py
+++ b/psp_emu/harness/fuzz_asd.py
@@ -25,7 +25,14 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from pspemu import Component, consts # noqa: E402
DISPATCH = consts.ASD["dispatcher"] # 0xD013B8
-VALIDATE = 0xD12E90 # asd_validate_ptr
+# asd_validate_ptr. Resolved from the image, not hardcoded: it moves between
+# builds (0xD0C9F8 .. 0xD12E90 across the 12 images in psp_out/elf), so a
+# hardcoded address makes this harness fetch from 0 the moment it is pointed at
+# another build -- e.g. the card's own ASD 33.0.0.217, where it lives at
+# 0xD0FF08. ta_entries.find_asd_validate requires a UNIQUE signature match and
+# raises otherwise, so a build it cannot place is an error rather than a guess.
+# 0xD12E90 is kept only as the expected answer for the default image.
+VALIDATE_DEFAULT = 0xD12E90
FEATURE = 0xD116AC # asd_feature_enabled (no longer patched)
RXID_BUF = consts.ASD["rxid_buf"] # 0xD1F038
RET1 = bytes([0x01, 0x20, 0x70, 0x47]) # MOVS R0,#1 ; BX LR
@@ -47,6 +54,8 @@ class AsdFuzzer:
def __init__(self, seed=0):
self.rng = random.Random(seed)
c = self.c = Component("asd")
+ from pspemu import ta_entries
+ self.validate = ta_entries.find_asd_validate(c)
c.svc.register(0xF2, lambda comp, n: 0) # crypto / nested RPC
c.svc.register(0x8D, lambda comp, n: 0x31) # ASIC id
c.svc.register(0x5E, lambda comp, n: 0)
@@ -94,12 +103,12 @@ class AsdFuzzer:
# say so. Two directions, because "accepts our buffers" alone is also
# true of a stub that accepts everything.
for b in self.bufs:
- if not c.run_function(VALIDATE, (b, 0x2000, 0, 0)):
+ if not c.run_function(self.validate, (b, 0x2000, 0, 0)):
raise RuntimeError(
"asd_validate_ptr rejects argument buffer %#x; it must live"
" in the caller window %#x..%#x" % (b, CALLER_WINDOW,
CALLER_WINDOW + CALLER_WINDOW_SZ))
- if c.run_function(VALIDATE, (0x00D70000, 0x2000, 0, 0)):
+ if c.run_function(self.validate, (0x00D70000, 0x2000, 0, 0)):
raise RuntimeError(
"asd_validate_ptr accepted ASD scratch (0xD70000) -- it has been"
" stubbed out, so pointer arguments are no longer gated and any"
@@ -187,6 +196,11 @@ def main(iters=5000, seed=1):
for _ in range(iters):
f.run_one()
print("ASD fuzz: iterations=%d seed=%d" % (iters, seed))
+ print(" asd_validate_ptr resolved to %#x%s"
+ % (f.validate,
+ " (== the expected address for the default image)"
+ if f.validate == VALIDATE_DEFAULT else
+ " (NOT the default image's %#x -- a different ASD build)" % VALIDATE_DEFAULT))
unh = sorted({n for n, _s in f.c.svc.unhandled if isinstance(n, int)})
if unh:
print(" QUALIFIED: %d SVC(s) answered with a fabricated 0: %s"
diff --git a/psp_emu/pspemu/ta_entries.py b/psp_emu/pspemu/ta_entries.py
index 64c960e..8c949da 100644
--- a/psp_emu/pspemu/ta_entries.py
+++ b/psp_emu/pspemu/ta_entries.py
@@ -48,6 +48,57 @@ def resolve(comp, base=0x400100):
return tramp, create & ~1, invoke & ~1
+# ---------------------------------------------------------------------- ASD
+#
+# ASD is not a GP TA: it has no TA_Create/TA_Invoke pair at trampoline+0xA0/0xB0
+# (those read as 0, which is why the generic resolver reports "does not apply"
+# rather than returning them). Its trampoline is ARM code, and the RPC
+# dispatcher pointer sits at +0x1C with the Thumb bit set:
+#
+# trampoline+0x00 e1a00002 mov r0, r2
+# trampoline+0x04 e59fc010 ldr ip, [pc, #0x10]
+# trampoline+0x08 e12fff3c blx ip
+# trampoline+0x0c ef000075 svc #0x75
+# trampoline+0x10 <__stack_chk_guard value>
+# trampoline+0x1c -> asd dispatcher | 1
+#
+# Checked across all 13 ASD builds in psp_out/elf: the trampoline address moves
+# from 0xD125D4 to 0xD19868, the four stub words are identical every time, and
+# the dispatcher is 0xD013B8 in every single one, referenced exactly once in the
+# image. So the dispatcher is a fixed ABI address, but it is still READ from the
+# image here rather than hardcoded, so a build that moves it is detected instead
+# of silently mis-driven.
+ASD_BASE = 0xD00100
+ASD_DISPATCH_OFF = 0x1C
+ASD_STUB = (0xE1A00002, 0xE59FC010, 0xE12FFF3C, 0xEF000075)
+
+
+def resolve_asd(comp, base=ASD_BASE):
+ """Return (trampoline, dispatcher) for an ASD image."""
+ marker, = struct.unpack("<I", comp.read(base, 4))
+ if marker != HDR_MARKER:
+ raise ValueError("ASD header marker at %#x is %#x, expected %#x"
+ % (base, marker, HDR_MARKER))
+ tramp, = struct.unpack("<I", comp.read(base + TRAMP_OFF, 4))
+ stub = struct.unpack("<4I", comp.read(tramp, 16))
+ if stub != ASD_STUB:
+ raise ValueError("ASD trampoline stub at %#x is %s, not the known shape -- "
+ "the layout changed and the dispatcher offset cannot be "
+ "assumed" % (tramp, [hex(w) for w in stub]))
+ disp, = struct.unpack("<I", comp.read(tramp + ASD_DISPATCH_OFF, 4))
+ return tramp, disp & ~1
+
+
+def verify_asd(Component, paths):
+ """Resolve every supplied ASD image. Returns [(path, tramp, dispatcher)]."""
+ out = []
+ for p in paths:
+ c = Component("asd", image_path=p)
+ t, d = resolve_asd(c)
+ out.append((p, t, d))
+ return out
+
+
def verify(Component):
"""Re-derive the entries for every image whose values are known. Returns a
list of (name, ok, got_create, want_create, got_invoke, want_invoke)."""
@@ -57,3 +108,32 @@ def verify(Component):
_t, gc, gi = resolve(c, base)
out.append((name, gc == wc and gi == wi, gc, wc, gi, wi))
return out
+
+
+# `asd_validate_ptr` moves between builds (0xD0C9F8 .. 0xD12E90 across the 12
+# images in psp_out/elf) and is hardcoded by harness/fuzz_asd.py, so pointing a
+# harness at another build fetches from address 0 unless it is resolved.
+#
+# Its first 48 bytes are byte-identical in every build we hold, so a signature
+# lookup finds it. Checked: exactly ONE match in each of the 12 images -- a
+# signature that matched twice, or zero times, would make the answer worthless,
+# so find_asd_validate() requires uniqueness rather than taking the first hit.
+ASD_VALIDATE_SIG = bytes.fromhex(
+ "0246b2f1804f4ff0000098bfb1f1805f00d970471144b2f5"
+ "800f02d3b1f5c00f06d30020b2f1806ff3d3b0eb117ff0d1")
+
+
+def find_asd_validate(comp, base=ASD_BASE, size=0x2F000):
+ """Locate asd_validate_ptr in a loaded ASD image by signature."""
+ blob = comp.read(base, size)
+ hits, off = [], 0
+ while True:
+ i = blob.find(ASD_VALIDATE_SIG, off)
+ if i < 0:
+ break
+ hits.append(base + i)
+ off = i + 1
+ if len(hits) != 1:
+ raise ValueError("asd_validate_ptr signature matched %d times, need exactly 1 "
+ "-- refusing to guess" % len(hits))
+ return hits[0]
diff --git a/psp_out/HW-TA-VERSION-REPRODUCTION.md b/psp_out/HW-TA-VERSION-REPRODUCTION.md
index 966187b..962ada8 100644
--- a/psp_out/HW-TA-VERSION-REPRODUCTION.md
+++ b/psp_out/HW-TA-VERSION-REPRODUCTION.md
@@ -79,8 +79,46 @@ in a different link. The `err_state=7` one-shot latch, the subcmd12 overrun
thresholds and their exact values all carry over unchanged.
**So the version caveat is discharged for HDCP and DTM**: these results hold on
-the builds the RX 7900 XTX actually loads. ASD is not covered -- the resolver
-does not handle it, so no claim is made.
+the builds the RX 7900 XTX actually loads.
+
+## ASD, now covered too
+
+ASD needed two more things than HDCP/DTM, because it is not a GP TA.
+
+*Dispatcher.* Its trampoline is ARM code with the RPC dispatcher pointer at
+`+0x1C` (Thumb bit set), not a create/invoke pair at `+0xA0/+0xB0` -- which is
+why the generic resolver read zeros. `resolve_asd()` handles it. Checked across
+all 12 ASD builds in `psp_out/elf`: the trampoline moves from 0xD125D4 to
+0xD19868, the four stub words are identical every time, and the dispatcher is
+0xD013B8 in every one, referenced exactly once per image. It is still *read*
+from the image rather than hardcoded, so a build that moves it is detected.
+A corrupted stub is refused (negative control).
+
+*`asd_validate_ptr`.* `fuzz_asd` hardcoded 0xD12E90, which made it fetch from
+address 0 on any other build. It now resolves by signature, and the lookup
+requires a **unique** match -- exactly one hit in each of the 12 builds, landing
+at 0xD0FF08 for the card's 33.0.0.217 and recovering 0xD12E90 for the default
+image, which the harness prints as an explicit agreement check.
+
+The signature was first written into the source by hand and matched **zero**
+builds including the one it was copied from -- a transcription error that the
+unique-match requirement turned into a loud refusal instead of a silent
+mis-resolution. It is now taken from the image programmatically.
+
+Results (ours is 33.0.**1**.21, the card runs 33.0.**0**.217):
+
+| harness | ours | card's ASD | verdict |
+| --- | --- | --- | --- |
+| `fuzz_asd` (400 iters) | 938 blocks, 395 ok / 5 noise | 967 blocks, **same 395/5** | reproduces |
+| `asd_rpc` | `asd_topology_query` rv 0x0/0x2/0x103 | **same rvs**, 30 -> 31 blocks | reproduces |
+| `load_asd` | 81 blocks, 2/2 controls reject | **76 blocks, 2/2 controls reject** | verifies and runs |
+
+`load_asd` is the strongest of the three: it takes the card's **signed**
+container (0x2F100, extracted from the firmware blob, not the body-only ELF),
+puts it through the firmware's own loader, and the RSA signature check passes --
+while both bit-flip negative controls are still rejected. The card's real ASD
+verifies and executes in the emulator, entering at the same
+0xD01188/0xD011A8/0xD013B8 sequence.
## A misattribution corrected