Repository navigation
soc: apple, wifi: bound firmware-supplied sizes and addresses in PMP, AOP2, brcmfmac and centauri - #2894
soc: apple, wifi: bound firmware-supplied sizes and addresses in PMP, AOP2, brcmfmac and centauri#2894RyanTheTide wants to merge 5 commits into
Conversation
The PMP firmware asks the driver for DMA buffers (OPC_MALLOC) and for register slots (OPC_REGISTER_IOREG). Every request was granted and kept until the firmware freed it, so the number of buffers held for it, their total size and the register list had no bound. Count the live allocations and their size, and refuse one that would go over 64 buffers or 64 MiB, four of the largest buffer a single request can ask for (its size field is 24 bits). These are sanity bounds well above normal use: the driver's lists are sized for ten buffers and 340 registers, which is what a normal boot uses. A freed buffer gives its room back. Refuse a register once the list has 0xffff entries. The reply carries the new entry's index in 16 bits below the opcode, so a larger index cannot be returned without corrupting the reply. A refused request gets no reply and is logged, as other requests the driver cannot handle are. The bounds are in pmp_alloc.rs with host tests, run by tools/asahi/run-host-tests.py as pmp-alloc-tests.rs. Signed-off-by: Ryan Murray <[email protected]>
Each AFK_GETBUF from the AOP2 firmware allocated a new device-managed coherent buffer and stored it in the endpoint's ring, replacing the one before. Those buffers are only released at unbind, which this driver does not allow, so a repeated GETBUF kept adding buffers. The stores of the buffer and its size were also not ordered against t6050_aop2_view(), which reads the rings from the resume path in another thread, so a reader could pair a new buffer with an old size. An endpoint now gets one buffer for as long as the firmware runs. A repeated GETBUF of the same size is answered with the same IOVA; one with no size or with another size is refused and logged (ratelimited), without an answer. The buffer is published with smp_store_release() after its size and IOVA, and t6050_aop2_view() reads it with smp_load_acquire(), so a reader that finds the buffer also finds its size. As the buffer never changes once set, no lock is needed between the RTKit receive worker and the readers. Add KUnit tests (CONFIG_APPLE_T6050_AOP_KUNIT_TEST, suite apple_t6050_aop) for the GETBUF decision and the ring view's bounds. Signed-off-by: Ryan Murray <[email protected]>
…M mapping When a control request stalls, brcmf_pcie_ctl_stall() reads two words of the trap record at an address taken from shared RAM, and the console code reads its descriptor, write index and buffer at addresses taken from shared RAM. None of them was checked against the size of the TCM mapping. Record the BAR2 length at mapping time. Read the trap record only when it lies within the mapping; the firmware is still declared dead either way. When the console is set up, accept its descriptor and buffer only when both lie within the mapping, otherwise leave the console disabled as when the firmware reports none, and start reading it from the beginning of the buffer. The console reader and the trap scan stop when the firmware's write index is outside the buffer. Add a KUnit case for the range check. Signed-off-by: Ryan Murray <[email protected]>
Every reply to the statistics command overwrites stats_length, while station_stats_valid is only set by a station counter record of a supported length. A later reply carrying another record leaves the counters marked valid with a length that no longer describes them, and the debugfs and connection readers then iterate past station_stats. Record the length of the accepted counter record in its own field, set together with station_stats_valid, and iterate over that. Move the statistics reply handling into a helper so that it can be tested, and add a KUnit case for it (CONFIG_APPLE_CENTAURI_KUNIT_TEST). Signed-off-by: Ryan Murray <[email protected]>
|
Review at e0b2c56. All four fixes are correct as far as they go, and the centauri commit is good as is. The issues below are about how complete the bounds are and how strict they are.
Rows owed at this head (none run yet): J713 boot on default cmdline with PMP probe, brcmfmac Wi-Fi up, and s2idle x2 (plus the PMP counts from item 7). Neo with PMP and s2idle x2. One other BCM43xx Mac (BCM4387/4388) for Wi-Fi up and a console read, because the console_init change reaches every brcmfmac PCIe chip. A T6050 row for AOP2 probe, sensors/mics and a sleep/wake cycle. A J813/J815/J873 row for Wi-Fi join and a |
brcmf_pcie_ctl_stall() and brcmf_pcie_console_trapped() now check the trap record and the console buffer against devinfo->tcm_size with brcmf_pcie_tcm_range_valid() from pcie.h. Give the fake device that field (the size of its fake dongle RAM), take the helper from pcie.h, and add two controls: a trap record and a console buffer that end past the fake RAM are not read, and the firmware is still declared dead for the trap. The new mutations trap-bound and console-bound drop the checks; the fake RAM's bounds assertion then fails. Signed-off-by: Ryan Murray <[email protected]>
|
Review at da76d20. The only change since e0b2c56 is one new commit, da76d20, which updates the host harness
No new issues. There are no agent trailers in the commits, and the body ends correctly. Verdict: CHANGES (1, 2, 4, 9 must be fixed; 5 and 6 are wording/nits; 7 needs data). Rows owed (none run yet), all on the default cmdline:
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review at da76d208afd980704c5bbe3ee0ece40ce41153a5 (all 7 CI checks green: host-tests fixed by da76d208af, source, rust-build, kunit, and all 3 DWC3/ATC builds pass).
Blockers
- §1 / §5 Zero hardware test rows across all 4 touched subsystems:
Only QEMU KUnit, host tests, andW=1builds have been run at this head; every hardware row is still listed under "Still to run":- PMP (
drivers/soc/apple/pmp.rs): Needs J713 and Neo default-cmdline boot +s2idlex2 rows, including live allocation count/bytes andioreg_entries.len()after boot and after wake (sinceioreg_entriesis never cleared and a refusal triggersfail_display()on boards with a display bridge). - AOP2 (
drivers/soc/apple/t6050-aop.c): Needs a T6050 probe + sleep/wake hardware row. - brcmfmac (
drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c): Needs J713 plus another BCM43xx Mac (BCM4387/4388) Wi-Fi up + console read row. - centauri (
drivers/net/wireless/apple/centauri/centauri_wifi.c): Needs a J813/J815/J873 Wi-Fi join +station_statsread row. - Include §5 regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors) on each row.
- PMP (
- §2 AOP2
GETBUFrefusal is too strict without T6050 wake evidence (drivers/soc/apple/t6050-aop.c:149-157):
t6050_aop_getbuf_check()refuses any repeatGETBUFwithsize != r->sizewithout sending an ACK, leaving that endpoint hung until reboot. Without T6050 wake evidence proving identical sizes on every wake, acceptingsize <= r->size(reusing the existing larger buffer) and refusing onlysize > r->sizeis safer. - §2 Potential
u32wrap inbrcmf_pcie_console_trapped()range check (drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c:1013-1014):
Passingconsole->base_addr + BRCMF_CONSOLE_WRITEIDX_OFFSETas au32offset tobrcmf_pcie_tcm_range_valid(..., 4)wraps around ifconsole->base_addris nearU32_MAX. Validatebrcmf_pcie_tcm_range_valid(devinfo->tcm_size, console->base_addr, BRCMF_CONSOLE_WRITEIDX_OFFSET + 4)(matchingconsole_init()), or drop the redundant check sinceconsole_init()already zeroesbase_addrunless both descriptor and buffer lie withintcm_size.
Non-blocking notes
- Subsystem bundling: Grouping 4 independent subsystems (PMP, AOP2, brcmfmac, centauri) with disjoint hardware requirements blocks lab-testable fixes (PMP, brcmfmac) behind hardware the lab lacks (T6050, J813). Splitting into one PR per subsystem is strongly recommended.
- brcmfmac scope vs title: Only trap and console offsets are bounded here;
ring_info_addr,htod_mb_data_addr/dtoh_mb_data_addr,ringmem, andtcm_base_addressoffsets remain unchecked againsttcm_size. Either validate them inbrcmf_pcie_init_share_ram_info()or narrow the PR title. - PMP constant duplication (
pmp_alloc.rs:6vspmp.rs:90):MALLOC_SIZE_MAX = 1 << 24is off by 1 fromMALLOC_SIZE_MASK = 0xFFFFFF, makingsize > MALLOC_SIZE_MAXunreachable from the masked 24-bit field; derive from one constant. - AOP2 commit message: "no lock is needed between the RTKit receive worker and the readers" holds for
buf/size, whereastx_off/tx_size/tx_readyremain plain stores (still memory-safe becauset6050_aop2_view()validates them against fixedr->size). - centauri (
centauri_wifi.c:1291,2307): Thedev_info()andseq_printf()headers still reportwifi->stats_length(the last reply's length) while the loop iterateswifi->station_stats_len.
Checklist summary
- §1 No model gating: Pass in code; blocked on multi-Mac hardware coverage.
- §2 Production-ready: Blocked on AOP2 strict-size refusal and
console_trapped()u32 addition wrap. - §3 Safety: Pass (defensive bounds derived from wire/BAR formats, not hardcoded hardware-protection limits).
- §4 Clean-room & attribution: Pass (human author/committer + human
Signed-off-by:only across all 5 commits, zero AI trailers in commits,Assisted-by:in PR body). - §5 Evidence: Strong KUnit/host-test/mutation coverage and green CI (7/7), blocked on zero hardware rows.
- §6 Naming: Pass.
Assisted-by: LLM (Gemini 4 Neon)
|
Thanks for the review. Split per subsystem as asked (item 9); this PR is superseded by:
All four are on the current
Rows are listed under "Still to run" on each PR. AOP2 and centauri need M5 / J8xx rows the lab doesn't have. |
Four independent fixes, one commit each (plus a host-test harness update for the brcmfmac one), where these drivers took sizes, addresses or counts from their coprocessor firmware without checking them.
Problem
soc: apple: pmp): every buffer request and register registration from the firmware was granted and kept, with no bound on the number of live buffers, their total size or the register list. The register reply carries the new index in 16 bits.soc: apple: t6050-aop): everyAFK_GETBUFallocated a new device-managed buffer that is only released at unbind, and the buffer and its size were published without ordering against the reader on the sleep/wake path.Change
No gates on chip, board or firmware version; no new parameters.
Testing
LLVM=1):apple_t6050_aop5/5,brcmfmac-pcie-tcm1/1,apple-centauri-wifi1/1 pass. With the fixes reverted (tests kept), 5 cases fail: 3 inapple_t6050_aop, the brcmfmac and the centauri case.tools/asahi/pmp-alloc-tests.rs(inrun-host-tests.py): passes; with the bounds removed, 4 of 5 checks fail.tools/asahi/brcmf-recovery-tests.py(fake dongle RAM) now models the TCM size: 11/11 runs pass, including two new mutations that drop the trap and console bounds (both caught by the fake RAM's bounds assertion). Fullrun-host-tests.pylocally: 458/464, the 6 others are timeouts in unrelated GPU/DCP/USB tests on a loaded build box.W=1build ofdrivers/soc/apple/, brcmfmac and centauri: no new warnings. rustfmt and checkpatch clean apart from the MAINTAINERS notes.Still to run
apple,t6050-aop2) and the centauri path need an M5 row; we don't have one in the lab, a row from someone with one is welcome.PMP detail
Problem
The PMP driver grants every buffer request (
OPC_MALLOC) and every register registration (OPC_REGISTER_IOREG) the firmware sends and keeps them until the firmware frees them. Neither the number of live buffers, their total size, nor the length of the register list was bounded. The register reply also carries the new entry's index in 16 bits, which a longer list cannot represent.Change
pmp_alloc.rswithAllocBudget: at most 64 live allocations and 64 MiB in total (four of the largest buffer one request can describe, its size field being 24 bits). A freed buffer returns its room. Normal boots use about ten buffers.register_ioreg()refuses a registration once the list holds 0xffff entries, so the index always fits its reply field.Testing
tools/asahi/pmp-alloc-tests.rs(wired intorun-host-tests.py): 5/5 pass; with the bounds removed, 4 of 5 fail.drivers/soc/apple/: see details.Still to run
Reviewer detail
state(aMutex, so sleeping allocation is fine), which keeps claim, allocation and push atomic with respect tofree().claim()callsrelease().AOP2 detail
Problem
Each
AFK_GETBUFfrom the AOP2 firmware allocated a new device-managed coherent buffer and stored it in the endpoint's ring, replacing the previous one. Device-managed buffers are only released at unbind, which this driver does not allow, so repeated requests (for example one per wake) kept adding buffers. The buffer pointer and its size were also published without ordering againstt6050_aop2_view(), which reads the rings from the sleep and wake paths on another thread.Change
GETBUFof the same size is answered with the same IOVA; a request with no size or a different size is refused and logged (ratelimited).smp_store_release()after its size and IOVA, andt6050_aop2_view()reads it withsmp_load_acquire(). The buffer never changes once set, so no lock is needed.Testing
apple_t6050_aop(CONFIG_APPLE_T6050_AOP_KUNIT_TEST, arm64 qemu): see details. With the old behaviour (every request allocates) the reuse/refusal cases fail.Still to run
brcmfmac detail
Problem
On a stalled control request,
brcmf_pcie_ctl_stall()reads the trap record at an address taken from shared RAM, and the console code (brcmf_pcie_bus_console_init(),brcmf_pcie_bus_console_read(),brcmf_pcie_console_trapped()) reads its descriptor, write index and buffer at addresses taken from shared RAM. None of these offsets was checked against the size of the TCM mapping.Change
tcm_size) when the TCM is mapped.brcmf_pcie_tcm_range_valid(). The trap record is read only when it lies within the mapping; otherwise its address is logged. At console setup the descriptor and buffer are accepted only when both lie within the mapping; otherwise the console stays disabled, as when the firmware reports none. The console reader and the trap scan stop when the write index is outside the buffer, and reading starts at the beginning of the buffer after each setup.Testing
brcmfmac-pcie-tcm(range edge cases incl. wrap-around): see details.Still to run
centauri detail
Problem
Every reply to the statistics command overwrites
stats_length, whilestation_stats_validis set only by a station-counter record of a supported length. A later reply carrying another record leaves the counters marked valid with a length that no longer describes them, and the debugfs and connection readers iteratestation_statsby that length.Change
station_stats_len, set together withstation_stats_validand cleared with it; both readers iterate over it.record_stats_reply()so it can be tested. No other behaviour change.Testing
apple-centauri-wifi(CONFIG_APPLE_CENTAURI_KUNIT_TEST): a valid record followed by a reply with another record keeps the recorded length; unsupported lengths are not recorded. See details.Still to run
station_statsread). Not in our lab.Assisted-by: LLM (Claude:Opus 5.5)