Files
nvdriver/tools/timer-timeout-vgx-evidence.py

54 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""Read original ELF symbols/source only; never call or change the driver."""
from pathlib import Path
import hashlib
import json
from elftools.elf.elffile import ELFFile
ROOT = Path(__file__).resolve().parents[1]
ANALYSIS = Path('/home/geodd/nvidia-driver/analysis-580.178.04')
def symbol(path, name):
with path.open('rb') as stream:
elf = ELFFile(stream)
table = elf.get_section_by_name('.symtab')
item = next(s for s in table.iter_symbols() if s.name == name)
section = elf.get_section(item['st_shndx'])
start, size = item['st_value'], item['st_size']
code = section.data()[start:start+size]
relocations = []
for relocation_section in elf.iter_sections():
if relocation_section['sh_type'] not in ('SHT_RELA', 'SHT_REL'):
continue
if elf.get_section(relocation_section['sh_info']).name != section.name:
continue
symbols = elf.get_section(relocation_section['sh_link'])
for relocation in relocation_section.iter_relocations():
offset = relocation['r_offset']
if start <= offset < start+size:
relocations.append({'offset': offset-start,
'target': symbols.get_symbol(relocation['r_info_sym']).name,
'addend': relocation.entry.get('r_addend')})
return {'path':str(path), 'file_sha256':hashlib.sha256(path.read_bytes()).hexdigest(),
'symbol':name, 'section':section.name, 'offset':hex(start),
'size':size, 'bytes':code.hex(), 'relocations':relocations}
def main():
wrapper = symbol(ANALYSIS/'extracted/kernel/nvidia/nv-kernel.o_binary','_nv036619rm')
installed = symbol(Path('/lib/modules/5.15.0-202-generic/updates/dkms/nvidia.ko'),'os_is_vgx_hyper')
assert wrapper['size'] == 9 and wrapper['bytes'].startswith('f30f1efae9')
assert any(row['target']=='os_is_vgx_hyper' for row in wrapper['relocations'])
assert installed['bytes']=='e8000000005531c04889e55de900000000'
assert [r['target'] for r in installed['relocations']] == ['__fentry__','__x86_return_thunk']
output = {'scope':'Static ELF bytes and exact relocations; no loaded-driver execution',
'fresh_REA':'reports/timer-timeout-vgx-rea/_nv036619rm.rea.json',
'original_RM_tail_forwarder':wrapper,'installed_Linux_false_implementation':installed}
(ROOT/'reports/timer-timeout-vgx-binary-evidence.json').write_text(json.dumps(output,indent=2)+'\n')
print('Original nine-byte RM tail-forwarder and installed constant-false Linux implementation verified.')
if __name__ == '__main__':
main()