#!/usr/bin/env python3 """Per-field mutation fuzz: one dword at a time, rest zero. The earlier profiles filled every field at once, which a first-stage validator will usually reject, so deeper code was never reached. This mutates ONE dword per invoke (offsets 4..0x80) with a set of interesting values, leaving the rest zero, and reports any field/value that changes the status, stalls, or writes past the declared window. Controls: the unmutated baseline status per command is recorded first; a field is only reported if it differs from that baseline. """ 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 PAT=0xA5A5A5A5; DECL=0x4000; TOTAL=0x8000 VALUES=[0xFFFFFFFF, 0x80000000, 0x7FFFFFFF, 0x00001000, 0xFFFFFFF0] 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 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 inv(sid,shm,cid,off=None,val=0): buf=bytearray(TOTAL); struct.pack_into('5: findings.append(('STALL',cid,hex(off),hex(v))); break if s!=base: findings.append(('STATUS',cid,hex(off),hex(v),hex(base),hex(s))); break if findings and findings[-1][0] in ('OOB','STALL'): break print('%-6s %s'%(name, findings[:6] if findings else 'no field mutation changed behaviour'))