Repository navigation
kboot, main: T6050: optionally preserve iBoot's live DART-mtp tables and pages (opt-in T6050_MTP_RSV) - #38
TripleU613 wants to merge 1 commit into
Conversation
…and pages Opt-in build switch T6050_MTP_RSV (default builds are unchanged). On T6050 iBoot leaves DART-mtp SID 0 translating, with its page tables in ordinary RAM that no ADT or DT node covers. A loader or kernel that reuses those pages corrupts the MTP's live session. With the switch, on chip_id == T6050 only: - main: a read-only walk of DART-mtp SID 0 (3-level 16K tables, PA checked against the ADT reg, caps of 64 tables / 16384 leaves / 256 ranges, no malloc) runs after firmware_init() and before heapblock_init(); the heap is then capped below the lowest recorded range above its base, and a range holding the heap base marks the walk failed; - chainload_image() refuses before any write if the stub's destination meets a range; top_of_memory_alloc() panics before carving one; - gz/xz payload inflate and the boot= gz path are bounded by the new heapblock_room(), so the decoder cannot write past the heap limit; - kboot_prepare_dt(), after dt_set_memory(): re-checks the root table's checksum and the heap's extent, then adds one no-map /reserved-memory/dart-mtp-pages@... node (apple,dart-mem) per range. A failed or overflowing walk makes every guarded path refuse, so no OS starts on an unverified layout. Testing and limits (J714s, Mac17,9): - NATIVE, earlier implementation only: the same walk and no-map carry in the owner's independent raw loader (m5boot) boots Linux on J714s with the built-in keyboard and trackpad; without the reservation Linux reused iBoot's MTP tables (RTKit -62, no keyboard/trackpad). - This m1n1 port is OFFLINE: built with clang 23.1.3 in stage 1 (CHAINLOADING=1) and ESP stage 2 configurations, both reproducible, with a static call-order check on the ELFs. It has not been booted on any Mac. - Boards whose kernel restarts the MTP on its own DART instead are reported to work without it; it is therefore off by default. Prepared with AI assistance (Claude Opus 5.5); the owner reviews and signs off before submission. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
[Medium impact] The changes affect opt-in T6050 boot flows. The PR should not merge until the heap protection and the three outstanding findings are fixed. Findings
SummaryAdds opt-in
|
| if (chip_id == T6050) | ||
| kboot_t6050_dart_mtp_scan(); |
There was a problem hiding this comment.
Failed scans still allow writes
main ignores a failed kboot_t6050_dart_mtp_scan() and continues into heap-backed initialization. If the walk hits a table, leaf, or range limit, its partial list need not include the lowest live page. kboot_t6050_limit_heap() still trusts that list, so initialization can overwrite undiscovered MTP pages before the later boot refusal.
Stop before further initialization when the scan fails, or prevent all heap allocations in that state.
| if (!t6050_in_ram(t2)) { | ||
| bad++; | ||
| continue; |
There was a problem hiding this comment.
Skipped tables hide live pages
If a valid child table lives in firmware-owned memory outside the boot RAM window, t6050_in_ram() rejects its address. The walk skips that table and still reports success, even though it may map pages inside usable RAM. Those pages remain unrecorded and available for the kernel to overwrite. The same skip occurs for t3.
Refuse the walk when a valid child table cannot be checked instead of counting it as bad and continuing.
| snprintf(name, sizeof(name), "dart-mtp-pages@%lx", start); | ||
| if (dt_get_or_add_reserved_mem(name, "apple,dart-mem", true, start, end - start) < 0) |
There was a problem hiding this comment.
Repeated pages shrink reservations
If the DART maps leaf addresses A, A + SZ_16K, then A again, the walk records 32 KiB and 16 KiB ranges with the same start. Both use the same node name here. dt_get_or_add_reserved_mem() overwrites the earlier reg, leaving the second live page unreserved and available for the kernel to overwrite.
Merge overlapping ranges before emitting nodes, or keep the largest extent when a node already exists.
|
Withdrawing this PR. Factual correction:
|
| if (limit) | ||
| heapblock_set_limit((void *)limit); |
There was a problem hiding this comment.
Proxy setup removes MTP protection
Connecting the standard proxy client replaces the MTP heap cap installed here. ProxyUtils.__init__() calls heapblock_set_limit() with the current heap plus 128 MiB, and that setter discards the earlier limit.
If a recorded MTP page lies inside that space, later heap allocations can overwrite it. The final heap check runs after those writes. Keep the MTP cap separate from the client’s limit, and enforce the lower of the two.
Base:
integration/aurora7f6df96. One commit. It is independent of the T6050 stack (#30, #33-#37) and cherry-picks cleanly onto it too.Problem. On T6050 (seen on J714s, Mac17,9), iBoot leaves DART-mtp SID 0 translating, with its page tables and pages in ordinary RAM that no ADT or DT node covers. A loader heap, a chainloaded stage, or the kernel can reuse those pages and corrupt the MTP's live session.
What this adds (behind a new build switch
T6050_MTP_RSV, off by default, so default builds are unchanged; only onchip_id == T6050):main: afterfirmware_init()and beforeheapblock_init(), a read-only walk of DART-mtp SID 0.reg, caps at 64 tables / 16384 leaves / 256 ranges, and does no malloc.chainload_image()refuses before any write if the destination meets a range.top_of_memory_alloc()panics before carving one.boot=gz path are bounded by a newheapblock_room(), so a decoder can't write past the heap limit.kboot_prepare_dt(), afterdt_set_memory(): re-checks the root table's checksum and the heap's extent, then adds one no-map/reserved-memory/dart-mtp-pages@…node (apple,dart-mem) per range.Validation (be aware of the scope):
mov w2, #immwhose immediate grows by the number of lines this patch inserts above it (+13, +207, +9). That is the__LINE__argument of diagnostic macros, verified by decoding the differing words. There is no other code change.CHAINLOADING=1) and ESP stage 2 configurations on the T6050 (M5 Max, J714c): boot from disk through the Omarchy chain #30-wdt: leave the watchdog armed when the boot-args say m1n1.wdt=keep #36 stack, reproducibly, and checked the static call order in the ELFs (walk before heap init; guards beforechainload_image's writes, before inflate, and right afterdt_set_memory).NATIVE, earlier implementation only: the same walk and no-map reservation, in the owner's own raw loader (m5boot, buildRetracted, see the correction above: on the logged boots this walk found SID 0 not translating and reserved nothing.gzft1, sha256 9d22fab0…), boots Linux 7.2 (kernel kboot: default J514M/T6034 native display and graphics #32) on J714s with the built-in keyboard and trackpad. Without the reservation, Linux reused iBoot's MTP tables (RTKit -62, no keyboard/trackpad).Assistance and sign-off. Prepared with AI assistance (Claude Opus 5.5), disclosed in the commit trailer. The commit carries no Signed-off-by. The human submitter (@TripleU613) reviews it and adds their own before merge.