883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
85 lines
3.5 KiB
Python
85 lines
3.5 KiB
Python
"""Own-child regression for fixed public race/class header watchpoints."""
|
|
import ctypes as C
|
|
import json
|
|
import os
|
|
import struct
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
|
|
import engine_race_class_watch as watch_module
|
|
|
|
abi = Path(sys.argv[1]) if len(sys.argv) > 1 else None
|
|
|
|
|
|
def run(field):
|
|
with tempfile.TemporaryDirectory() as temp:
|
|
root = Path(temp)
|
|
(root / 'runtime').mkdir()
|
|
ready_r, ready_w = os.pipe()
|
|
pid = os.fork()
|
|
if pid == 0:
|
|
try:
|
|
os.close(ready_r)
|
|
libc = C.CDLL(None)
|
|
libc.mmap.restype = C.c_void_p
|
|
libc.mmap.argtypes = [C.c_void_p, C.c_size_t, C.c_int, C.c_int, C.c_int, C.c_long]
|
|
table_page = watch_module.TABLE & ~4095
|
|
code = 0x140001000
|
|
if libc.mmap(table_page, 4096, 3, 0x100022, -1, 0) != table_page:
|
|
os._exit(2)
|
|
if libc.mmap(code, 4096, 3, 0x100022, -1, 0) != code:
|
|
os._exit(3)
|
|
C.memmove(watch_module.TABLE, struct.pack('<QQQ', table_page + 0x300, 0,
|
|
0x7FFFFFFFFFFFFFFF), 24)
|
|
target = dict(pointer=watch_module.TABLE,
|
|
count=watch_module.TABLE + 8)[field]
|
|
value = table_page + 0x400 if field == 'pointer' else 1
|
|
disp = target - (code + 10 + 7)
|
|
body = (b'\x48\xb8' + struct.pack('<Q', value) + b'\x48\x89\x05' +
|
|
struct.pack('<i', disp) + b'\xc3')
|
|
C.memmove(code, body, len(body))
|
|
if libc.mprotect(C.c_void_p(code), 4096, 5):
|
|
os._exit(4)
|
|
os.write(ready_w, b'x')
|
|
os.close(ready_w)
|
|
time.sleep(.1)
|
|
C.CFUNCTYPE(None)(code)()
|
|
time.sleep(.1)
|
|
os._exit(0)
|
|
except BaseException:
|
|
os._exit(5)
|
|
os.close(ready_w)
|
|
try:
|
|
assert os.read(ready_r, 1) == b'x'
|
|
watch_module.ROOT = root
|
|
result = root / 'runtime/watch.json'
|
|
watcher = watch_module.Watch(pid, timeout=2, result_path=result,
|
|
abi_path=abi, fields=(field,))
|
|
until = time.monotonic() + 3
|
|
while not watcher.done and time.monotonic() < until:
|
|
watcher.poll()
|
|
time.sleep(.003)
|
|
data = json.loads(result.read_text())
|
|
assert data['status'] == 'public-race-class-field-write-observed'
|
|
assert data['field'] == field
|
|
assert data['hardware_registers_restored'] and not data['instruction_pointer_changed']
|
|
assert data['instruction_after_write'] == hex(0x140001011)
|
|
assert not data['packet_payloads_read'] and not data['authentication_buffers_read']
|
|
if field == 'pointer':
|
|
assert data['final_header']['pointer_present'] and data['final_header']['count'] == 0
|
|
else:
|
|
assert data['final_header']['pointer_present'] and data['final_header']['count'] == 1
|
|
os.waitpid(pid, 0)
|
|
finally:
|
|
os.close(ready_r)
|
|
if 'watcher' in locals() and watcher.attached:
|
|
watcher.cancel()
|
|
|
|
|
|
run('pointer')
|
|
run('count')
|
|
print('Fixed public race/class pointer and count writes observed in owned children; registers restored and no packet/auth data read.')
|