Skip to content

wifi: brcmfmac: skip a scanned BSS on a band or channel the wiphy doesn't have - #191

Merged
derekross merged 1 commit into
derekross:omamobilefrom
W4HO-ham:brcmfmac-inform-null-chan
Nov 8, 2026
Merged

derekross merged 1 commit into
derekross:omamobilefrom
W4HO-ham:brcmfmac-inform-null-chan

Conversation

@W4HO-ham

@W4HO-ham W4HO-ham commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

brcmf_inform_single_bss() hands cfg80211 the result of ieee80211_get_channel() without checking it. The BCM4383 on the palmtop reports channel 177 (5 GHz UNII-4), which brcmf_construct_chaninfo() drops from the band table at every boot ("Ignoring unexpected firmware channel 177"), so a nearby access point on it gives a NULL channel. Today, during a sleep series, the escan timeout worker oopsed on it in cfg80211_inform_single_bss_data(). The worker died inside cfg80211's RCU read-side section, the next suspend couldn't freeze khugepaged (stuck in lru_add_drain_all()), ACPM stopped answering and the palmtop reset. pstore kept the console, and the trace is in the commit message.

The fix skips such a BSS with a debug message and returns 0, so brcmf_inform_bss() still reports the rest of the list. Upstream wireless-next has the same unchecked lookup.

Checked: checkpatch --strict (one long line, the quoted oops), W=1 arm64 build of cfg80211.o with clang, tools/kernel-pr-check. Not yet run on the palmtop: the oops was rare (one boot of the last fifteen), so the test there is that scanning and connecting still work. I'll add that result here.

@W4HO-ham
W4HO-ham force-pushed the brcmfmac-inform-null-chan branch from fbe485d to 12a4a80 Compare November 3, 2026 18:22
@W4HO-ham W4HO-ham changed the title wifi: brcmfmac: skip a scanned BSS on a channel the wiphy doesn't have wifi: brcmfmac: skip a scanned BSS on a band or channel the wiphy doesn't have Nov 3, 2026
@W4HO-ham

W4HO-ham commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

This is the small PR on omamobile you asked for on #56 and #187 (item 2), and it carries #56's fourth commit forward. Reworked as you suggested: the chanspec is decoded for every BSS, a 6 GHz one is skipped on its decoded band first, and the NULL check stays as the backstop. It now has Fixes: 5b435de0d786 (the unchecked lookup goes back to the driver's first commit, by upstream blame). The message also says what the console recorded: Invalid chanspec 0x5001 (6 GHz channel 1) from the palmtop's older out-of-tree brcmutil just before, and channel 177 on every boot. The BSS the scan was reporting when it crashed wasn't logged.

checkpatch --strict (the quoted oops line, and the upstream commit ID this grafted tree doesn't have), W=1 arm64 clang build of cfg80211.o, kernel-pr-check: clean. Still to come: the 9a test note (uname -r, the cfg80211.c blob id, scans with no oops). It needs the palmtop on a kernel with the in-tree driver, which I'll build from #187's head for your item 5 too.

@derekross

Copy link
Copy Markdown
Owner

Thank you, @W4HO-ham, for turning this into its own small PR so quickly, and for the 6 GHz rework. I checked the crash path: with a NULL channel, cfg80211 reads channel->band in cfg80211_get_bss_channel(), which matches the oops at address 0. Mainline has the same unchecked lookup, and the Fixes: id resolves upstream to the driver's first commit. kernel-pr-check --build --merge on today's omamobile passes (the only warning is the quoted oops line), and CI is green.

My 7 Pro has the same latent bug: its BCM4389 logs "Ignoring unexpected firmware channel 169/173/177" at every boot, so an access point on those channels would crash it too. The fix is right for both phones. The 6 GHz skip also changes what my 7 Pro shows, though. Until now a 6 GHz BSS whose channel number also exists on 2.4 or 5 GHz (1, 5, 9, 149 and so on) was reported on the wrong band, and now it drops out of the scan list. That's correct, but my run on the 1st covered only the NULL check, so I'll run this version on the 7 Pro (join, scans compared with the base kernel) before I merge.

From you, before it lands: the 9a note you mentioned, with uname -r, the cfg80211.c blob id you loaded, and scans with no oops.

Small things, none blocking:

  • struct brcmu_chan ch isn't initialised, and the d11ac decoder leaves band unset for band bits 0x8000 (with a WARN). The new 6 GHz test would then read garbage. = {} would cover it.
  • One sentence in the message about the wrong-band case would explain the visible change.
  • For upstream, the NULL check stands alone (worth a Cc to stable). The 6 GHz part needs our brcmutil 6 GHz decode first, so I'd send them separately.

…sn't have

brcmf_inform_single_bss() picks the band from the channel number alone,
turns it into a frequency and hands cfg80211 the result of
ieee80211_get_channel() unchecked. For a channel the wiphy doesn't
carry that lookup returns NULL, and cfg80211 dereferences it.

The firmware does report such BSSes. A 6 GHz chanspec's channel number
is read as a 2.4 or 5 GHz one (6 GHz channel 37 becomes 5185 MHz,
which no band has), and since brcmf_construct_chaninfo() skips 6 GHz
chanspecs there is no 6 GHz band to find it in anyway. A 5 GHz channel
the band table doesn't have does the same: on a Pixel 9a (BCM4383)
every boot with Wi-Fi logs "brcmf_construct_chaninfo: Ignoring
unexpected firmware channel 177" (UNII-4). The boot that crashed had
just warned "Invalid chanspec 0x5001" (6 GHz, channel 1) from an older
brcmutil without the 6 GHz band; which BSS the scan was reporting when
it crashed wasn't logged. Once, from the escan timeout worker:

  Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
  Workqueue: events brcmf_cfg80211_escan_timeout_worker [brcmfmac]
  pc : cfg80211_inform_single_bss_data+0xb0/0x4fc [cfg80211]
  Call trace:
   cfg80211_inform_single_bss_data+0xb0/0x4fc [cfg80211] (P)
   cfg80211_inform_bss_data+0xbc/0x12d4 [cfg80211]
   brcmf_inform_single_bss+0x190/0x20c [brcmfmac]
   brcmf_cfg80211_escan_timeout_worker+0x80/0xec [brcmfmac]

The worker died inside cfg80211's RCU read-side section, so the next
system suspend couldn't freeze khugepaged (stuck in lru_add_drain_all())
and the phone reset a few seconds later.

Decode the chanspec for every BSS and skip a 6 GHz one first, then keep
a NULL check on the channel as the backstop. A 6 GHz BSS whose channel
number also exists on 2.4 or 5 GHz (1, 5, 9, 149 and so on) was
reported until now on the wrong band; it now drops out of the scan list,
which is a visible change on any chip whose firmware reports 6 GHz. Both return 0 with a debug
message, so the rest of the scan list is still reported:
brcmf_inform_bss() stops at the first error.

Fixes: 5b435de0d786 ("net: wireless: add brcm80211 drivers")
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
@W4HO-ham
W4HO-ham force-pushed the brcmfmac-inform-null-chan branch from 12a4a80 to 6d03f12 Compare November 3, 2026 21:15
@W4HO-ham

W4HO-ham commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Done (6d03f12): struct brcmu_chan ch = {}, and a sentence on the wrong-band case: a 6 GHz BSS on a channel number that also exists on 2.4 or 5 GHz now drops out of the scan list. W=1 is clean. Agreed on upstream: the NULL check alone with Cc stable, and the 6 GHz part after our brcmutil decode. The 9a note (uname -r, the cfg80211.c blob, scans with no oops) comes with #187's smoke run, from a test kernel I'll rebuild with this head.

@W4HO-ham

W4HO-ham commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

The 9a note. Release 7.3.0-rc6-omamobile-push1-g63aa17cc8b81: #187 merged onto today's omamobile, then this PR's head (6d03f12), #152 and a test-only SPI commit. cfg80211.c blob in that tree: f57a5dfcceb6. It differs from this branch's own 8d386c04220a only because #187 also touches the file. Five NetworkManager rescans on the palmtop found 14, 21, 25, 21 and 21 BSSes, and the boot logged no Internal error. The usual Ignoring unexpected firmware channel lines are there (9), as on every boot. An earlier boot of the same stack on the old omamobile (…-gbd53c717eeea, same cfg80211.c) found 15, 12, 17, 27 and 30, also with no oops.

@derekross

Copy link
Copy Markdown
Owner

Thank you, @W4HO-ham, for the quick follow-up and for the 9a note. I rebuilt
your tested tree (today's omamobile, #187, then this PR). It gives exactly
the cfg80211.c blob you reported, f57a5dfcceb6, so your scans ran this
code. The = {} also does what I hoped: a zeroed band reads as 2.4 GHz, not
6 GHz, so an odd chanspec still goes through the normal lookup and the NULL
check.

That's everything I needed from you. What's left is on my side: the 7 Pro run
of this version (join, scans compared with the base kernel). Then I'll merge.

One tiny thing, only if you push again for another reason: the new sentence
in the message didn't get rewrapped. One line is 94 columns.

@derekross

Copy link
Copy Markdown
Owner

@W4HO-ham thank you, this ran clean on my Pixel 7 Pro (BCM4389). The kernel was omamobile with this PR and #187 merged on top, 7.3.0-rc6-omamobile-push1-g1590b15c0934.

  • Scans: two rescans each listed the 2.4 and 5 GHz networks in range (3 and 2 here, against 2 and 1 on the kernel before), and nothing on 6 GHz, which this phone's wiphy doesn't offer. There's no skip line, so no scanned BSS fell outside the wiphy here, and nothing that should be listed went missing.
  • Connection: it reconnected to the same network on 5 GHz. A 300 MB download ran at about 130 Mbit/s: 208k packets, no rx errors or drops, no No PKTID, no firmware timeout or trap, no WARN.
  • Firmware log: the kernel before logged a p2p_create_p2pdev timeout and a WLC_SET_ROAM_TRIGGER error at each Wi-Fi start; this boot logged neither, though I wouldn't credit that to this PR without more boots.

Merging now.

@derekross
derekross merged commit cb315e4 into derekross:omamobile Nov 8, 2026
1 check passed
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.

2 participants