From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 419AE2233AF; Sun, 24 Nov 2024 13:51:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732456291; cv=none; b=S3WfAxgXHfIKy86RbwOTL1+Eq6J+RDYpw0qyOcEYa21WXzJjtZ6Kjc3aI6tilgb9udNSESmireFmonLYtfdfP8dp2qJdy5cqu4X1PKkvNuUrQ5MMUy2MsY3cNO838QfS+ieE3XUU3cZZr8pzufdRivOu/ZrMIsqpHrH+IjEef9Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732456291; c=relaxed/simple; bh=7AxnOxBq/W3DTVZaGHO/xLyqDdqyDi9rJPyozFB+DVs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EwwVvfAG473TUf2E+Dl0mVGmnUT/xGs6385P/iynt4BJLDXu/RlZ2Si/C8kryXteVaej3+Txe9gi9uZYOvf2RebswbG0JUS9N7wUAtTOml2oSqNcu2Z9ykUsirkqM1XgtuRWH3ZDjnjv/GHS1GydDq4n5JJuDjTrEEFx6nzrE4U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UR8B213N; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UR8B213N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A968C4AF09; Sun, 24 Nov 2024 13:51:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732456290; bh=7AxnOxBq/W3DTVZaGHO/xLyqDdqyDi9rJPyozFB+DVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UR8B213NfkNw0Uc2sbcaNgDzpvOguL2kb4Y/mYEquRLFnltjuX73P8FPuqjLI8hPM xo1/qofG5jHZ+5UZp2wJOBc1QQnnqqX3c5q7ii+jfOmldMoA1k85uyD8eMQ3wbQHsb 5vVfP7wdOtuAcOdiMmSiy4JPomu2UWWt9UH3qUM91h5RZJkvByYWlCARLerVWvsD2N XoDfOkM87mBhzB9HSss6fTFvm/KWvJFYdCUN+avBB89IEUk4AnbUkZlCTyGTXpT+Fr HLmiwSTqsmes5rXo4jMxsSQ3hK8TY1Pmi7q/rUwil6+Ziuh5iRn7XYzS0MKUXgKZRU 3FzjY2MlYU06A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Norbert van Bolhuis , Kalle Valo , Sasha Levin , arend.vanspriel@broadcom.com, saikrishnag@marvell.com, krzysztof.kozlowski@linaro.org, megi@xff.cz, erick.archer@outlook.com, jacobe.zang@wesion.com, linux-wireless@vger.kernel.org, brcm80211@lists.linux.dev, brcm80211-dev-list.pdl@broadcom.com Subject: [PATCH AUTOSEL 6.1 41/48] wifi: brcmfmac: Fix oops due to NULL pointer dereference in brcmf_sdiod_sglist_rw() Date: Sun, 24 Nov 2024 08:49:04 -0500 Message-ID: <20241124134950.3348099-41-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241124134950.3348099-1-sashal@kernel.org> References: <20241124134950.3348099-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.119 Content-Transfer-Encoding: 8bit From: Norbert van Bolhuis [ 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 Signed-off-by: Kalle Valo Link: https://patch.msgid.link/20241107132903.13513-1-nvbolhuis@gmail.com Signed-off-by: Sasha Levin --- 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 e300278ea38c6..9217e9f6e9076 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