"""SMU argument/index fuzz -- SAFE (read-only Get* messages only). The SMU table DMA is VM-protected (verified). The remaining SMU attack surface is the firmware's *parsing* of message arguments. The safest slice to fuzz is the index-taking Get* messages: if an out-of-range index returns OK with a value (instead of a clean rejection), the SMU firmware read out of bounds -> a value from adjacent SMU SRAM leaks into the ARG register = information disclosure. Only queries clocks/voltages/debug data. No writes, no state changes, no reset. """ import time from tinygrad import Device from tinygrad.runtime.autogen.am import smu_13_0_0 as smu d = Device["AMD"]; adev = d.iface.dev_impl MSG, ARG, RESP = adev.mmMP1_SMN_C2PMSG_66, adev.mmMP1_SMN_C2PMSG_82, adev.mmMP1_SMN_C2PMSG_90 def send(msg, param=0, timeout_ms=200): RESP.write(0); ARG.write(param & 0xffffffff); MSG.write(msg) end = time.monotonic() + timeout_ms/1000 while time.monotonic() < end: r = RESP.read() if r != 0: return r, ARG.read() time.sleep(0.001) return None, ARG.read() # PPCLK ids for this ASIC CLKS = {n[len("PPCLK_"):]:v for n,v in vars(smu).items() if n.startswith("PPCLK_") and isinstance(v,int)} print("PPCLK ids:", CLKS) def sweep(name, mid, params): print("\n=== %s (%#x) ==="%(name,mid)) ok_vals=[] for p in params: r,a = send(mid, p) tag = "OK" if r==1 else ("REJ(%#x)"%r if r is not None else "TIMEOUT") if r==1: ok_vals.append((p,a)) # only print rejections/anomalies compactly + all OKs print(" param=%#010x -> %-8s arg=%#010x"%(p,tag,a)) # 1) GetDpmFreqByIndex: (clk<<16)|index. Valid indices are small; 0xff = "count". # Fuzz index far past the real DPM level count for GFXCLK. gfx = CLKS.get("GFXCLK", 0) print("\n[valid baseline] GetDpmFreqByIndex GFXCLK count (idx=0xff):", "%#x"%send(smu.PPSMC_MSG_GetDpmFreqByIndex,(gfx<<16)|0xff)[1]) sweep("GetDpmFreqByIndex GFXCLK idx sweep", smu.PPSMC_MSG_GetDpmFreqByIndex, [(gfx<<16)|i for i in [0,1,2,3,4,5,6,7,8,16,32,64,127,128,200,254]]) # 2) fuzz the CLOCK id field itself (high half) out of range - table index on the other axis sweep("GetDpmFreqByIndex bad-clk sweep", smu.PPSMC_MSG_GetDpmFreqByIndex, [(c<<16)|0 for c in [0x10,0x20,0x40,0x80,0xff,0x100,0xfff,0xffff]]) # 3) GetMinDpmFreq / GetMaxDpmFreq / GetDcModeMaxDpmFreq take a clk id for nm,mid in [("GetMinDpmFreq",smu.PPSMC_MSG_GetMinDpmFreq), ("GetMaxDpmFreq",smu.PPSMC_MSG_GetMaxDpmFreq), ("GetDcModeMaxDpmFreq",smu.PPSMC_MSG_GetDcModeMaxDpmFreq)]: sweep(nm, mid, [0,1,2,4,8,0x10,0x20,0x40,0x80,0xff,0x100,0x1000,0xffff]) # 4) GetVoltageByDpm (index), GetDebugData (index) sweep("GetVoltageByDpm", smu.PPSMC_MSG_GetVoltageByDpm, [0,1,2,4,8,0x10,0x40,0xff,0x100,0x1000,0xffff,0xffffffff]) if hasattr(smu,'PPSMC_MSG_GetDebugData'): sweep("GetDebugData", smu.PPSMC_MSG_GetDebugData, [0,1,2,3,4,8,0x10,0x40,0xff,0x100,0x1000]) print("\nSMU alive after fuzz:", adev.smu.is_smu_alive())