1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#!/usr/bin/env python3
"""Load every corpus ASD build via GFX_CMD_ID_LOAD_ASD — a path never exercised here.
ASD is driver-class: it loads but refuses INVOKE, so all TA-side fuzzing skipped it. The
LOAD_ASD path itself (cmd 4) has never been driven with anything but the in-use image, and
the corpus holds ~20 distinct ASD builds. Each is a differently-shaped signed blob going
through the loader's parse and authenticate path.
Report status and timing per image; a stall or a state change afterwards would be a finding.
Control: after every load, a known-good TA must still load, proving the PSP is still healthy.
"""
import glob, hashlib, os, struct, sys, time
sys.path.insert(0,'/root/psp/hw')
from tinygrad import Device
import tinygrad.runtime.autogen.am.am as am
from ring_wrap import install
adev=Device["AMD"].iface.dev_impl; psp=adev.psp
submit=install(psp,adev)
def alloc(n):
pa=adev.mm.palloc(n,align=0x1000,zero=True,boot=False); return pa,adev.paddr2mc(pa)
ta=open(glob.glob('/root/psp/contall/ta_42-0-0-6_1c874c3c*')[0],'rb').read()
def load(blob, cmd_id):
ap_,amc=alloc(0x100000); cp,cmc=alloc(0x8000)
n=(len(blob)+3)&~3
adev.vram.view(ap_,n)[:]=blob+b'\x00'*(n-len(blob)); adev.gmc.flush_hdp()
c=am.struct_psp_gfx_cmd_resp(cmd_id=cmd_id); t=c.cmd.cmd_load_ta
t.app_phy_addr_lo,t.app_phy_addr_hi=amc&0xFFFFFFFF,amc>>32; t.app_len=len(blob)
t.cmd_buf_phy_addr_lo,t.cmd_buf_phy_addr_hi=cmc&0xFFFFFFFF,cmc>>32; t.cmd_buf_len=0x4000
t0=time.time()
sid=None
try:
r=submit(c); st=r.resp.status&0xFFFFFFFF; sid=r.resp.session_id
except Exception as e:
try: st=int(str(e).strip().split()[-1])&0xFFFFFFFF
except Exception: st=-1
dt=time.time()-t0
if st==0 and sid is not None:
u=am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_UNLOAD_TA); u.cmd.cmd_unload_ta.session_id=sid
try: submit(u)
except Exception: pass
return st, dt
files=sorted(glob.glob('/root/psp/contall/asd_*.bin'))
lo,hi=(int(sys.argv[1]),int(sys.argv[2])) if len(sys.argv)>2 else (0,len(files))
print('%d ASD images; testing %d..%d'%(len(files),lo,hi), flush=True)
bad=[]
for p in files[lo:hi]:
st,dt = load(open(p,'rb').read(), am.GFX_CMD_ID_LOAD_ASD)
tag=''
if dt>5: tag=' <<< STALL'
else:
cst,cdt = load(ta, am.GFX_CMD_ID_LOAD_TA) # health control
if cst!=0 or cdt>5: tag=' <<< PSP UNHEALTHY AFTER'
if tag: bad.append((os.path.basename(p),hex(st),tag.strip()))
print(' %-40s -> %#-11x %.1fs%s'%(os.path.basename(p)[:40],st,dt,tag), flush=True)
if tag: break
print('\nanomalies: %s'%(bad or 'none'), flush=True)
|