Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH wireless 0/2] wifi: brcmfmac: check a glom length and a ring index from the device
@ 2026-12-01  9:12 Maoyi Xie
  2026-12-01  9:12 ` [PATCH wireless 1/2] wifi: brcmfmac: sdio: reject glom chains longer than U16_MAX Maoyi Xie
  2026-12-01  9:12 ` [PATCH wireless 2/2] wifi: brcmfmac: msgbuf: reject an out-of-range D2H ring write index Maoyi Xie
  0 siblings, 2 replies; 3+ messages in thread
From: Maoyi Xie @ 2026-12-01  9:12 UTC (permalink / raw)
  To: Arend van Spriel; +Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl

These patches add two checks on values that the device sends. Patch 1
rejects an SDIO glom descriptor whose lengths add up to more than
U16_MAX. Patch 2 rejects a D2H ring write index at or above the ring
depth on PCIe.

Both bugs were found with a CodeQL-based static analysis tool that we
are developing. Each bug was reproduced in a userspace harness under
AddressSanitizer. Not tested on hardware. Compile-tested with W=1 on
next-20261116.

I used an LLM to help write the harnesses and these patches.

Maoyi Xie (2):
  wifi: brcmfmac: sdio: reject glom chains longer than U16_MAX
  wifi: brcmfmac: msgbuf: reject an out-of-range D2H ring write index

 .../wireless/broadcom/brcm80211/brcmfmac/commonring.c    | 8 ++++++++
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c  | 9 ++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

-- 
2.34.1


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

* [PATCH wireless 1/2] wifi: brcmfmac: sdio: reject glom chains longer than U16_MAX
  2026-12-01  9:12 [PATCH wireless 0/2] wifi: brcmfmac: check a glom length and a ring index from the device Maoyi Xie
@ 2026-12-01  9:12 ` Maoyi Xie
  2026-12-01  9:12 ` [PATCH wireless 2/2] wifi: brcmfmac: msgbuf: reject an out-of-range D2H ring write index Maoyi Xie
  1 sibling, 0 replies; 3+ messages in thread
From: Maoyi Xie @ 2026-12-01  9:12 UTC (permalink / raw)
  To: Arend van Spriel; +Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl

brcmf_sdio_rxglom() passes the length of the glom chain to
brcmf_sdiod_recv_chain() as a u16. If the descriptor lengths, padded to
a whole block, add up to more than 65535, the length wraps. On a host
without scatter-gather support, brcmf_sdiod_recv_chain() then allocates
glom_skb with the wrapped length and reads up to 64 KiB past its end.

A valid superframe is at most U16_MAX bytes, since its header holds a
16-bit length. Sum the descriptor lengths in a uint and reject a longer
chain.

Found with a CodeQL-based static analysis tool. Reproduced in a
userspace harness under AddressSanitizer. Not tested on hardware.

Fixes: a413e39a3857 ("brcmfmac: fix brcmf_sdcard_recv_chain() for host without sg support")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
I used an LLM to help write the harness and this patch.

 drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index d30468cac360..d428372bddd3 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -1514,7 +1514,8 @@ static void brcmf_sdio_hdpack(struct brcmf_sdio *bus, u8 *header,
 
 static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)
 {
-	u16 dlen, totlen;
+	u16 dlen;
+	uint totlen;
 	u8 *dptr, num = 0;
 	u16 sublen;
 	struct sk_buff *pfirst, *pnext;
@@ -1566,6 +1567,12 @@ static u8 brcmf_sdio_rxglom(struct brcmf_sdio *bus, u8 rxseq)
 				    (roundup(totlen, bus->blocksize) - totlen);
 				totlen = roundup(totlen, bus->blocksize);
 			}
+			if (totlen > U16_MAX) {
+				brcmf_err("descriptor total len %u too long\n",
+					  totlen);
+				pnext = NULL;
+				break;
+			}
 
 			/* Allocate/chain packet for next subframe */
 			pnext = brcmu_pkt_buf_get_skb(sublen + bus->sgentry_align);
-- 
2.34.1


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

* [PATCH wireless 2/2] wifi: brcmfmac: msgbuf: reject an out-of-range D2H ring write index
  2026-12-01  9:12 [PATCH wireless 0/2] wifi: brcmfmac: check a glom length and a ring index from the device Maoyi Xie
  2026-12-01  9:12 ` [PATCH wireless 1/2] wifi: brcmfmac: sdio: reject glom chains longer than U16_MAX Maoyi Xie
@ 2026-12-01  9:12 ` Maoyi Xie
  1 sibling, 0 replies; 3+ messages in thread
From: Maoyi Xie @ 2026-12-01  9:12 UTC (permalink / raw)
  To: Arend van Spriel; +Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl

brcmf_commonring_get_read_ptr() takes the write index of a D2H ring from
the device without a check against the ring depth. A larger index makes
brcmf_msgbuf_process_rx() parse items past the end of the ring buffer.
An index equal to the depth makes it walk the ring again and again.

Reject an index at or above the depth and report no new items.

Found with a CodeQL-based static analysis tool. Reproduced in a
userspace harness under AddressSanitizer. Not tested on hardware.

Fixes: 9a1bb60250d2 ("brcmfmac: Adding msgbuf protocol.")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
I used an LLM to help write the harness and this patch.

 .../net/wireless/broadcom/brcm80211/brcmfmac/commonring.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.c
index e44236cb210e..aec2ba2f7c52 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.c
@@ -10,6 +10,7 @@
 #include <brcmu_wifi.h>
 
 #include "core.h"
+#include "debug.h"
 #include "commonring.h"
 
 void brcmf_commonring_register_cb(struct brcmf_commonring *commonring,
@@ -210,6 +211,13 @@ void *brcmf_commonring_get_read_ptr(struct brcmf_commonring *commonring,
 	if (commonring->cr_update_wptr)
 		commonring->cr_update_wptr(commonring->cr_ctx);
 
+	if (commonring->w_ptr >= commonring->depth) {
+		brcmf_err("invalid w_ptr %u (depth %u)\n", commonring->w_ptr,
+			  commonring->depth);
+		*n_items = 0;
+		return NULL;
+	}
+
 	*n_items = (commonring->w_ptr >= commonring->r_ptr) ?
 				(commonring->w_ptr - commonring->r_ptr) :
 				(commonring->depth - commonring->r_ptr);
-- 
2.34.1


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

end of thread, other threads:[~2026-12-01  9:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  9:12 [PATCH wireless 0/2] wifi: brcmfmac: check a glom length and a ring index from the device Maoyi Xie
2026-12-01  9:12 ` [PATCH wireless 1/2] wifi: brcmfmac: sdio: reject glom chains longer than U16_MAX Maoyi Xie
2026-12-01  9:12 ` [PATCH wireless 2/2] wifi: brcmfmac: msgbuf: reject an out-of-range D2H ring write index Maoyi Xie

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