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