Skip to content

wifi: brcmfmac: pcie: check firmware-supplied TCM addresses and keep console reads in bounds - #2907

Merged
RyanTheTide merged 6 commits into
mainfrom
hardening/brcmfmac-pcie-tcm-bounds-20261123
Nov 27, 2026
Merged

RyanTheTide merged 6 commits into
mainfrom
hardening/brcmfmac-pcie-tcm-bounds-20261123

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

brcmfmac's PCIe code takes several addresses from dongle memory (shared RAM) and reads and writes through them without checking them against the TCM mapping. This series checks them where they are read, and stops the console reader from looping on a write index outside its buffer.

Problem

  • The console descriptor, buffer address, buffer size and write index weren't checked against the mapping. A write index at or past the buffer size also kept brcmf_pcie_bus_console_read() looping forever: the read index wraps at the buffer size and never meets it.
  • The shared RAM block was only checked to start inside the dongle RAM. The mailbox words, ring information, ring memory and (with TCM ring indices) the four index arrays it points to weren't checked at all.
  • The trap record read on a stalled control request (our recovery code) wasn't checked either.

Change

  1. keep console reads inside the TCM and the console buffer: record the TCM mapping length. Accept the console only when its descriptor and buffer lie inside the mapping (otherwise it stays off, as when the firmware reports none), start reading at the beginning of the buffer, and stop on an out-of-range write index. This part also applies to mainline.
  2. check the shared RAM addresses against the TCM: check the shared RAM block, the mailbox words, the ring information, the ring memory and the TCM index arrays (one index per common ring and flowring) when they are read, and fail the probe with -EINVAL if one is outside. Also applies to mainline.
  3. read a trap record only inside the TCM: our stall/trap code. Read the trap record only inside the mapping (the firmware is declared dead either way), reset the trap scan with the console state, and start the scan at the buffer's beginning when the reported index is outside it.
  4. check the ring counts before sizing the host index buffer: with host-memory ring indices, fail the probe when the reported submission/completion ring counts are smaller than the rings the driver hands indices to (applies to mainline).
  5. read no console when the firmware reports none: no descriptor reads for console address 0; drop a stale partial line at console setup (applies to mainline).
  6. take ring pointers from the dongle only inside the ring: a read/write pointer at or past the ring depth is not taken; the last one stays and the update returns -EIO (applies to mainline).

No gates; no new parameters. A firmware whose addresses are all inside the mapping sees no change.

Testing

  • KUnit brcmfmac-pcie-tcm (range helper) passes (arm64 qemu, LLVM=1).
  • New host test tools/asahi/brcmf-shared-tcm-tests.py runs the driver's real shared RAM, ring, host-index, ring-pointer and console code against a fake TCM that asserts on every access outside it: 22 controls pass. Each of its 15 mutations drops one check and fails a control.
  • tools/asahi/brcmf-recovery-tests.py models the TCM size and adds a trap-record control; the new trap-bound mutation fails it.
  • All brcmf host tests pass at each of the six commits (43, 55, 56, 57, 58 and 60 runs).
  • arm64 W=1 build of brcmfmac: no warnings; checkpatch clean apart from the MAINTAINERS note.

Still to run

  • Default command line: J713 Wi-Fi up, s2idle x2, and a firmware console read (brcmfmac debug message level with FWCON). The same on one more BCM4387/BCM4388 Mac (M1 Pro or J616s), since the console change reaches every brcmfmac PCIe chip.
Reviewer detail
  • The shared RAM span checked is up to the end of BRCMF_SHARED_HOST_CAP2_OFFSET, the last field the driver touches.
  • The TCM index check is in the TCM-indices branch only, where idxbuf was never allocated, so the early return leaks nothing. The ring memory check runs before any ring is allocated.
  • The console descriptor/buffer checks in brcmf_pcie_console_trapped() from the earlier version are gone: console init now validates both once, and only the existing write index check remains there.
  • Split out of soc: apple, wifi: bound firmware-supplied sizes and addresses in PMP, AOP2, brcmfmac and centauri #2894 per review: the upstream-applicable console fix is its own commit, the shared RAM checks are new, and the trap/stall part is a separate commit on our code.

…le buffer

The firmware console's descriptor address, buffer address, buffer size
and write index all come from dongle memory. None of them was checked
against the TCM mapping, so console reads could go past the end of the
BAR. A write index at or past the buffer size also kept
brcmf_pcie_bus_console_read() in its loop for good: the read index wraps
at the buffer size and never meets the write index.

Record the length of the TCM mapping. 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 at the beginning of the buffer. The reader
stops 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]>
The shared RAM block and the addresses it holds (the two mailbox words,
the ring information, the ring memory and, when the firmware keeps the
ring indices in its own memory, the four index arrays) are offsets into
the TCM mapping that come from dongle memory. The driver reads and
writes through all of them, but only checked that the shared RAM block
starts inside the dongle's RAM.

Check each against the length of the TCM mapping when it is read, before
it is used, and fail the probe with -EINVAL when one is outside. The
index arrays are checked for one index per common ring and flowring.

Add tools/asahi/brcmf-shared-tcm-tests.py, which runs the driver's
shared RAM, ring and console setup against a fake TCM that asserts on
every access outside it; one mutation per check drops it and fails a
control.

Signed-off-by: Ryan Murray <[email protected]>
When a control request stalls, brcmf_pcie_ctl_stall() reads the trap
type and exception PC from a record whose address comes from shared RAM,
without checking it against the TCM mapping. Read the record only when
it lies within the mapping; the firmware is declared dead either way.

The console trap scan starts at the write index the firmware reports
when the console is set up. Reset the scan with the rest of the console
state, and start it at the beginning of the buffer when that index is
outside the buffer, so a scan that could not start before now does.

tools/asahi/brcmf-recovery-tests.py gives its fake device the TCM size
and adds a control for a trap record past the end of the TCM; the new
mutation trap-bound drops the check and the fake's bounds assertion
fails.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at afa278b.

Follow-up to the #2894 review, brcmfmac part. All three points raised there are fixed. Requesting changes for item 1 because it is an out-of-bounds write into host memory, driven by firmware values, on the path this PR sets out to bound.

Fixed from #2894:

  • Partly bounded (item 1): the shared RAM block (pcie.c:2067), both mailbox words and the ring information (:2112-2118), the ring memory (:1638-1644) and the four TCM index arrays (:1663-1676) are now checked against tcm_size, and the probe fails with -EINVAL. tcm_base_address + offset is covered by the block check (last field touched is HOST_CAP2, :2158).
  • Upstream split (item 2): commit 1 is the console/tcm_size part alone and touches none of our stall/trap code; the trap record check (:1062) and the scan reset are commit 3.
  • Dead re-checks (item 3): brcmf_pcie_console_trapped() keeps only the index check (:1017).

Still open:

  1. Host-memory indices are not sized by what the driver uses. With BRCMF_PCIE_SHARED_DMA_INDEX, idxbuf is allocated for max_submissionrings + max_completionrings entries (:1646-1650), both firmware words, but the rings then take 2 + max_flowrings H2D and 3 D2H slots in it (:1725-1749, :1765-1778) through plain host pointers (brcmf_pcie_read_idx/write_idx, :639-653). A shared version >= 6 firmware reporting max_completionrings < 3, or max_submissionrings < 2 + max_flowrings, gets 16-bit reads and writes past the DMA allocation. This is host memory, not the BAR. Commit 2 checks the same counts for the TCM branch only; add the two comparisons before the allocation.
  2. The index values themselves are used as read: r_ptr/w_ptr come straight from the firmware (:1464, :1482), and brcmf_commonring_get_read_ptr() turns a w_ptr above depth into n_items past the ring's DMA buffer (commonring.c:213-221). Clamp or reject an index >= depth where it is read. A separate patch is fine, but the PR text should not suggest the ring path is now bounded.
  3. brcmf-shared-tcm-tests.py runs with max_submissionrings = 4, max_completionrings = 3 and TCM indices only (shared flags word is 6 at line 144, counts at line 154), so the host-index branch has no control. Add one with item 1.

Rows owed at this head (none run): default command line, Wi-Fi up, s2idle x2 and a firmware console read on J713 and on one BCM4387/BCM4388 Mac (M1 Pro or J616s); plus one firmware-death recovery on either, since console init now also resets the read and scan state on a restart.

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Formal adversarial §1–§6 pre-PR checklist review at afa278b972d13fa675ad82e863e61bddeb36a7a8 (REQUEST_CHANGES — host-memory ring-index bounds blocker, pending CI, and owed §5 hardware rows).

Checklist Summary

  • §1 (No model gating): Pass — no chip, SoC, board, or firmware-version gates; clean upstream/Aurora split across the 3 commits.
  • §2 (Production-ready, no hacks): Pass — no new parameters or delays.
  • §3 (Safety — TCM/host bounds & integer arithmetic): Blocked — brcmf_pcie_tcm_range_valid() (pcie.h:215-219) is overflow-free, and the TCM checks for shared RAM (BRCMF_SHARED_SIZE = 116 covering up to HOST_CAP2), mailboxes, ringinfo, ringmem, TCM index arrays, console descriptor/buffer/write index, and trap record (pcie.c:1062-1069) are sound. However, the host-memory ring-index path (BRCMF_PCIE_SHARED_DMA_INDEX) in the same brcmf_pcie_init_ringbuffers() function still permits firmware-driven out-of-bounds reads/writes in host DMA memory (Blocker #1).
  • §4 (Clean-room & attribution): Pass — all 3 commits carry human author/committer (Ryan Murray <[email protected]>) and human Signed-off-by: only (zero AI trailers in commits); PR body includes Assisted-by:.
  • §5 (Evidence): Blocked — CI still pending and hardware rows unrun.
  • §6 (Naming): Pass.

Blockers

  1. §3 (Safety — Host DMA ring-index buffer under-allocation / OOB read-write, drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c:1646-1778):
    • When BRCMF_PCIE_SHARED_DMA_INDEX is enabled (devinfo->dma_idx_sz != 0), brcmf_pcie_init_ringbuffers() allocates idxbuf of (max_submissionrings + max_completionrings) * devinfo->dma_idx_sz * 2 bytes using untrusted firmware u16 counts (pcie.c:1624-1627), then hands out BRCMF_NROF_H2D_COMMON_MSGRINGS + max_flowrings (2 + max_flowrings) H2D index slots (:1725-1737, :1763-1778) and BRCMF_NROF_D2H_COMMON_MSGRINGS (3) D2H index slots (:1739-1752) accessed via plain host pointer arithmetic (brcmf_pcie_read_idx()/brcmf_pcie_write_idx(), :639-654).
    • On shared.version >= 6, firmware reporting max_submissionrings < BRCMF_NROF_H2D_COMMON_MSGRINGS + max_flowrings or max_completionrings < BRCMF_NROF_D2H_COMMON_MSGRINGS (including 0) causes out-of-bounds 16-bit reads/writes in host DMA memory.
    • Commit 2 validates those exact slot counts on the TCM-index branch only; validate max_submissionrings >= BRCMF_NROF_H2D_COMMON_MSGRINGS + max_flowrings and max_completionrings >= BRCMF_NROF_D2H_COMMON_MSGRINGS before allocating idxbuf, and add a BRCMF_PCIE_SHARED_DMA_INDEX host-index test case + mutation in tools/asahi/brcmf-shared-tcm-tests.py (which currently only exercises dma_idx_sz == 0).
  2. §5 (Owed hardware verification rows & pending CI):
    • CI at afa278b972d1: 3/7 green (source, host-tests, rust-build); 4/7 still queued (kunit, DWC3/ATC ×3).
    • Owed on hardware at the final head (default command line): Wi-Fi up, s2idle ×2, firmware console read (FWCON), and regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors) on J713 and on one BCM4387/BCM4388 Mac (M1 Pro or J616s), plus a firmware-death recovery test on either.

Non-blocking Technical Notes

  • Console disabled sentinel (pcie.c:1142-1151): When firmware reports console->base_addr == 0 ("no console"), brcmf_pcie_tcm_range_valid(devinfo->tcm_size, 0, 12) succeeds and brcmf_pcie_bus_console_init() reads offsets 0..11 (ARM vectors) before later readers ignore the console because !console->base_addr. Guarding if (!console->base_addr || !brcmf_pcie_tcm_range_valid(...)) avoids bogus init reads/logs; resetting console->log_idx = 0 on re-init would also drop any stale partial line across firmware restart.
  • Ring r_ptr/w_ptr values (pcie.c:1464, 1482 → commonring.c:213-221): Firmware-supplied ring pointer values are still not bounds-checked against commonring->depth (a w_ptr > depth yields an out-of-bounds n_items in brcmf_commonring_get_read_ptr()). Fine to track in a follow-up patch, provided the PR description makes clear that ring-pointer value clamping is separate.

…dex buffer

When the firmware keeps the ring indices in host memory, the index
buffer is sized from the submission and completion ring counts it
reports, while the driver hands out one index per common ring and
flowring. A firmware that reports fewer submission rings than common
rings plus flowrings, or fewer completion rings than common completion
rings, made the driver read and write indices past the end of the
buffer.

Check both counts before the buffer is allocated and fail the probe
with -EINVAL when they are short. Shared RAM versions before 6 derive
the counts from the flowring count and always pass.

tools/asahi/brcmf-shared-tcm-tests.py now uses the driver's own host
index accessors and has controls for host indices; the mutation
dma-counts drops the check.

Signed-off-by: Ryan Murray <[email protected]>
A console address of 0 means the firmware has no console, but the
console setup still read its descriptor at the start of the TCM before
the readers ignored it. Skip the reads in that case, and drop a partial
console line left from an earlier firmware when the console is set up
again.

tools/asahi/brcmf-shared-tcm-tests.py gets a control for a firmware
without a console; the mutation console-none drops the check.

Signed-off-by: Ryan Murray <[email protected]>
…the ring

The read and write pointers of the message rings are read back from the
dongle (from TCM or from the host index buffer) and used as ring
positions: the common ring code computes item counts and buffer
addresses from them. A pointer at or past the ring depth made it reach
past the end of the ring buffer.

Take a pointer only when it is below the ring depth; otherwise keep the
last one, log it (rate-limited) and return -EIO, as the update does
when the bus is down.

tools/asahi/brcmf-shared-tcm-tests.py gets a control for both updates;
the mutations rptr-depth and wptr-depth drop the checks.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Thanks. Addressed at 73d8f7c (three new commits, no history rewrite):

  • Host index buffer (blocker 1): 6b6878e checks max_submissionrings >= BRCMF_NROF_H2D_COMMON_MSGRINGS + max_flowrings and max_completionrings >= BRCMF_NROF_D2H_COMMON_MSGRINGS before idxbuf is allocated, and fails the probe with -EINVAL. Shared RAM versions before 6 derive the counts from the flowring count, so they always pass. The host test now uses the driver's own brcmf_pcie_read_idx()/brcmf_pcie_write_idx() and has host-index controls (well formed, short submission count, zero completion count) plus a dma-counts mutation.
  • No-console sentinel: 2c9da32 skips the descriptor reads when the console address is 0 and resets log_idx at console setup. New control + console-none mutation.
  • Ring r_ptr/w_ptr vs depth: done here rather than as a follow-up (73d8f7c). brcmf_pcie_ring_mb_update_rptr()/_wptr() take a dongle pointer only when it is below commonring->depth. Otherwise they keep the last one, log (the pcie.c brcmf_err is net_ratelimited) and return -EIO, as they already do when the bus is down. Control + rptr-depth/wptr-depth mutations.

Tests: host brcmf-* 60/60 (shared-tcm: 22 controls, 15 mutations all killed); every one of the six commits passes the brcmf host tests on its own (43/55/56/57/58/60 runs). KUnit brcmfmac-pcie-tcm passes; arm64 W=1 of brcmfmac: 0 warnings; checkpatch clean.

Hardware rows (J713 + one BCM4387/4388 Mac: Wi-Fi up, s2idle x2, FWCON console read, regression counts, firmware-death recovery) are next on a kernel at this head.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at 73d8f7c.

Three new commits on top of afa278b, no history rewrite. Status of the points from my last review:

  1. Host index buffer sized from firmware counts: fixed. 6b6878e checks max_submissionrings >= 2 + max_flowrings and max_completionrings >= 3 before idxbuf is allocated and fails the probe (pcie.c:1667-1675). It returns before any allocation, so there is nothing to unwind. Shared versions before 6 derive the counts, and a max_flowrings underflow there is still caught by the > 512 check.
  2. Ring index values from the dongle: fixed in this PR (73d8f7c). update_rptr/update_wptr take the index only when it is below depth and otherwise keep the last one (:1466-1475, :1493-1502). With both pointers kept in range, brcmf_commonring_get_read_ptr() and reserve_for_write stay inside the ring buffer. The commonring callers ignore the return value, so a dongle that keeps reporting a bad index leaves the ring stalled with a rate-limited error rather than recovering. That is the safe outcome, and the firmware-death row will show what happens next.
  3. No host-index control in the test: fixed. The test now compiles the driver's own read_idx/write_idx and update_rptr/update_wptr, with a well-formed host-index control, short submission and zero completion cases, and dma-counts, rptr-depth, wptr-depth mutations. The console-desc mutation was rewritten to match the new condition, so it still bites.

Dj's console notes are also done (2c9da32): no descriptor reads when the console address is 0, and log_idx is reset at console setup (:1145-1153).

Nothing new found. Small remark, not blocking: the ring-pointer check is >= depth. That is right for the dongle's view, where an index equal to depth never appears because it wraps to 0. Saying so in the comment at :1467 would save the next reader the same question. Commit trailers are fine.

Verdict: APPROVE on code. Rows owed at this head (none run): on the default command line, Wi-Fi up, s2idle x2 and a firmware console read on J713 and on one BCM4387/BCM4388 Mac (M1 Pro or J616s), plus one firmware-death recovery on either. The author has these next. CI is still running (4 pending).

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Formal adversarial §1–§6 re-review at 73d8f7cde2683357de5cd04e28638f68785626c1 (REQUEST_CHANGES — Wave 60C host idxbuf blocker + both technical notes resolved cleanly with 0 remaining code blockers; still blocked on owed §5 hardware rows and 1 queued CI check).

Wave 60C Fix Verification (3 new commits, no history rewrite)

  1. Host idxbuf ring-count check (6b6878e84275, pcie.c:1666-1683): Fixed. Before allocating devinfo->idxbuf when devinfo->dma_idx_sz != 0, validates max_submissionrings >= BRCMF_NROF_H2D_COMMON_MSGRINGS + max_flowrings and max_completionrings >= BRCMF_NROF_D2H_COMMON_MSGRINGS, failing probe with -EINVAL before any allocation. Verified overflow-free sizing: max_flowrings <= 512, u16 counts yield bufsz <= (65535 + 65535) * 4 * 2 = 1,048,560 bytes, and all H2D (2 + max_flowrings write + read) and D2H (3 write + read) index slots fit within bufsz. If dma_alloc_coherent() fails, fallback to dma_idx_sz = 0 runs the TCM index range checks. tools/asahi/brcmf-shared-tcm-tests.py now compiles the real brcmf_pcie_read_idx()/brcmf_pcie_write_idx() with valid, short-submission, and zero-completion host-index controls plus the dma-counts mutation.
  2. No-console sentinel & log_idx reset (2c9da3201cd8, pcie.c:1143-1153): Fixed. Resets bufsize, read_idx, log_idx, scan_idx, and scan_len on init and skips descriptor reads when console->base_addr == 0, with matching control and console-none mutation.
  3. Dongle r_ptr/w_ptr bounds vs ring depth (73d8f7cde268, pcie.c:1468-1474, 1495-1501): Fixed. brcmf_pcie_ring_mb_update_rptr() and _wptr() reject ptr >= commonring->depth, preserving the last valid pointer, logging rate-limited brcmf_err, and returning -EIO. Verified against commonring.c (reserve_for_write*, get_read_ptr): keeping 0 <= r_ptr, w_ptr < depth guarantees all ring buffer indexing stays in bounds. Controls and rptr-depth/wptr-depth mutations added to brcmf-shared-tcm-tests.py and run-host-tests.py.

Checklist Summary

  • §1 (No model gating): Pass.
  • §2 (Production-ready, no hacks): Pass.
  • §3 (Safety): Pass — TCM bounds, host idxbuf sizing, console bounds, trap record bounds, and ring pointer depth bounds are all verified sound.
  • §4 (Clean-room & attribution): Pass — all 6 commits carry human author/committer (Ryan Murray <[email protected]>) and human Signed-off-by: only (zero AI trailers in commits); PR body includes Assisted-by:.
  • §5 (Evidence): Blocked — see Remaining Blockers below.
  • §6 (Naming): Pass.

Remaining Blockers

  1. §5 (Owed hardware verification rows): No hardware rows posted yet at 73d8f7cde268. Owed on the default command line: Wi-Fi up, s2idle ×2, FWCON firmware console read, and regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors) on J713 and on one BCM4387/BCM4388 Mac (M1 Pro or J616s), plus a firmware-death recovery test on either.
  2. CI still finishing: 6/7 green (host-tests, source, rust-build, kunit, DWC3/ATC builtin-no-atc, DWC3/ATC modular-no-atc); 1/7 QUEUED (DWC3/ATC builtin-modular-atc).

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) area:wireless Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 73d8f7cd: ready to merge

Check Detail
CI at head ok 7 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at 73d8f7cd
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:gpu, area:wireless
Merge: gh pr merge 2907 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: FINISH, then merge at 73d8f7cde268: the code is ready; it needs only a row at this head.

Blockers: none in the code. Missing row: one brcmfmac Mac at this head (J713, or a BCM4387/4388 Mac such as the J616s): Wi-Fi up, two s2idle cycles, and the firmware console read working.

Checked: no Apple material, no gates. Firmware-supplied TCM addresses are checked, and console reads stay in bounds. CI green.

@DjDeveloperr
DjDeveloperr dismissed stale reviews from themself November 25, 2026 04:05

Superseded by the review at 73d8f7c

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 25, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

73d8f7cde268 J413 (BCM4387) PASS / J713 (BCM4388) FAIL — new brcmfmac kernel error caught on BCM4388 (7.3.0-aurora-pr2907+, CONFIG_BRCMDBG=y, guarded one-shot, default cmdline; both restored to saved kernels):

  • J713 (M4 Air, BCM4388 [14e4:4434], boot_id=1e531320) — FAIL (new kernel error from 73d8f7cde268):
    • At t=16.329s during Wi-Fi bring-up / association, the new ring-pointer bounds check logged a kernel error and returned -EIO:
      [ 16.329278] brcmfmac 0000:01:00.0: brcmf_pcie_ring_mb_update_rptr: ring 4: r_ptr 0 outside depth 0
    • Likely a TX flowring (ring 4) polled while commonring->depth == 0 during ring setup/teardown (ptr >= commonring->depth triggers 0 >= 0).
    • Functional Wi-Fi still worked: wld0 associated on 5 GHz (5745 MHz, 270/400 MBit/s), ping 5/5 (0% loss) pre-wake, post-wake 1 (rtc1 8 s), and post-wake 2 (rtc1 8 s, suspend_stats: success=2 fail=0), Enforcing, 0 failed, 0 AVC. Restored saved 7.3.0-aurora-fleet85 (boot_id=b8f6c040, trial removed).
  • J413 (M2 Air, BCM4387 [14e4:4433], boot_id=44379920) — PASS:
    • wld0 associated on 5 GHz (5745 MHz, 300/400 MBit/s), ping 5/5 (0% loss) pre-wake, post-wake 1 (rtc1 8 s), and post-wake 2 (rtc1 8 s, suspend_stats: success=2 fail=0), 0 brcmfmac errors, GL (Apple M2 (G14G B0)) + Borealis VK PASS, Enforcing, 0 failed, 0 AVC, 0 new kernel errors. Restored saved 7.3.0-aurora-fleet89 (boot_id=cbc65377, trial removed).

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) ready-to-merge Meets the merge policy: merge it (bot) labels Nov 25, 2026
@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed ready-to-merge Meets the merge policy: merge it (bot) labels Nov 25, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

73d8f7cde268 (batched cleanly in J616s Batch #2 5b411e230229 over main 95a983c08be4, 0 merge-tree diffs across all 8 changed files) J616s (MacBook Pro 16" M4 Pro, T6040, BCM4388/6, guarded one-shot 7.3.0-aurora-pr2905+, default cmdline, boot_id=de17fad3) FINDING / FAIL (new brcmfmac KERN_ERR):

  • During normal boot + 2x rtc1 s2idle on BCM4388/6 (0000:01:00.0, firmware 23.10.1039.0.41.51.239 FWID 01-974167da), commit 73d8f7cde268 logged a new kernel error not present on stock fleet89 or Batch mux: apple-display-crossbar: replace the T602x selector fields instead of OR-ing them #1:
    brcmfmac 0000:01:00.0: brcmf_pcie_ring_mb_update_rptr: ring 4: r_ptr 0 outside depth 0
    
  • Root cause: brcmf_pcie_ring_mb_update_rptr() now checks if (ptr >= commonring->depth) and logs brcmf_err + returns -EIO. For flowrings / unconfigured or torn-down rings where commonring->depth == 0 (before brcmf_commonring_config() or after teardown), r_ptr == 0 satisfies 0 >= 0 and triggers the out-of-bounds error path even though the dongle pointer is 0.
  • Wi-Fi stayed up (3/3 ping pre- and post-s2idle), 0 failed units, 0 GPU faults, Enforcing, 2/2 s2idle; stock 7.3.0-aurora-fleet89 restored & verified (b67edc6c).

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

MERGETRAIN6: HOLD at 73d8f7cde268. The readiness bot counts the row comments as hardware rows, but two of them are FAILs from this change. On J713 (BCM4388, 11-25 05:44) and J616s (BCM4388/6, Batch #2), brcmf_pcie_ring_mb_update_rptr logs ring 4: r_ptr 0 outside depth 0 and returns -EIO. Stock fleet89 never logs this.

Cause: the new bounds check ptr >= commonring->depth also fires for a flowring that has not been configured yet or was already torn down. Such a ring has depth == 0, and the dongle's index 0 then satisfies 0 >= 0. Suggested fix: treat depth == 0 as "ring not live" and return without updating or logging, in both update_rptr and update_wptr, so the bound applies only to configured rings. Add a host-test case for depth 0 with ptr 0. Then the J713 or J616s row at the new head needs zero brcmfmac errors, plus the J413 regression row.

Routed to the owner lane (SEC-SOC2).

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide
RyanTheTide merged commit 0c2e7d0 into main Nov 27, 2026
10 of 11 checks passed
@RyanTheTide
RyanTheTide deleted the hardening/brcmfmac-pcie-tcm-bounds-20261123 branch November 27, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) area:wireless Area from CODEOWNERS (bot) needs-template PR body lacks Tested or Risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants