* [PATCH rtw-next v3 0/2] wifi: rtw88: 8822c: fix cck_pd_set when the chip stops responding
@ 2026-11-15 20:18 Zeshan Ahmed Nobin
2026-11-15 20:18 ` [PATCH rtw-next v3 1/2] wifi: rtw88: 8822c: fix out-of-bounds access in cck_pd_set Zeshan Ahmed Nobin
2026-11-15 20:18 ` [PATCH rtw-next v3 2/2] wifi: rtw88: 8822c: ignore nrx values without CCK PD registers Zeshan Ahmed Nobin
0 siblings, 2 replies; 4+ messages in thread
From: Zeshan Ahmed Nobin @ 2026-11-15 20:18 UTC (permalink / raw)
To: linux-wireless; +Cc: linux-kernel, Ping-Ke Shih, Luka Gejak, Kalle Valo
rtw8822c_phy_cck_pd_set() indexes its tables with two values read from
the chip, bw and nrx. When the chip stops responding, both can be
invalid; on PCIe, register reads then return all ones, so both are 3.
Patch 1 takes bw from rtwdev->hal.current_band_width instead, as Luka
Gejak suggested, which fixes the out-of-bounds access. Patch 2 makes the
function ignore nrx values without CCK PD registers, which Luka found
while reviewing v1.
The two belong together. With patch 1 alone, bw is always valid, so on
PCIe a chip that stops responding gets past the WARN_ON() in
rtw8822c_phy_cck_pd_set_reg() and reaches the zero-mask register access
that patch 2 prevents. Patch 2 indexes rtw8822c_cck_pd_reg[] with bw, so
it needs patch 1 first. Both are marked for stable.
v3:
- Patch 1: take bw from hal instead of reading it from the chip, and
drop the check (Luka)
- Patch 1: replace the forced-bw test, which no longer applies, with
real chip failures (Luka); add a check of hal against the register
- Patch 2: update the message and notes for the change in patch 1
(Luka)
- Patch 2: add Cc: stable, since with patch 1 a chip that stops
responding on PCIe reaches the zero-mask access
- Patch 2: add Luka's Reviewed-by; the code is unchanged
- Keep the order, and say here that the two belong together (Luka)
v2: https://lore.kernel.org/all/20261108182837.682661-1-zeshanahmednobin@gmail.com/
v1: https://lore.kernel.org/linux-wireless/20261105113415.73184-1-zeshanahmednobin@gmail.com/
AI assistance: I asked an AI coding assistant to help find out why the
RTL8822CE in my laptop keeps failing. It analyzed the kernel logs and
found the bw bug (Luka found the nrx one and suggested the approach in
patch 1), wrote the code, the debug-only changes used for testing, and
the messages. I reviewed everything and ran the tests described in each
patch before sending.
Zeshan Ahmed Nobin (2):
wifi: rtw88: 8822c: fix out-of-bounds access in cck_pd_set
wifi: rtw88: 8822c: ignore nrx values without CCK PD registers
drivers/net/wireless/realtek/rtw88/rtw8822c.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
base-commit: 04c9984187228904f222681661c50db3f0c50b71
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH rtw-next v3 1/2] wifi: rtw88: 8822c: fix out-of-bounds access in cck_pd_set
2026-11-15 20:18 [PATCH rtw-next v3 0/2] wifi: rtw88: 8822c: fix cck_pd_set when the chip stops responding Zeshan Ahmed Nobin
@ 2026-11-15 20:18 ` Zeshan Ahmed Nobin
2026-11-16 14:49 ` Luka Gejak
2026-11-15 20:18 ` [PATCH rtw-next v3 2/2] wifi: rtw88: 8822c: ignore nrx values without CCK PD registers Zeshan Ahmed Nobin
1 sibling, 1 reply; 4+ messages in thread
From: Zeshan Ahmed Nobin @ 2026-11-15 20:18 UTC (permalink / raw)
To: linux-wireless; +Cc: linux-kernel, Ping-Ke Shih, Luka Gejak, Kalle Valo
rtw8822c_phy_cck_pd_set() reads the bandwidth from a 2-bit register
field and uses it as the first index into dm_info->cck_pd_lv[], which
only has entries for 20 and 40 MHz.
When the chip stops responding on the PCIe bus, register reads return
all ones and bw becomes 3. The function then reads cck_pd_lv[3][nrx],
past the end of the array. If that byte differs from new_lvl, it calls
rtw8822c_phy_cck_pd_set_reg(), which rejects bw with WARN_ON(), and
then writes new_lvl to cck_pd_lv[3][nrx] anyway. UBSAN reports the
first of these accesses as:
UBSAN: array-index-out-of-bounds in .../rtw88/rtw8822c.c:4407:21
index 3 is out of range for type 'u8 [2][4]'
Workqueue: phy0 rtw_watch_dog_work [rtw88_core]
Call Trace:
<TASK>
__ubsan_handle_out_of_bounds+0xdd/0x120
rtw8822c_phy_cck_pd_set+0x33c/0x510 [rtw88_8822c]
rtw_phy_dynamic_mechanism+0x310/0x330 [rtw88_core]
rtw_watch_dog_work+0x217/0x330 [rtw88_core]
The driver doesn't need to read the bandwidth from the chip:
rtw_set_channel() stores it in rtwdev->hal.current_band_width and
programs the same value into the chip. Use the stored value. CCK PD
only runs on 2.4 GHz, where the bandwidth is 20 or 40 MHz, so the
stored value is always a valid index.
On PCIe, a chip that stops responding still returns nrx = 3; the next
patch handles nrx values without CCK PD registers.
The fix and this message were drafted with an AI coding assistant
(Claude Opus 5.5 by Anthropic), then reviewed and tested by the
submitter.
Fixes: 479c4ee931a6 ("rtw88: add dynamic cck pd mechanism")
Cc: stable@vger.kernel.org
Suggested-by: Luka Gejak <luka.gejak@linux.dev>
Signed-off-by: Zeshan Ahmed Nobin <zeshanahmednobin@gmail.com>
---
Notes:
Testing, on an RTL8822CE in an ASUS TUF Gaming A15 (FA506IU) whose chip
intermittently stops responding on the PCIe bus:
- Without this patch, on Ubuntu's 6.8.0-147 and 7.0.0-42 kernels, 22 of
the 23 boots in which the chip failed while the driver was running
logged three UBSAN reports for the reads, the WARN_ON() and one report
for the write; the other logged neither. Boots without a failure
logged neither. The trace above is from 7.0.0-42, whose line numbers
are three lower than mainline here.
- With both patches on 6.8.0-147, whose CCK PD and channel code is the
same as rtw-next's, a debug-only counter compared hal's bandwidth with
bits 3:2 of 0x9b0 at every call. On a 40 MHz connection on 2.4 GHz,
they matched at all 1389 calls, across 20 hardware scans and 3
associations.
- In the same setup, the chip failed in two boots. The function then
ran 13 and 15 times while the chip read back all ones (0x9b0 gave
0xffffffff). Neither boot logged a UBSAN report or a warning from
rtw88 after the failure.
- Build-tested on rtw-next (04c998418722) with W=1: no warnings.
drivers/net/wireless/realtek/rtw88/rtw8822c.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.c b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
index 09315d23e2c4..df7df76785e4 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8822c.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
@@ -4404,7 +4404,7 @@ static void rtw8822c_phy_cck_pd_set(struct rtw_dev *rtwdev, u8 new_lvl)
u8 nrx, bw;
nrx = (u8)rtw_read32_mask(rtwdev, 0x1a2c, 0x60000);
- bw = (u8)rtw_read32_mask(rtwdev, 0x9b0, 0xc);
+ bw = rtwdev->hal.current_band_width;
rtw_dbg(rtwdev, RTW_DBG_PHY, "lv: (%d) -> (%d) bw=%d nr=%d cck_fa_avg=%d\n",
dm_info->cck_pd_lv[bw][nrx], new_lvl, bw, nrx,
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH rtw-next v3 2/2] wifi: rtw88: 8822c: ignore nrx values without CCK PD registers
2026-11-15 20:18 [PATCH rtw-next v3 0/2] wifi: rtw88: 8822c: fix cck_pd_set when the chip stops responding Zeshan Ahmed Nobin
2026-11-15 20:18 ` [PATCH rtw-next v3 1/2] wifi: rtw88: 8822c: fix out-of-bounds access in cck_pd_set Zeshan Ahmed Nobin
@ 2026-11-15 20:18 ` Zeshan Ahmed Nobin
1 sibling, 0 replies; 4+ messages in thread
From: Zeshan Ahmed Nobin @ 2026-11-15 20:18 UTC (permalink / raw)
To: linux-wireless; +Cc: linux-kernel, Ping-Ke Shih, Luka Gejak, Kalle Valo
rtw8822c_phy_cck_pd_set() reads nrx, the number of CCK RX paths minus
one, from a 2-bit register field. The driver only ever sets it to 0 or
1, for one or two RX paths (see rtw8822c_config_cck_rx_path()), and
rtw8822c_cck_pd_reg[] only has registers for those two values; its
entries for nrx 2 and 3 are all zero.
A device that stops responding can return any value. On PCIe, register
reads then return all ones, so nrx is 3. On USB, a failed read returns
whatever an earlier read left in the buffer. bw comes from
rtwdev->hal.current_band_width and stays valid. When the level then
changes, rtw8822c_phy_cck_pd_set_reg() gets past its WARN_ON(), which
only checks nrx against RTW_RF_PATH_MAX, and calls rtw_read32_mask()
and rtw_write32_mask() on register 0x0 with a zero mask. Both compute
__ffs(0), which is undefined, and the write puts back whatever was read
from register 0x0.
Return early when rtw8822c_cck_pd_reg[] has no registers for nrx.
The fix and this message were drafted with an AI coding assistant
(Claude Opus 5.5 by Anthropic), then reviewed and tested by the
submitter.
Reported-by: Luka Gejak <luka.gejak@linux.dev>
Closes: https://lore.kernel.org/linux-wireless/f6a7d3272fe7635c6a83698dfab5d85500437ca6@linux.dev/
Fixes: 479c4ee931a6 ("rtw88: add dynamic cck pd mechanism")
Cc: stable@vger.kernel.org
Reviewed-by: Luka Gejak <luka.gejak@linux.dev>
Signed-off-by: Zeshan Ahmed Nobin <zeshanahmednobin@gmail.com>
---
Notes:
Testing, on the same RTL8822CE (PCIe) with both patches on 6.8.0-147,
and a debug-only change that forces nrx to 3 on a working chip at 40 MHz
on 2.4 GHz:
- With this patch, in 12 s the function ran 6 times and returned early
each time. rtw8822c_phy_cck_pd_set_reg() was never called, and there
was no UBSAN report.
- With the new check also skipped, rtw8822c_phy_cck_pd_set_reg() ran
with nrx 3, and UBSAN reported "shift exponent 64 is too large for
32-bit type 'unsigned int'" in rtw_read32_mask() and
rtw_write32_mask(). There was no WARN_ON(), as bw was valid. That is
the path a PCIe chip that stops responding takes with patch 1 alone.
- In the second of the two chip failures described in patch 1, a
debug-only counter showed that rtw8822c_phy_cck_pd_set_reg() was
never called with nrx 2 or 3.
- Not tested on USB hardware.
- Build-tested on rtw-next (04c998418722) with W=1: no warnings.
drivers/net/wireless/realtek/rtw88/rtw8822c.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.c b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
index df7df76785e4..1eb1a9656886 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8822c.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
@@ -4406,6 +4406,14 @@ static void rtw8822c_phy_cck_pd_set(struct rtw_dev *rtwdev, u8 new_lvl)
nrx = (u8)rtw_read32_mask(rtwdev, 0x1a2c, 0x60000);
bw = rtwdev->hal.current_band_width;
+ /*
+ * rtw8822c_cck_pd_reg[] only has registers for one and two RX paths
+ * (nrx 0 and 1); its entries for nrx 2 and 3 are all zero. A device
+ * that stops responding can still return those values.
+ */
+ if (!rtw8822c_cck_pd_reg[bw][nrx].mask_pd)
+ return;
+
rtw_dbg(rtwdev, RTW_DBG_PHY, "lv: (%d) -> (%d) bw=%d nr=%d cck_fa_avg=%d\n",
dm_info->cck_pd_lv[bw][nrx], new_lvl, bw, nrx,
dm_info->cck_fa_avg);
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH rtw-next v3 1/2] wifi: rtw88: 8822c: fix out-of-bounds access in cck_pd_set
2026-11-15 20:18 ` [PATCH rtw-next v3 1/2] wifi: rtw88: 8822c: fix out-of-bounds access in cck_pd_set Zeshan Ahmed Nobin
@ 2026-11-16 14:49 ` Luka Gejak
0 siblings, 0 replies; 4+ messages in thread
From: Luka Gejak @ 2026-11-16 14:49 UTC (permalink / raw)
To: Zeshan Ahmed Nobin, linux-wireless; +Cc: linux-kernel, Ping-Ke Shih, Kalle Valo
On November 15, 2026 9:18:25 PM GMT+01:00, Zeshan Ahmed Nobin
<zeshanahmednobin@gmail.com> wrote:
>rtw8822c_phy_cck_pd_set() reads the bandwidth from a 2-bit register
>field and uses it as the first index into dm_info->cck_pd_lv[], which
>only has entries for 20 and 40 MHz.
>
>When the chip stops responding on the PCIe bus, register reads return
>all ones and bw becomes 3. The function then reads cck_pd_lv[3][nrx],
>past the end of the array. If that byte differs from new_lvl, it calls
>rtw8822c_phy_cck_pd_set_reg(), which rejects bw with WARN_ON(), and
>then writes new_lvl to cck_pd_lv[3][nrx] anyway. UBSAN reports the
>first of these accesses as:
>
> UBSAN: array-index-out-of-bounds in .../rtw88/rtw8822c.c:4407:21
> index 3 is out of range for type 'u8 [2][4]'
> Workqueue: phy0 rtw_watch_dog_work [rtw88_core]
> Call Trace:
> <TASK>
> __ubsan_handle_out_of_bounds+0xdd/0x120
> rtw8822c_phy_cck_pd_set+0x33c/0x510 [rtw88_8822c]
> rtw_phy_dynamic_mechanism+0x310/0x330 [rtw88_core]
> rtw_watch_dog_work+0x217/0x330 [rtw88_core]
>
>The driver doesn't need to read the bandwidth from the chip:
>rtw_set_channel() stores it in rtwdev->hal.current_band_width and
>programs the same value into the chip. Use the stored value. CCK PD
>only runs on 2.4 GHz, where the bandwidth is 20 or 40 MHz, so the
>stored value is always a valid index.
>
>On PCIe, a chip that stops responding still returns nrx = 3; the next
>patch handles nrx values without CCK PD registers.
>
>The fix and this message were drafted with an AI coding assistant
>(Claude Opus 5.5 by Anthropic), then reviewed and tested by the
>submitter.
>
>Fixes: 479c4ee931a6 ("rtw88: add dynamic cck pd mechanism")
>Cc: stable@vger.kernel.org
>Suggested-by: Luka Gejak <luka.gejak@linux.dev>
>Signed-off-by: Zeshan Ahmed Nobin <zeshanahmednobin@gmail.com>
>---
>
Looks good to me,
Reviewed-by: Luka Gejak <luka.gejak@linux.dev>
Best regards,
Luka Gejak
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-16 14:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15 20:18 [PATCH rtw-next v3 0/2] wifi: rtw88: 8822c: fix cck_pd_set when the chip stops responding Zeshan Ahmed Nobin
2026-11-15 20:18 ` [PATCH rtw-next v3 1/2] wifi: rtw88: 8822c: fix out-of-bounds access in cck_pd_set Zeshan Ahmed Nobin
2026-11-16 14:49 ` Luka Gejak
2026-11-15 20:18 ` [PATCH rtw-next v3 2/2] wifi: rtw88: 8822c: ignore nrx values without CCK PD registers Zeshan Ahmed Nobin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®