[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250918121051.3504490-1-lgs201920130244@gmail.com>
Date: Thu, 18 Sep 2025 20:10:51 +0800
From: Guangshuo Li <lgs201920130244@...il.com>
To: Andrew Lunn <andrew+netdev@...n.ch>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Guangshuo Li <lgs201920130244@...il.com>,
Uwe Kleine-König <u.kleine-koenig@...libre.com>,
Jeff Garzik <jeff@...zik.org>,
"Maciej W. Rozycki" <macro@...am.me.uk>,
Mariusz Kozlowski <m.kozlowski@...land.pl>,
netdev@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: stable@...r.kernel.org
Subject: [PATCH] net: ethernet: broadcom: sb1250-mac: Add checks for kcalloc() in sbdma_initctx()
Two kcalloc() allocations (descriptor table and context table) can fail
and are used unconditionally afterwards (ALIGN()/phys conversion and
dereferences), leading to potential NULL pointer dereference.
Check both allocations and bail out early; on the second failure, free
the first allocation to avoid a leak. Do not emit extra OOM logs.
Fixes: 73d739698017 ("sb1250-mac.c: De-typedef, de-volatile, de-etc...")
Fixes: c477f3348abb ("drivers/net/sb1250-mac.c: kmalloc + memset conversion to kcalloc")
Cc: stable@...r.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@...il.com>
---
drivers/net/ethernet/broadcom/sb1250-mac.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/broadcom/sb1250-mac.c b/drivers/net/ethernet/broadcom/sb1250-mac.c
index 30865fe03eeb..e16a49e22488 100644
--- a/drivers/net/ethernet/broadcom/sb1250-mac.c
+++ b/drivers/net/ethernet/broadcom/sb1250-mac.c
@@ -625,6 +625,8 @@ static void sbdma_initctx(struct sbmacdma *d, struct sbmac_softc *s, int chan,
d->sbdma_dscrtable_unaligned = kcalloc(d->sbdma_maxdescr + 1,
sizeof(*d->sbdma_dscrtable),
GFP_KERNEL);
+ if (!d->sbdma_dscrtable_unaligned)
+ return; /* avoid NULL deref in ALIGN/phys conversion */
/*
* The descriptor table must be aligned to at least 16 bytes or the
@@ -644,7 +646,11 @@ static void sbdma_initctx(struct sbmacdma *d, struct sbmac_softc *s, int chan,
d->sbdma_ctxtable = kcalloc(d->sbdma_maxdescr,
sizeof(*d->sbdma_ctxtable), GFP_KERNEL);
-
+ if (!d->sbdma_ctxtable) {
+ kfree(d->sbdma_dscrtable_unaligned);
+ d->sbdma_dscrtable_unaligned = NULL;
+ return;
+ }
#ifdef CONFIG_SBMAC_COALESCE
/*
* Setup Rx/Tx DMA coalescing defaults
--
2.43.0
Powered by blists - more mailing lists