apple-ibridge: fix heap out-of-bounds write in appleib_add_device() (sub_hdevs[] indexed by raw collection index)#11
Open
xeeban wants to merge 1 commit into
Conversation
appleib_add_device() indexes the fixed-size sub_hdevs[] array -- which has
only ARRAY_SIZE(appleib_sub_hid_ids) (== 2) slots -- by the raw HID collection
index. On the T1's combined display/ALS interface the report descriptor has 7
collections (the ALS, five nested sensor collections, and the Touch Bar
display at index 6), so the display's hid_device* is written to sub_hdevs[6]:
24 bytes past the end of the devm-allocated appleib_hid_dev_info. This corrupts
the adjacent slab object on every probe, and the latent corruption then GPFs on
any later iBridge teardown (driver unload, USB unbind/re-enumerate, or
suspend/resume) in remove_nodes()/hid_destroy_device(); the non-canonical
"pointers" in the crash are byte-for-byte the device's report descriptor.
Index sub_hdevs[] by the matched id's slot in appleib_sub_hid_ids[]
(dev_id - appleib_sub_hid_ids, {0,1}, in-bounds by construction) instead. Warn
only for unmatched application collections (the nested sensor collections are
expected, not errors), guard against a duplicate collection filling a slot,
never store an ERR_PTR in the array, and clean up the full array on the error
path. Correct indexing also means the display sub-device is actually destroyed
by appleib_remove_device() (it was orphaned at the OOB index, leaking + UAF on
parent unbind) and the sub_open[] flag lands on the right slot. Also
NULL/ERR-guard the sub-device in the raw-event forwarder.
Tested on MacBookPro13,2 (T1), kernels 6.x and 7.0.10: the per-boot "Unknown
collection" warnings are gone and iBridge teardown / USB re-enumeration no
longer GPFs or D-state-deadlocks.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
xeeban
pushed a commit
to xeeban/macbook-t1-linux
that referenced
this pull request
Jun 12, 2026
The heap-OOB fix is filed at t2linux/apple-ib-drv#11 (build-tested, T1-iBridge-scoped, inert on T2; issues are disabled on that repo so it went as a PR). Link it from README #7, touch-bar Upstream, and the issue/PR drafts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope / safety: memory-safety fix in the T1 iBridge path —
apple_ibridgebinds onlyUSB_DEVICE_ID_APPLE_IBRIDGE(0x8600), soappleib_add_device()never runs on a T2 machine (the T2 Touch Bar0x8302/0x8102is handled by separate drivers). It is also behavior-preserving for any well-formed layout, so it is inert / zero-risk for T2 users.What
appleib_add_device()indexes the fixed-sizesub_hdevs[]array — which has onlyARRAY_SIZE(appleib_sub_hid_ids)(= 2) slots — by the raw HID collection indexi. On the T1's combined display/ALS interface the report descriptor has 7 collections (the ALS, five nested sensor collections, and the Touch Bar display at index 6), so the display'shid_device *is written tosub_hdevs[6]— 24 bytes past the end of thedevm-allocatedappleib_hid_dev_info. This is a heap out-of-bounds write on every probe / every boot; the corrupted adjacent object then GPFs on any later teardown of the iBridge (driver unload, USB unbind/re-enumerate, or suspend/resume).This PR indexes
sub_hdevs[]by the matched sub-device-id slot instead (dev_id - appleib_sub_hid_ids,{0,1}, in-bounds by construction).Root cause
hdev->maxcollectioncounts every collection, whilesub_hdevs[]is only ever sized/iterated as 2 slots everywhere else (appleib_remove_device(),appleib_forward_int_op(), raw-event), soiis the wrong index here.Proof
A later teardown GPFs with non-canonical "pointers" that are byte-for-byte the first 16 bytes of the live report descriptor (a
hid_device's first member isdev_rdesc):The change
appleib_add_device()— index by the matched slot; warn only for unmatched application collections (the nested sensor collections are expected, not errors); guard against a duplicate collection mapping to an already-filled slot; never store anERR_PTRin the array; clean up the full array on the error path. Correct indexing also means the display sub-device is now destroyed byappleib_remove_device()(it was orphaned at the OOB index → leak + UAF on parent unbind) and thesub_open[]flag lands on the right slot.sub_hdevs[i]once and NULL/IS_ERR-guard it beforehid_input_report().No functional change on the normal path — the same sub-devices register and bind, the bar lights as before, minus the five bogus
Unknown collectionwarnings per boot. (The old code's extra sub-devices at indices ≥ 2 were never touched by any forwarder/remove/open loop — they were pure orphans/leaks.)Testing
Unknown collectionwarnings; any iBridge teardown (echo 0/1 > .../authorized,modprobe -r apple_touchbar) GPFs inremove_nodes()/hid_destroy_device()or D-state-deadlocksmodprobe; recovery is a hard reboot.authorized0→1 power-cycle and a fullmodprobe -r/reload run clean (no GPF, no D-state, process staysR), repeatedly; Touch Bar + ALS bind and function across reboots.Note
This is a generic memory-safety bug — not suspend-specific; that's just one reliable trigger. Full write-up (crash forensics + adversarial review of the fix): https://github.com/xeeban/macbook-t1-linux/blob/main/touch-bar/IBRIDGE-TEARDOWN-UAF-ANALYSIS.md
Credit to @roadrunner2 (Ronald Tschalär) for the original driver.