b40: S12-wrapper pop restore kills 8B/call leak; uni DDRHI parity; run-sbl b40

This commit is contained in:
SashegDev
2026-09-15 00:58:48 +00:00
parent 521c8e5398
commit 0062e8f8da
4 changed files with 154 additions and 15 deletions
+12
View File
@@ -229,3 +229,15 @@
UARTDM-страница) замаплен в uni как leak-sink (+8M runway). UARTDM-страница) замаплен в uni как leak-sink (+8M runway).
QEMU не тронут (в гэпе периферия; короткие прогоны не достают). QEMU не тронут (в гэпе периферия; короткие прогоны не достают).
UART все еще пуст. UART все еще пуст.
## b40: S12-wrapper pop restore (2026-09-14)
- 105M-фолт раскрыт ловушкой записи в текст: push.w на 0x80078DC писал
по sp=0x802F688 (стек в тексте sbl_main), далее fetch по затертым
байтам. Корень: b25 заменил pop r4,pc на bx ip во враппере S12
(0x8007B66), каждый вызов сиротил 8B фрейма (около 58B/Kinsn);
к 105M sp съехал, pop.w с восстановлением sp/pc (0x800EB94) взял
чужой stacked-lr. b40 вернул pop (2B), r0=0 снова по контракту.
- Побочка: ранний clock-путь теперь идет честно (раньше диверт его
пропускал): IMEM-стек, чтение за верхом IMEM. Uni не мапил DDRHI,
QEMU мапит: добавлен паритет (0x08610000, 16M-64K). b40 на 2M чист,
sp живет в DDRHI, unmapped 0. Дефолт run-sbl теперь b40.
+1 -1
View File
@@ -5,7 +5,7 @@
set -e set -e
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
QEMU=~/qemu-src/qemu-8.2.2/build/qemu-system-arm QEMU=~/qemu-src/qemu-8.2.2/build/qemu-system-arm
B=${1:-b39} B=${1:-b40}
IMG=fw/img/emmc-real.img IMG=fw/img/emmc-real.img
if [ ! -f "$IMG" ]; then if [ ! -f "$IMG" ]; then
echo "no $IMG — сначала: python3 tools/ffu_extract.py fw/dl/RM1127_059X5R5_orig.ffu --emmc-user fw/img/user-real.bin" echo "no $IMG — сначала: python3 tools/ffu_extract.py fw/dl/RM1127_059X5R5_orig.ffu --emmc-user fw/img/user-real.bin"
+140
View File
@@ -2553,8 +2553,148 @@ def main():
d[o:o + 2] = bytes.fromhex('c046') d[o:o + 2] = bytes.fromhex('c046')
save(d, 'img0_b39.elf') save(d, 'img0_b39.elf')
# b40 = b39 + S12-wrapper pop restore (0x8007B66 bx ip -> pop):
# b25 chained the wrapper pop to bx ip; with S12 preserving sp the
# frame is intact, while bx ip orphaned 8B per call (105M sp-smash).
# Content below = b39 body with the 0x8007B66 hunk reverted to pop.
# naked clock leaf never sets r3 (stale stacked return addr,
# observed 0x8007975); the store writes 0xffff over live code,
# faulting the next fetch there. Peripheral write, nothing in emu
# reads it back (polls use scaffolded [0x73A100]). Same rationale
# as the b17 stm NOP. 2B->2B, no eating.
d = bytearray(base)
for va, (a, b) in BLX2BL.items():
set4(d, va, b)
for va, exp, new in [
(0x802F664, 'e4f77efc', 'c046c046'),
(0x802F672, 'e6f7bbfa', 'c046c046'),
(0x802F678, 'e9f7fef9', 'c046c046'),
(0x801B71E, '9847fee7', 'c046c046'),
(0x8008396, 'fef780f9', 'c046c046'),
(0x8016184, 'fdf790fc', 'c046c046'),
(0x801B76C, '280b0508', '00000708'),
(0x8017AFC, 'bde8fc87', 'eef74fb8'),
(0x802F690, '9847fee7', 'c046c046'),
(0x801671C, '9847fee7', 'c046c046'),
(0x8013BAC, 'f8bd0a4a', 'f3f730b8'),
(0x801B6BE, 'bde8f081', 'ebf7c3ba'),
(0x8016720, '10bd0000', 'f0f7b2ba'),
(0x8034810, 'bde8fc87', 'd2f76eba'),
(0x8007798, 'bde8f08f', 'fff7c3ba'),
(0x8016334, 'f0f7a4ff', 'c046c046'),
(0x8016342, 'f0f79eef', 'f0f79dbf'),
(0x802F9A0, 'ffe70648', 'd7f7c4b9'),
(0x802F9B2, 'fee78817', 'd7f7bbb9'),
(0x802F9A2, 'c4b943f2', 'd7f7c3b9'),
(0x800EB96, 'bde8fe8f', 'f8f7cfb8'),
(0x8007916, 'bde8f09f', 'fff720ba'),
]:
assert hx(d, va) == exp, (hex(va), hx(d, va))
set4(d, va, new)
# Full bl idiom at 0x8006682 (bl + pop, 6B) -> NOPs (see b18).
o = off(0x8006682)
assert d[o:o + 6].hex() == '00f001f807bd', hx(d, 0x8006682, 6)
d[o:o + 6] = bytes.fromhex('c046c046c046')
o = off(0x8013AA8)
assert d[o:o + 4].hex() == '07f026be', hx(d, 0x8013AA8)
d[o:o + 4] = bytes.fromhex('c046c046')
o = off(0x8013BA6)
assert d[o:o + 2].hex() == 'b888', (hex(0x8013BA6), hx(d, 0x8013BA6, 2))
d[o:o + 2] = bytes.fromhex('ff20')
# b40: S12-wrapper pop RESTORED (revert b25 chain at this site).
# b25 sent pop to bx ip because the pop read scratch; with S12
# preserving sp the frame is intact, while bx ip orphaned 8B per
# call and smashed sp into text at 105M. S16 keeps serving B66.
o = off(0x8007B66)
assert d[o:o + 2].hex() == '10bd', hx(d, 0x8007B66, 2)
# Clock S11 (see b24).
o = off(0x800E988)
assert d[o:o + 2].hex() == '10bd', hx(d, 0x800E988, 2)
d[o:o + 2] = bytes.fromhex('7047')
# Poll re-init skip (see b27).
o = off(0x8007748)
assert d[o:o + 2].hex() == '96b1', hx(d, 0x8007748, 2)
d[o:o + 2] = bytes.fromhex('14e0')
# Poll-epilogue add NOP (see b28).
o = off(0x8007794)
assert d[o:o + 2].hex() == '07b0', hx(d, 0x8007794, 2)
d[o:o + 2] = bytes.fromhex('c046')
# Partition wrap-check (see b33).
o = off(0x801844E)
assert d[o:o + 2].hex() == '04d3', hx(d, 0x801844E, 2)
d[o:o + 2] = bytes.fromhex('04e0')
# Hang-site neutralize (see b34).
o = off(0x8018458)
assert d[o:o + 2].hex() == 'fee7', hx(d, 0x8018458, 2)
d[o:o + 2] = bytes.fromhex('ffe7')
# Clock-store NOP: str r1,[r3] (2B 1960) -> mov r8,r8 (2B c046).
o = off(0x800E986)
assert d[o:o + 2].hex() == '1960', hx(d, 0x800E986, 2)
d[o:o + 2] = bytes.fromhex('c046')
save(d, 'img0_b40.elf')
+1 -14
View File
@@ -30,6 +30,7 @@ RAMS = [
(0x00400000, 0x07400000), # RPM range (heap-ish) (0x00400000, 0x07400000), # RPM range (heap-ish)
(0x08000000, 0x00600000), # DDRLOW (0x08000000, 0x00600000), # DDRLOW
(0x08600000, 0x00010000), # IMEM (0x08600000, 0x00010000), # IMEM
(0x08610000, 0x00FF0000), # DDRHI (QEMU parity; IMEM-stack spillover)
(0x80000000, 0x07C00000), # DDRHIGH_A (0x80000000, 0x07C00000), # DDRHIGH_A
(0x87C00000, 0x00800000), # SMEM(+SBL BSS) (0x87C00000, 0x00800000), # SMEM(+SBL BSS)
(0x07800000, 0x000AF000), # leak-sink HI (S12 frame march; (0x07800000, 0x000AF000), # leak-sink HI (S12 frame march;
@@ -350,25 +351,11 @@ def main():
except Exception: except Exception:
pass pass
mu.hook_add(UC_HOOK_MEM_WRITE, hook_txt, begin=0x802F600, end=0x802F700) mu.hook_add(UC_HOOK_MEM_WRITE, hook_txt, begin=0x802F600, end=0x802F700)
_splog2 = []
def hook_spck(mu, addr, size, data):
try:
from unicorn.arm_const import UC_ARM_REG_SP as _S
sp = mu.reg_read(_S)
except Exception:
return
if not (0x07800000 <= sp < 0x08610000):
if len(_splog2) < 5:
_splog2.append((count[0], addr, sp))
mu.hook_add(UC_HOOK_CODE, hook_spck)
import atexit as _ax3 import atexit as _ax3
def _dtx(): def _dtx():
print('txt-writes:', len(_txtlog)) print('txt-writes:', len(_txtlog))
for n, pc, a, sz, v, sp, lr in _txtlog: for n, pc, a, sz, v, sp, lr in _txtlog:
print(' insn', n, hex(pc), hex(a), sz, hex(v), hex(sp), hex(lr)) print(' insn', n, hex(pc), hex(a), sz, hex(v), hex(sp), hex(lr))
print('sp-trips:', len(_splog2))
for n, pc, sp in _splog2:
print(' insn', n, hex(pc), hex(sp))
_ax3.register(_dtx) _ax3.register(_dtx)
# null-fetch redirect: branch-to-0 lands in maze (movs r0,#0; bx lr), # null-fetch redirect: branch-to-0 lands in maze (movs r0,#0; bx lr),
# immune to [0]-writes that clobber a static maze copy # immune to [0]-writes that clobber a static maze copy