#!/usr/bin/env python3 """TA header fields +0x1c and +0x20 survive modification and still authenticate. Used or ignored? Zeroing either still yields LOAD_TA status 0x0 on a signed image, so they are outside what the signature covers (or are not checked). Both hold addresses in the image's own range (+0x1c = 0x402000, +0x20 = 0x4011a0), so if they steer anything -- an entry point, a copy destination -- an attacker controls it without forging a signature. Test: set each to a range of values and see whether (a) the load still succeeds, and (b) the loaded TA still behaves the same when invoked. A behaviour change means the field is CONSUMED. """ import glob, struct, sys, time sys.path.insert(0,'/root/psp/hw') from tinygrad import Device import tinygrad.runtime.autogen.am.am as am from ring_wrap import install adev=Device["AMD"].iface.dev_impl; psp=adev.psp submit=install(psp,adev) base=open(glob.glob('/root/psp/contall/ta_42-0-0-6_1c874c3c*')[0],'rb').read() def alloc(n): pa=adev.mm.palloc(n,align=0x1000,zero=True,boot=False); return pa,adev.paddr2mc(pa) def run(off,val,tag): blob=bytearray(base) if off is not None: struct.pack_into('>32; t.app_len=len(blob) t.cmd_buf_phy_addr_lo,t.cmd_buf_phy_addr_hi=cmc&0xFFFFFFFF,cmc>>32; t.cmd_buf_len=0x4000 t0=time.time() try: r=submit(c); st=r.resp.status&0xFFFFFFFF; sid=r.resp.session_id except Exception as e: try: st=int(str(e).strip().split()[-1])&0xFFFFFFFF except Exception: st=-1 sid=None dt=time.time()-t0 out='' if st==0 and sid is not None and dt<5: buf=bytearray(0x4000); struct.pack_into('5 run(None,0,'CONTROL unmodified') for off in (0x1c,0x20): for val,vn in ((0,'0'),(0x400100,'image base'),(0xDEADBEEF,'0xdeadbeef'),(0xFFFFFFFF,'ones')): if run(off,val,'hdr[%#x]=%s'%(off,vn)): sys.exit(3)