Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH rtw-next] wifi: rtw89: debug: fix diag_mac crash
@ 2026-11-23  0:12 Josef Schlehofer
  2026-11-23  1:23 ` Ping-Ke Shih
  0 siblings, 1 reply; 2+ messages in thread
From: Josef Schlehofer @ 2026-11-23  0:12 UTC (permalink / raw)
  To: Ping-Ke Shih; +Cc: linux-wireless

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,
and initialize p_rewind.

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: stable@vger.kernel.org
Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
---
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 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw89/debug.c b/drivers/net/wireless/realtek/rtw89/debug.c
index b129341e71c..8dc3464832f 100644
--- a/drivers/net/wireless/realtek/rtw89/debug.c
+++ b/drivers/net/wireless/realtek/rtw89/debug.c
@@ -5257,7 +5257,7 @@ static ssize_t rtw89_mac_diag_iter_all(struct rtw89_dev *rtwdev,
 {
 	const struct rtw89_fw_element_hdr *elm = rtwdev->fw.elm_info.diag_mac;
 	u32 n_plains = 0, n_rules = 0, n_positive = 0, n_ignore = 0;
-	char *p = buf, *end = buf + bufsz, *p_rewind;
+	char *p = buf, *end = buf + bufsz, *p_rewind = NULL;
 	const void *rule, *rule_end;
 	u32 elm_size, rule_size;
 	const void *msg_start;
@@ -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) {
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [PATCH rtw-next] wifi: rtw89: debug: fix diag_mac crash
  2026-11-23  0:12 [PATCH rtw-next] wifi: rtw89: debug: fix diag_mac crash Josef Schlehofer
@ 2026-11-23  1:23 ` Ping-Ke Shih
  0 siblings, 0 replies; 2+ messages in thread
From: Ping-Ke Shih @ 2026-11-23  1:23 UTC (permalink / raw)
  To: Josef Schlehofer; +Cc: linux-wireless@vger.kernel.org

Josef Schlehofer <pepe.schlehofer@gmail.com> wrote:
> @@ -5257,7 +5257,7 @@ static ssize_t rtw89_mac_diag_iter_all(struct rtw89_dev *rtwdev,
>  {
>         const struct rtw89_fw_element_hdr *elm = rtwdev->fw.elm_info.diag_mac;
>         u32 n_plains = 0, n_rules = 0, n_positive = 0, n_ignore = 0;
> -       char *p = buf, *end = buf + bufsz, *p_rewind;
> +       char *p = buf, *end = buf + bufsz, *p_rewind = NULL;

With fixes of prev_{seq, sheet}, is it still needed to set p_rewind = NULL?
(Though it is harmless).

>         const void *rule, *rule_end;
>         u32 elm_size, rule_size;
>         const void *msg_start;
> @@ -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) {
> --
> 2.54.0 (Apple Git-157)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-23  1:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  0:12 [PATCH rtw-next] wifi: rtw89: debug: fix diag_mac crash Josef Schlehofer
2026-11-23  1:23 ` Ping-Ke Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox