[PATCH rtw-next v2] wifi: rtw89: debug: fix diag_mac crash

From
Josef Schlehofer <hidden>
Date
2026-11-23 10:36:49
Some DIAG_MAC elements start with rules for other HCI types.
rtw89_mac_diag_iter_all() skips those rules but still updates
prev_sheet and prev_seq. The first rule matching the device can
therefore be mistaken for a continuation of the same sequence,
leaving p_rewind uninitialized. A later sequence transition then
rewinds the output pointer to an invalid address and can crash the
kernel.

Update prev_sheet and prev_seq only for rules that are processed.

A walk over the DIAG_MAC rules in linux-firmware 20261019 showed
unchanged sequence grouping on PCIe and corrected grouping on USB/SDIO.

Tested on RTL8922AU (Cudy BE6500) over USB in AP mode with
backports 7.2 on Linux 6.18.64 (OpenWrt). Without the fix, the first
read crashed the kernel. With it, three reads returned 147(41)/86/84
and traffic kept working.

Fixes: 7bf433c6767f ("wifi: rtw89: debug: add parser to diagnose along DIAG_MAC fw element")
Cc: <redacted>
Signed-off-by: Josef Schlehofer <redacted>
---
v2: drop the p_rewind initializer (Ping-Ke). prev_seq starts at 0, so
the first rule that is not ignored always sets p_rewind.
v1: https://lore.kernel.org/linux-wireless/20261123001225.13076-1-pepe.schlehofer@gmail.com/ (local)

The grouping changes only for rtw8852bt_fw.bin, rtw8852c_fw-2.bin and
rtw8922a_fw-4.bin on USB and SDIO. For the RTL8922AU the walk gives 84
sequences before and 86 after, which matches the summary lines seen on
the board. rtw89_mac_diag_iter_all() and its helpers are the same in
rtw-next.

 drivers/net/wireless/realtek/rtw89/debug.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw89/debug.c b/drivers/net/wireless/realtek/rtw89/debug.c
index b129341e71c..a1aa0cf13a1 100644
--- a/drivers/net/wireless/realtek/rtw89/debug.c
+++ b/drivers/net/wireless/realtek/rtw89/debug.c
@@ -5325,11 +5325,11 @@ static ssize_t rtw89_mac_diag_iter_all(struct rtw89_dev *rtwdev,
 			break;
 		}
 
+		prev_seq = seq;
+		prev_sheet = sheet;
 next:
 		n_plains++;
 		rule += rh->len * 4;
-		prev_seq = seq;
-		prev_sheet = sheet;
 	}
 
 	if (positive_bmp) {
base-commit: 8b29fd95e2d3cb80564eb7cb34248b844422ba1e
-- 
2.54.0 (Apple Git-157)
Thread (2 messages) 2 messages, 2 authors, last reply 12h ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help