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 --- 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 #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