mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 14:38:47 +00:00
23 lines
2.8 KiB
Python
23 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Read installed NVIDIA module ELF prefixes; never register/execute probes."""
|
|
from pathlib import Path
|
|
import json,re,subprocess,hashlib
|
|
from elftools.elf.elffile import ELFFile
|
|
R=Path(__file__).resolve().parents[1];M=Path('/lib/modules/5.15.0-202-generic/updates/dkms/nvidia.ko')
|
|
manifest=json.loads((R/'reports/gpu-firmware-live-trace-map.json').read_text());names=[r['symbol']for r in manifest['symbols']]+['rm_init_adapter','_nv000790rm','nv_open_device','nv_close_device']
|
|
with M.open('rb')as f:
|
|
elf=ELFFile(f);symtab=elf.get_section_by_name('.symtab');symbols={s.name:s for s in symtab.iter_symbols()};text=elf.get_section_by_name('.text').data();rows=[]
|
|
for name in names:
|
|
s=symbols[name];off=s['st_value'];raw=text[off:off+24];output=subprocess.check_output(['objdump','-d','--disassemble='+name,str(M)],text=True);instructions=[line.strip()for line in output.splitlines()if re.match(r'^\s*[0-9a-f]+:\s',line)][:6]
|
|
rows.append({'symbol':name,'module_text_offset':hex(off),'prefix_hex':raw.hex(),'first_instructions':instructions,'endbr64_at_entry':raw[:4]==bytes.fromhex('f30f1efa'),'offset4_preserves_all_entry_registers_and_RSP':raw[:4]==bytes.fromhex('f30f1efa'),'offset4_safe_instruction_boundary':raw[:4]==bytes.fromhex('f30f1efa'),'trace_registration_guaranteed':False})
|
|
rel=elf.get_section_by_name('.rela.text');fentry=[]
|
|
if rel:
|
|
for r in rel.iter_relocations():
|
|
s=symtab.get_symbol(r['r_info_sym'])
|
|
if s.name in ['__fentry__','mcount','_mcount']:
|
|
for name in ['nv_open_device','nv_close_device','rm_init_adapter','_nv000790rm','_nv028470rm']:
|
|
fn=symbols[name]
|
|
if fn['st_value']<=r['r_offset']<fn['st_value']+24:fentry.append({'symbol':name,'relocation_offset_from_entry':r['r_offset']-fn['st_value'],'target':s.name})
|
|
report={'read_only':True,'installed_module_file':str(M),'installed_module_sha256':hashlib.sha256(M.read_bytes()).hexdigest(),'prefixes':rows,'entry_fentry_relocations':fentry,'interpretation':['ENDBR64 is4bytes and has no architectural register/SP mutation. A probe at+4 lands on the next original instruction and sees entry registers/RSP.','This is an instruction-boundary/snapshot contract only; kernel trace policy, decoder and module lifetime still control registration.','RM code uses a customRBP frame area; RBP must not be assumed a conventional frame pointer or C unwinding proof.','A probe after the first push changes entry stackargument offsets. Exact+4 avoids that for ENDBR-prefixed entries.','Public wrapperfentry versus privateRM nofentry is consistent with NOTRACE policy rejection; installedprefix evidence alone cannot prove rejection cause.'],'tracing_changed':False}
|
|
(R/'reports/gpu-firmware-probe-prefixes.json').write_text(json.dumps(report,indent=2)+'\n');print('entries',len(rows),'ENDBR',sum(r['endbr64_at_entry']for r in rows),'fentry',fentry)
|