Re: [PATCH rtw-next v4] wifi: rtw88: 8822c: validate bw and nrx read from registers

From: Luka Gejak

Date: Wed Nov 25 2026 - 16:14:38 EST


On November 25, 2026 9:37:53 PM GMT+01:00, Zeshan Ahmed Nobin
<zeshanahmednobin@xxxxxxxxx> wrote:
>rtw8822c_phy_cck_pd_set() reads nrx and bw from the chip with
>rtw_read32_mask() and uses them as indexes into dm_info->cck_pd_lv[][]
>and rtw8822c_cck_pd_reg[][].
>
>When the chip stops responding on the PCIe bus, register reads return
>all ones, so bw and nrx both become 3. bw = 3 is past the end of both
>arrays. When the chip stopped responding on Ubuntu's 7.0.0-43 kernel,
>UBSAN reported:
>
> 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:
> 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]
>
>nrx = 3 fits in cck_pd_lv[][], but rtw8822c_cck_pd_reg[][] only has
>registers for nrx 0 and 1. The entry for nrx 3 is empty: register 0,
>mask 0. If bw is valid and the level changes, the driver uses that
>empty entry. rtw_read32_mask() then shifts by __ffs(0), which is
>undefined; in a test that faked only nrx 3, UBSAN reported "shift
>exponent 64 is too large".
>
>Return early if bw or nrx is out of range, before either is used as
>an index.
>
>Fixes: 479c4ee931a6 ("rtw88: add dynamic cck pd mechanism")
>Reported-by: Luka Gejak <luka.gejak@xxxxxxxxx>
>Closes: https://lore.kernel.org/linux-wireless/f6a7d3272fe7635c6a83698dfab5d85500437ca6@xxxxxxxxx/
>Cc: stable@xxxxxxxxxxxxxxx
>Signed-off-by: Zeshan Ahmed Nobin <zeshanahmednobin@xxxxxxxxx>
>---

Looks good to me,

Reviewed-by: Luka Gejak <luka.gejak@xxxxxxxxx>

Best regards,
Luka Gejak