Linux wireless drivers development
 help / color / mirror / Atom feed
From: Maoyi Xie <maoyixie.tju@gmail.com>
To: Arend van Spriel <arend.vanspriel@broadcom.com>
Cc: linux-wireless@vger.kernel.org, brcm80211@lists.linux.dev,
	brcm80211-dev-list.pdl@broadcom.com
Subject: [PATCH wireless 2/2] wifi: brcmfmac: msgbuf: reject an out-of-range D2H ring write index
Date: Tue,  1 Dec 2026 17:12:15 +0800	[thread overview]
Message-ID: <20261201091215.3661018-3-maoyixie.tju@gmail.com> (raw)
In-Reply-To: <20261201091215.3661018-1-maoyixie.tju@gmail.com>

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


      parent reply	other threads:[~2026-12-01  9:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201091215.3661018-3-maoyixie.tju@gmail.com \
    --to=maoyixie.tju@gmail.com \
    --cc=arend.vanspriel@broadcom.com \
    --cc=brcm80211-dev-list.pdl@broadcom.com \
    --cc=brcm80211@lists.linux.dev \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox