public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Norbert van Bolhuis <nvbolhuis@gmail.com>,
	Kalle Valo <kvalo@kernel.org>, Sasha Levin <sashal@kernel.org>,
	arend.vanspriel@broadcom.com, erick.archer@outlook.com,
	sebastian.reichel@collabora.com, saikrishnag@marvell.com,
	krzysztof.kozlowski@linaro.org, jacobe.zang@wesion.com,
	linux-wireless@vger.kernel.org, brcm80211@lists.linux.dev,
	brcm80211-dev-list.pdl@broadcom.com
Subject: [PATCH AUTOSEL 4.19 18/21] wifi: brcmfmac: Fix oops due to NULL pointer dereference in brcmf_sdiod_sglist_rw()
Date: Sun, 24 Nov 2024 08:56:51 -0500	[thread overview]
Message-ID: <20241124135709.3351371-18-sashal@kernel.org> (raw)
In-Reply-To: <20241124135709.3351371-1-sashal@kernel.org>

From: Norbert van Bolhuis <nvbolhuis@gmail.com>

[ Upstream commit 857282b819cbaa0675aaab1e7542e2c0579f52d7 ]

This patch fixes a NULL pointer dereference bug in brcmfmac that occurs
when a high 'sd_sgentry_align' value applies (e.g. 512) and a lot of queued SKBs
are sent from the pkt queue.

The problem is the number of entries in the pre-allocated sgtable, it is
nents = max(rxglom_size, txglom_size) + max(rxglom_size, txglom_size) >> 4 + 1.
Given the default [rt]xglom_size=32 it's actually 35 which is too small.
Worst case, the pkt queue can end up with 64 SKBs. This occurs when a new SKB
is added for each original SKB if tailroom isn't enough to hold tail_pad.
At least one sg entry is needed for each SKB. So, eventually the "skb_queue_walk loop"
in brcmf_sdiod_sglist_rw may run out of sg entries. This makes sg_next return
NULL and this causes the oops.

The patch sets nents to max(rxglom_size, txglom_size) * 2 to be able handle
the worst-case.
Btw. this requires only 64-35=29 * 16 (or 20 if CONFIG_NEED_SG_DMA_LENGTH) = 464
additional bytes of memory.

Signed-off-by: Norbert van Bolhuis <nvbolhuis@gmail.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://patch.msgid.link/20241107132903.13513-1-nvbolhuis@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
index 710dc59c5d34d..532733db4de85 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
@@ -770,7 +770,7 @@ void brcmf_sdiod_sgtable_alloc(struct brcmf_sdio_dev *sdiodev)
 
 	nents = max_t(uint, BRCMF_DEFAULT_RXGLOM_SIZE,
 		      sdiodev->settings->bus.sdio.txglomsz);
-	nents += (nents >> 4) + 1;
+	nents *= 2;
 
 	WARN_ON(nents > sdiodev->max_segment_count);
 
-- 
2.43.0


  parent reply	other threads:[~2024-11-24 13:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-24 13:56 [PATCH AUTOSEL 4.19 01/21] drm/radeon/r600_cs: Fix possible int overflow in r600_packet3_check() Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 02/21] samples/bpf: Fix a resource leak Sasha Levin
2024-12-02 12:12   ` Pavel Machek
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 03/21] net: fec_mpc52xx_phy: Use %pa to format resource_size_t Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 04/21] net: ethernet: fs_enet: " Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 05/21] af_packet: avoid erroring out after sock_init_data() in packet_create() Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 06/21] Bluetooth: L2CAP: do not leave dangling sk pointer on error in l2cap_sock_create() Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 07/21] net: af_can: do not leave a dangling sk pointer in can_create() Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 08/21] net: ieee802154: do not leave a dangling sk pointer in ieee802154_create() Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 09/21] net: inet: do not leave a dangling sk pointer in inet_create() Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 10/21] net: inet6: do not leave a dangling sk pointer in inet6_create() Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 11/21] wifi: ath5k: add PCI ID for SX76X Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 12/21] wifi: ath5k: add PCI ID for Arcadyan devices Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 13/21] jfs: array-index-out-of-bounds fix in dtReadFirst Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 14/21] jfs: fix shift-out-of-bounds in dbSplit Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 15/21] jfs: fix array-index-out-of-bounds in jfs_readdir Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 16/21] jfs: add a check to prevent array-index-out-of-bounds in dbAdjTree Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 17/21] wifi: ipw2x00: libipw_rx_any(): fix bad alignment Sasha Levin
2024-11-24 13:56 ` Sasha Levin [this message]
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 19/21] ASoC: hdmi-codec: reorder channel allocation list Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 20/21] rocker: fix link status detection in rocker_carrier_init() Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 21/21] netpoll: Use rcu_access_pointer() in __netpoll_setup Sasha Levin

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=20241124135709.3351371-18-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=arend.vanspriel@broadcom.com \
    --cc=brcm80211-dev-list.pdl@broadcom.com \
    --cc=brcm80211@lists.linux.dev \
    --cc=erick.archer@outlook.com \
    --cc=jacobe.zang@wesion.com \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=kvalo@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=nvbolhuis@gmail.com \
    --cc=saikrishnag@marvell.com \
    --cc=sebastian.reichel@collabora.com \
    --cc=stable@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