Skip to content

kboot, main: T6050: optionally preserve iBoot's live DART-mtp tables and pages (opt-in T6050_MTP_RSV) - #38

Closed
TripleU613 wants to merge 1 commit into
omacom:integration/aurorafrom
TripleU613:t6050-dart-mtp-rsv
Closed

TripleU613 wants to merge 1 commit into
omacom:integration/aurorafrom
TripleU613:t6050-dart-mtp-rsv

Conversation

@TripleU613

@TripleU613 TripleU613 commented Nov 8, 2026 •

Copy link
Copy Markdown

Correction (2026-11-08), draft: the native claim below is retracted. Every native log of our raw loader (m5boot) we have, including its current build gzft1 with kernel #32, records m5.dartrsv=sid0-not-translating:1/0. On those boots DART-mtp SID 0 was not translating and the walk reserved nothing. So that loader's walk did not cause the keyboard/trackpad result, and the problem statement's "iBoot leaves DART-mtp SID 0 translating" is not supported by our current-firmware evidence. An earlier claim that iBoot leaves MTP's DART translating had already been retracted in our notes. The automated review's three P1 findings also stand. We are checking for any log of an actively translating SID 0. If none exists, this PR will be withdrawn rather than fixed. The commit message still carries the old claim and is not to be merged as is.

Base: integration/aurora 7f6df96. 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 on chip_id == T6050):

  • main: after firmware_init() and before heapblock_init(), a read-only walk of DART-mtp SID 0.
    • It uses 3-level 16K tables, checks every PA against the ADT reg, caps at 64 tables / 16384 leaves / 256 ranges, and does no malloc.
    • The heap is then capped below the lowest recorded range above its base. A range that holds the heap base marks the walk failed.
  • chainload_image() refuses before any write if the destination meets a range. top_of_memory_alloc() panics before carving one.
  • The gz/xz payload inflate and the boot= gz path are bounded by a new heapblock_room(), so a decoder can't 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.

Validation (be aware of the scope):

  • This m1n1 port has not been booted on any Mac (offline).
  • On this base, clang 23.1.3, I built three m1n1.bin variants: flag off, flag on, and the unpatched base. All build with rc 0 and the same 13 pre-existing warnings, none in the touched files.
    • Flag off: not byte-identical to the unpatched base. It differs in 8 instruction words (16 bytes), each a mov w2, #imm whose 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.
    • Flag on: contains the walk/reservation strings.
  • A separate audit built the stage 1 (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 before chainload_image's writes, before inflate, and right after dt_set_memory).
  • NATIVE, earlier implementation only: the same walk and no-map reservation, in the owner's own raw loader (m5boot, build 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). Retracted, see the correction above: on the logged boots this walk found SID 0 not translating and reserved nothing.
  • Boards whose kernel restarts the MTP on its own DART are reported to work without this, which is why it is opt-in.

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.

…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>
@greptile-apps

greptile-apps Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 1/5

[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

  1. P1 Proxy setup removes MTP protection ▶
  2. P1 Failed scans still allow writes ▶
  3. P1 Skipped tables hide live pages ▶
  4. P1 Repeated pages shrink reservations ▶

Summary

Adds opt-in T6050_MTP_RSV protection for pages found by an early MTP DART walk.

  • T6050 boots can keep active DART-mtp pages out of loader use.
  • Compressed images stop at the available heap limit.
  • The next operating system receives no-map reservations for DART-mtp pages.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Early MTP scan] --> B[Record tables and mapped pages]
    B --> C[Set heap cap]
    C --> D[Initialize devices and load payload]
    C --> E[Connect standard proxy client]
    E --> F[Replace heap cap]
    F --> D
    D --> G[Check root and heap extent]
    G --> H[Add no-map reservations]
    H --> I[Boot next stage]
Loading

Reviews (2) · Last reviewed commit: "kboot, main: T6050: optionally preserve ..." · Reviewed by Greptile

Comment thread src/main.c
Comment on lines +272 to +273
if (chip_id == T6050)
kboot_t6050_dart_mtp_scan();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Comment thread src/kboot.c
Comment on lines +5710 to +5712
if (!t6050_in_ram(t2)) {
bad++;
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Comment thread src/kboot.c
Comment on lines +5806 to +5807
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

@TripleU613
TripleU613 marked this pull request as draft November 8, 2026 03:37
@TripleU613

Copy link
Copy Markdown
Author

Withdrawing this PR. Factual correction:

  • Every concrete loader log we have from our own raw loader (m5boot) on this J714s records m5.dartrsv=sid0-not-translating:1/0. That includes its current build with kernel kboot: default J514M/T6034 native display and graphics #32. DART-mtp SID 0 was not translating, and that walk reserved nothing.
  • The native claim made here (that this walk and reservation preserved the MTP and made the keyboard/trackpad work) is retracted. No causation follows from the keyboard result.
  • We found no log of an actively translating SID 0, and no other code path that would justify this change.
  • Fixes for the three review findings (fail closed after a failed or partial walk, walk tables outside the RAM window, merge overlapping ranges) are kept on our branch with host regression tests. They are not proposed without a demonstrated need.
  • The branch and this PR's history are left in place.

@TripleU613 TripleU613 closed this Nov 8, 2026
@TripleU613
TripleU613 deleted the t6050-dart-mtp-rsv branch November 9, 2026 19:10
Comment thread src/kboot.c
Comment on lines +5780 to +5781
if (limit)
heapblock_set_limit((void *)limit);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant