mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 14:38:47 +00:00
36 lines
5.1 KiB
Python
Executable File
36 lines
5.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Evaluate original pure vtable-setter machine instructions under Unicorn, no target calls."""
|
|
import hashlib,json,struct,warnings
|
|
from _binary_path import resolve_580_binary
|
|
from pathlib import Path
|
|
warnings.filterwarnings('ignore',category=UserWarning,module='unicorn')
|
|
from elftools.elf.elffile import ELFFile
|
|
from unicorn import Uc,UC_ARCH_X86,UC_MODE_64
|
|
from unicorn.x86_const import *
|
|
R=Path(__file__).resolve().parents[1];P=resolve_580_binary()
|
|
TEXT=0x10000000;DATA=0x30000000;STACK=0x40000000;STOP=0x60000000
|
|
sets={'OBJFIFO':['_nv005970rm','_nv005971rm','_nv005972rm'],'KernelFifo':['_nv005912rm'],'OBJBUS':['_nv005953rm'],'KernelGmmu':['_nv005914rm','_nv005915rm','_nv005794rm'],'KernelBus':['_nv005902rm','_nv005903rm'],'MemoryManager':['_nv005935rm'],'KernelMemorySystem':['_nv005925rm'],'MemorySystem':['_nv005936rm']};all_names=sum(sets.values(),[])
|
|
expected={'OBJFIFO':{0x3b8:'_nv028203rm',0x3b0:'_nv028192rm',0x670:'_nv027806rm',0x678:'_nv027773rm',0x370:'_nv027712rm',0x368:'_nv027719rm',0x2c8:'_nv028125rm',0x388:'_nv028339rm',0x390:'_nv027717rm',0x5d8:'_nv027676rm',0x5c0:'_nv027678rm',0x410:'_nv028059rm',0x408:'_nv028037rm',0x2f0:'_nv027760rm',0x558:'_nv027885rm',0x700:'_nv027812rm',0x5e0:'_nv027828rm',0x4f8:'_nv028098rm',0x310:'_nv027854rm'},'KernelFifo':{0x200:'_nv040404rm',0x278:'_nv040364rm',0x1b8:'_nv040256rm',0x1f0:'_nv040410rm',0x170:'_nv040326rm',0x1a8:'_nv040242rm',0x288:'_nv040335rm'},'OBJBUS':{0x1b0:'_nv018688rm',0x1b8:'_nv018492rm',0x268:'_nv018613rm'},'MemorySystem':{0xb10:'_nv044754rm'},'KernelMemorySystem':{0x108:'_nv041679rm',0x110:'_nv041622rm'},'MemoryManager':{0x328:'_nv044068rm',0x330:'_nv043812rm',0x340:'_nv043988rm'},'KernelBus':{0x120:'_nv039492rm',0x128:'_nv039648rm',0x390:'_nv039387rm',0x3e0:'_nv039556rm',0x3e8:'_nv039394rm',0x4a8:'_nv039391rm',0x4b8:'_nv039497rm',0x398:'_nv039552rm',0x138:'_nv039638rm',0x140:'_nv039566rm',0x160:'_nv039455rm',0x168:'_nv039317rm',0x170:'_nv039316rm',0x418:'_nv039307rm',0x420:'_nv039476rm',0x430:'_nv039298rm',0x1b0:'_nv039500rm',0x1b8:'_nv039626rm'},'KernelGmmu':{0x160:'_nv040639rm',0x168:'_nv040663rm',0x170:'_nv040941rm',0x178:'_nv040947rm',0x180:'_nv040949rm',0x1b0:'_nv040785rm',0x1b8:'_nv040762rm',0x368:'_nv040937rm',0x358:'_nv040693rm',0x240:'_nv040889rm',0x388:'_nv040989rm',0x390:'_nv040986rm',0x328:'_nv040732rm',0x348:'_nv040729rm',0x2a8:'_nv040647rm',0x2f0:'_nv040712rm',0x230:'_nv040984rm',0x228:'_nv040880rm',0x238:'_nv040884rm',0x2e0:'_nv040673rm',0x408:'_nv040917rm',0x2e8:'_nv040870rm',0x410:'_nv040826rm',0x418:'_nv040867rm',0x420:'_nv040912rm',0x2c0:'_nv040871rm',0x3b0:'_nv040954rm',0x3b8:'_nv040810rm',0x430:'_nv040907rm',0x428:'_nv040797rm'}}
|
|
with P.open('rb') as f:
|
|
e=ELFFile(f);symbols=list(e.get_section_by_name('.symtab').iter_symbols());defined={s.name:s for s in symbols};text=bytearray(e.get_section_by_name('.text').data());text_index=e.get_section_index('.text');functions={n:(defined[n]['st_value'],defined[n]['st_size']) for n in all_names};relocations=0
|
|
for r in e.get_section_by_name('.rela.text').iter_relocations():
|
|
off=r['r_offset']
|
|
if not any(a<=off<a+size for a,size in functions.values()):continue
|
|
s=symbols[r['r_info_sym']];assert r['r_info_type'] in (2,11) and s['st_shndx']==text_index
|
|
value=TEXT+s['st_value']+r['r_addend']
|
|
if r['r_info_type']==2:value-=TEXT+off
|
|
struct.pack_into('<i',text,off,value);relocations+=1
|
|
uc=Uc(UC_ARCH_X86,UC_MODE_64);uc.mem_map(TEXT,(len(text)+4095)&~4095);uc.mem_write(TEXT,bytes(text));uc.mem_map(DATA,0x30000);uc.mem_map(STACK,0x10000);uc.mem_map(STOP,4096)
|
|
uc.mem_write(DATA+0x20000+16,struct.pack('<H',0x23));uc.mem_write(DATA+0x21000+16,struct.pack('<H',2))
|
|
rows=[];properties=[]
|
|
for cls,names in sets.items():
|
|
uc.mem_write(DATA,bytes(0x10000))
|
|
for name in names:
|
|
uc.reg_write(UC_X86_REG_RDI,DATA);uc.reg_write(UC_X86_REG_RSI,DATA+0x20000);uc.reg_write(UC_X86_REG_RDX,DATA+0x21000);uc.reg_write(UC_X86_REG_RSP,STACK+0xfff8);uc.reg_write(UC_X86_REG_RBP,STACK+0x8000);uc.mem_write(STACK+0xfff8,struct.pack('<Q',STOP));uc.emu_start(TEXT+functions[name][0],STOP,count=10000);assert uc.reg_read(UC_X86_REG_RIP)==STOP
|
|
if cls=='KernelGmmu':
|
|
actual=uc.mem_read(DATA+0x468,1)[0];assert actual==1;properties.append({'class':cls,'offset':'0x468','value':actual,'meaning':'selectedGV100 sysmem fault GPU-uncached'})
|
|
for offset,target in expected[cls].items():
|
|
actual=struct.unpack('<Q',uc.mem_read(DATA+offset,8))[0];assert actual==TEXT+defined[target]['st_value'],(cls,hex(offset),target,hex(actual));rows.append({'class':cls,'offset':hex(offset),'target':target,'target_text_offset':hex(defined[target]['st_value'])})
|
|
report={'passed':True,'artifact_sha256':hashlib.sha256(P.read_bytes()).hexdigest(),'architecture_HAL_index':'0x23','runtime_HAL_index':2,'runtime':'PF monolithic','pure_setter_relocations_applied':relocations,'setters':{k:v for k,v in sets.items()},'verified_bindings':rows,'verified_properties':properties,'execution':'Original pure assignment instructions only in isolated Unicorn memory; no driver function calls, native execution or hardware access'}
|
|
(R/'reports/channel-bindings-binary.json').write_text(json.dumps(report,indent=2)+'\n');print(len(rows),'original instruction-emulated GV100 bindings verified')
|