Repository navigation
soc: apple: pmp: avoid unaligned read, panicking unwraps, and vector desync - #4864
Conversation
…desync Harden PMP RTKit message handlers in drivers/soc/apple/pmp.rs: - Replace the unaligned raw pointer dereference in set_buf() with u64::from_le_bytes() over the checked 8-byte slice. - Replace unchecked .unwrap() calls in register_ioreg() with error propagation, guard the u32 conversion of DT tunable length with u32::try_from(), use lossless u64::from() widening in register_ioreg() and set_ioreg(), and reserve capacity in both state.ioreg_entries and state.ioreg_ids before pushing so OOM on the second push cannot leave the parallel vectors out of sync. - Add missing SAFETY documentation on display_send() and PmpData Send/Sync impls and remove a stale SAFETY comment above safe dev.get_drvdata(). Signed-off-by: Stepan Gulyaev <stepanoid2005@users.noreply.github.com>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
satchlj
left a comment
There was a problem hiding this comment.
Reviewed 743e985843ea (code-only; non-T8132 PMP hardware untested here):
set_buf()replaces the unaligned*const u64dereference withu64::from_le_bytes()over the bounds-checked[..8]slice (ptr_buf.size() >= 8verified directly above).register_ioreg()replaces all panicking.unwrap()calls with error propagation (hdr[0x40..0x44]/hdr[0..0x30]guarded bymsg_buf.size() >= 0x44,hdr[0x48..0x4c]guarded byhdr.len() >= 0x4c), validatesu32::try_from(len), widens losslessly viau64::from(), and reserves capacity on bothstate.ioreg_entriesandstate.ioreg_idsbefore pushing so an OOM cannot desynchronize the parallel vectors.display_send()andSend/Syncsafety comments are clear and accurate.
RyanTheTide
left a comment
There was a problem hiding this comment.
Checked that message lengths precede the byte reads and the existing little-endian fields and reply layout are preserved. Both vectors reserve capacity under the same state lock before either length changes. The reported J713 boot covers the live PMP path.
There was a problem hiding this comment.
Verdict: MERGE at 743e985
Checked: The DMA reads stay within the checked byte-slice bounds and preserve little-endian decoding. Both vectors reserve under the same state mutex before either gains an entry. Verified the exact KVec implementation takes the no-allocation path for those subsequent pushes. The checked tunable length is converted before copying. The contributor reports clean J713 PMP, thermal and power initialization.
|
Hardware-tested on MacBook Air 13" M3 ( Checks run (
|
|
Verified exact merge-tree against
Triple-approved ( |
What: Harden PMP RTKit message handlers in
drivers/soc/apple/pmp.rs: replace the unaligned raw*const u64read inset_buf()withu64::from_le_bytes(), replace panicking.unwrap()calls inregister_ioreg()with error propagation, guard DT tunable length conversion withu32::try_from(), reserve bothioreg_entriesandioreg_idsbefore pushing to prevent OOM desync, use losslessu64::from()widening inregister_ioreg()/set_ioreg(), and documentdisplay_send()andPmpDataSend/Syncsafety contracts.Tested: J713 (MacBook Air 13" M4, T8132) at
743e985843ea(default kernel command line withuser4k=on, candidate7.3.0-j713-20261206+containing743e985843eaunchanged onupstream/main9d46508f02b6): boots with 10/10 CPUs online, 0 failed units, 0 PMP errors;apple_pmp,apple_pmp_thermal, andapple_pmp_powerbind cleanly (PMP firmware and endpoint ready,J713 PMP vote bridge ready; retained existing PMP owner,pmp_sum_w=0.080 Wmedian,pmp_hotspot_c=50.0 Cmedian).Risk: two-way door · Apple Silicon Macs using
apple_pmp(M1 Pro/Max/Ultra,M2–M5,Neo); preserves existing valid-path behavior while replacing panics and unaligned pointer reads with error returns.Not yet: Hardware runs on non-
T8132PMP Macs (M1 Pro/Max/Ultra,M2,M3,M4 Pro/Max,M5,Neo).Details
set_buf(): replacesunsafe { *(ptr_buf.as_ptr() as *const u64) }withu64::from_le_bytes()over the bounds-checked 8-byte slice.register_ioreg(): propagates errors instead of.unwrap()onCStr::from_bytes_until_nul()andstate.value_buf, checksu32::try_from(len), widens withu64::from(), and callsreserve(1, GFP_KERNEL)on bothstate.ioreg_entriesandstate.ioreg_idsbefore pushing so an OOM on the second push cannot desynchronize the parallel vectors.# Safetydocumentation ondisplay_send()and// SAFETY:comments onunsafe impl Send/Sync for PmpData, and removes a stale// SAFETY:comment above safedev.get_drvdata().Evidence
743e985843eaonupstream/main(9d46508f02b6).scripts/checkpatch.pl --strict --codespell0 errors / 0 warnings;rustfmt --edition 2021 --check drivers/soc/apple/pmp.rsPASS;ARCH=arm64 LLVM=1 CLIPPY=1 drivers/soc/apple/pmp.o0 warnings on touched lines.T8132,7.3.0-j713-20261206+):apple_pmp,apple_pmp_thermal, andapple_pmp_power(hwmon0/hwmon8) active withpmp_sum_w=0.080 Wmedian andpmp_hotspot_c=50.0 Cmedian,0PMP errors,10/10CPUs online,0failed units.