#!/usr/bin/env python3 """Deep randomized fuzz, enabled by the wrapping ring (pass 85). Every earlier fuzz was capped near 1000 invokes per boot by our own ring bug. With `ring_wrap.install` that ceiling is gone, so this runs thousands of randomized param-block mutations per TA and watches for: non-benign status, stalls, writes past the declared window, and drift in a fixed re-probe (state corruption). Deterministic: seeded RNG, so any hit can be replayed exactly. """ import glob, random, 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) PAT=0xA5A5A5A5; DECL=0x4000; TOTAL=0x8000 BENIGN={0x0,0xffff0000} 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(TOTAL) 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=DECL r=submit(c); return r.resp.status&0xFFFFFFFF, r.resp.session_id, cp INTERESTING=[0,1,2,4,8,0x10,0x20,0x40,0x80,0x100,0x1000,0x4000,0x8000,0x10000, 0x7FFFFFFF,0x80000000,0xFFFFFFF0,0xFFFFFFFF,0xE0000000,0x00400000] def inv(sid,shm,cid,mut): buf=bytearray(TOTAL); struct.pack_into('2 else 2000 stem,skip=TAS[name] rng=random.Random(0xC0FFEE) st,sid,shm=load(open(glob.glob('/root/psp/contall/'+stem+'*')[0],'rb').read()) print('%s load %#x sid=%s'%(name,st,sid), flush=True) if st!=0: sys.exit(2) ref=inv(sid,shm,0,[])[3] hits=[] for i in range(N): cid=rng.randrange(0,12) if cid in skip: continue # offsets drawn from the WHOLE declared window, not just the first 0x100 bytes mut=[(rng.randrange(1,DECL//4)*4, rng.choice(INTERESTING)) for _ in range(rng.randrange(1,6))] s,dt,bey,out=inv(sid,shm,cid,mut) if bey: hits.append(('OOB',i,cid,mut,bey)); break if dt>5: hits.append(('STALL',i,cid,mut)); break if s not in BENIGN and (s>>16)!=0xffff: hits.append(('STATUS',i,cid,mut,hex(s))) if i%400==0 and i: r2=inv(sid,shm,0,[])[3] if r2!=ref: hits.append(('DRIFT',i,ref.hex(),r2.hex())); break print('%s: %d invokes, hits=%s'%(name,N,hits[:5] if hits else 'none'), flush=True)