* [PATCH] IB/hfi1: Fix potential leaks in IPoIB TX queue initialization
@ 2026-11-11 12:23 Guangshuo Li
2026-11-15 13:55 ` Leon Romanovsky
0 siblings, 1 reply; 4+ messages in thread
From: Guangshuo Li @ 2026-11-11 12:23 UTC (permalink / raw)
To: Dennis Dalessandro, Jason Gunthorpe, Leon Romanovsky
Cc: linux-rdma, linux-kernel
When an SDMA header allocation fails, rollback skips the current TX
queue. Its ring and already allocated headers are leaked. Free the
partially initialized ring before unwinding the completed queues.
This issue was found by our static analysis tool under development.
Fixes: c874ad879c2f ("IB/hifi1: add a null check of kzalloc_node in hfi1_ipoib_txreq_init")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
drivers/infiniband/hw/hfi1/ipoib_tx.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/hw/hfi1/ipoib_tx.c b/drivers/infiniband/hw/hfi1/ipoib_tx.c
index 8b9cc55db59d..2e9225b558b4 100644
--- a/drivers/infiniband/hw/hfi1/ipoib_tx.c
+++ b/drivers/infiniband/hw/hfi1/ipoib_tx.c
@@ -743,7 +743,7 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv)
kzalloc_node(sizeof(*tx->sdma_hdr),
GFP_KERNEL, priv->dd->node);
if (!hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr)
- goto free_txqs;
+ goto free_tx_ring;
}
netif_napi_add_tx(dev, &txq->napi, hfi1_ipoib_poll_tx_ring);
@@ -751,6 +751,10 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv)
return 0;
+free_tx_ring:
+ while (j--)
+ kfree(hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr);
+ kvfree(tx_ring->items);
free_txqs:
for (i--; i >= 0; i--) {
struct hfi1_ipoib_txq *txq = &priv->txqs[i];
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] IB/hfi1: Fix potential leaks in IPoIB TX queue initialization 2026-11-11 12:23 [PATCH] IB/hfi1: Fix potential leaks in IPoIB TX queue initialization Guangshuo Li @ 2026-11-15 13:55 ` Leon Romanovsky 2026-11-19 12:44 ` 李广硕 0 siblings, 1 reply; 4+ messages in thread From: Leon Romanovsky @ 2026-11-15 13:55 UTC (permalink / raw) To: Guangshuo Li Cc: Dennis Dalessandro, Jason Gunthorpe, linux-rdma, linux-kernel On Wed, Nov 11, 2026 at 08:23:19PM +0800, Guangshuo Li wrote: > When an SDMA header allocation fails, rollback skips the current TX > queue. Its ring and already allocated headers are leaked. Free the > partially initialized ring before unwinding the completed queues. free_tx_ring already performs that, see "for (j = 0; j < tx_ring_size; j++)" loop. Thanks > > This issue was found by our static analysis tool under development. > > Fixes: c874ad879c2f ("IB/hifi1: add a null check of kzalloc_node in hfi1_ipoib_txreq_init") > Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn> > --- > drivers/infiniband/hw/hfi1/ipoib_tx.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/infiniband/hw/hfi1/ipoib_tx.c b/drivers/infiniband/hw/hfi1/ipoib_tx.c > index 8b9cc55db59d..2e9225b558b4 100644 > --- a/drivers/infiniband/hw/hfi1/ipoib_tx.c > +++ b/drivers/infiniband/hw/hfi1/ipoib_tx.c > @@ -743,7 +743,7 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv) > kzalloc_node(sizeof(*tx->sdma_hdr), > GFP_KERNEL, priv->dd->node); > if (!hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr) > - goto free_txqs; > + goto free_tx_ring; > } > > netif_napi_add_tx(dev, &txq->napi, hfi1_ipoib_poll_tx_ring); > @@ -751,6 +751,10 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv) > > return 0; > > +free_tx_ring: > + while (j--) > + kfree(hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr); > + kvfree(tx_ring->items); > free_txqs: > for (i--; i >= 0; i--) { > struct hfi1_ipoib_txq *txq = &priv->txqs[i]; > > base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re:Re: [PATCH] IB/hfi1: Fix potential leaks in IPoIB TX queue initialization 2026-11-15 13:55 ` Leon Romanovsky @ 2026-11-19 12:44 ` 李广硕 2026-11-22 15:02 ` Leon Romanovsky 0 siblings, 1 reply; 4+ messages in thread From: 李广硕 @ 2026-11-19 12:44 UTC (permalink / raw) To: Leon Romanovsky Cc: Dennis Dalessandro, Jason Gunthorpe, linux-rdma, linux-kernel Hi Leon, Thanks for the review. From: Leon Romanovsky <leon@kernel.org> Date: 2026-11-15 21:55:24 To: Guangshuo Li <liguangshuo@mail.sdu.edu.cn> Cc: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>,Jason Gunthorpe <jgg@ziepe.ca>,linux-rdma@vger.kernel.org,linux-kernel@vger.kernel.org Subject: Re: [PATCH] IB/hfi1: Fix potential leaks in IPoIB TX queue initialization>On Wed, Nov 11, 2026 at 08:23:19PM +0800, Guangshuo Li wrote: >> When an SDMA header allocation fails, rollback skips the current TX >> queue. Its ring and already allocated headers are leaked. Free the >> partially initialized ring before unwinding the completed queues. > >free_tx_ring already performs that, see "for (j = 0; j < tx_ring_size; j++)" >loop. > >Thanks > >> >> This issue was found by our static analysis tool under development. >> >> Fixes: c874ad879c2f ("IB/hifi1: add a null check of kzalloc_node in hfi1_ipoib_txreq_init") >> Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn> >> --- >> drivers/infiniband/hw/hfi1/ipoib_tx.c | 6 +++++- >> 1 file changed, 5 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/infiniband/hw/hfi1/ipoib_tx.c b/drivers/infiniband/hw/hfi1/ipoib_tx.c >> index 8b9cc55db59d..2e9225b558b4 100644 >> --- a/drivers/infiniband/hw/hfi1/ipoib_tx.c >> +++ b/drivers/infiniband/hw/hfi1/ipoib_tx.c >> @@ -743,7 +743,7 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv) >> kzalloc_node(sizeof(*tx->sdma_hdr), >> GFP_KERNEL, priv->dd->node); >> if (!hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr) >> - goto free_txqs; >> + goto free_tx_ring; >> } >> >> netif_napi_add_tx(dev, &txq->napi, hfi1_ipoib_poll_tx_ring); >> @@ -751,6 +751,10 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv) >> >> return 0; >> >> +free_tx_ring: >> + while (j--) >> + kfree(hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr); >> + kvfree(tx_ring->items); >> free_txqs: >> for (i--; i >= 0; i--) { >> struct hfi1_ipoib_txq *txq = &priv->txqs[i]; >> >> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 >> > The j loop frees all the headers in each ring it visits. As I read free_txqs, the outer loop starts with i--, so it skips the queue where the header allocation failed. If that happens on queue 0, the loop never runs. Would it make sense to reuse the ring cleanup for the partial queue and keep netif_napi_del() only for queues where NAPI was added? If so, I'll send a v2 that does that. Thanks, Guangshuo ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Re: [PATCH] IB/hfi1: Fix potential leaks in IPoIB TX queue initialization 2026-11-19 12:44 ` 李广硕 @ 2026-11-22 15:02 ` Leon Romanovsky 0 siblings, 0 replies; 4+ messages in thread From: Leon Romanovsky @ 2026-11-22 15:02 UTC (permalink / raw) To: 李广硕 Cc: Dennis Dalessandro, Jason Gunthorpe, linux-rdma, linux-kernel On Thu, Nov 19, 2026 at 08:44:39PM +0800, 李广硕 wrote: > > Hi Leon, > > Thanks for the review. > > From: Leon Romanovsky <leon@kernel.org> > Date: 2026-11-15 21:55:24 > To: Guangshuo Li <liguangshuo@mail.sdu.edu.cn> > Cc: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>,Jason Gunthorpe <jgg@ziepe.ca>,linux-rdma@vger.kernel.org,linux-kernel@vger.kernel.org > Subject: Re: [PATCH] IB/hfi1: Fix potential leaks in IPoIB TX queue initialization>On Wed, Nov 11, 2026 at 08:23:19PM +0800, Guangshuo Li wrote: > >> When an SDMA header allocation fails, rollback skips the current TX > >> queue. Its ring and already allocated headers are leaked. Free the > >> partially initialized ring before unwinding the completed queues. > > > >free_tx_ring already performs that, see "for (j = 0; j < tx_ring_size; j++)" > >loop. > > > >Thanks > > > >> > >> This issue was found by our static analysis tool under development. > >> > >> Fixes: c874ad879c2f ("IB/hifi1: add a null check of kzalloc_node in hfi1_ipoib_txreq_init") > >> Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn> > >> --- > >> drivers/infiniband/hw/hfi1/ipoib_tx.c | 6 +++++- > >> 1 file changed, 5 insertions(+), 1 deletion(-) > >> > >> diff --git a/drivers/infiniband/hw/hfi1/ipoib_tx.c b/drivers/infiniband/hw/hfi1/ipoib_tx.c > >> index 8b9cc55db59d..2e9225b558b4 100644 > >> --- a/drivers/infiniband/hw/hfi1/ipoib_tx.c > >> +++ b/drivers/infiniband/hw/hfi1/ipoib_tx.c > >> @@ -743,7 +743,7 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv) > >> kzalloc_node(sizeof(*tx->sdma_hdr), > >> GFP_KERNEL, priv->dd->node); > >> if (!hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr) > >> - goto free_txqs; > >> + goto free_tx_ring; > >> } > >> > >> netif_napi_add_tx(dev, &txq->napi, hfi1_ipoib_poll_tx_ring); > >> @@ -751,6 +751,10 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv) > >> > >> return 0; > >> > >> +free_tx_ring: > >> + while (j--) > >> + kfree(hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr); > >> + kvfree(tx_ring->items); > >> free_txqs: > >> for (i--; i >= 0; i--) { > >> struct hfi1_ipoib_txq *txq = &priv->txqs[i]; > >> > >> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 > >> > > > > The j loop frees all the headers in each ring it visits. As I read > free_txqs, the outer loop starts with i--, so it skips the queue where > the header allocation failed. If that happens on queue 0, the loop > never runs. > > Would it make sense to reuse the ring cleanup for the partial queue > and keep netif_napi_del() only for queues where NAPI was added? If so, > I'll send a v2 that does that. I think that this will fix it. diff --git a/drivers/infiniband/hw/hfi1/ipoib_tx.c b/drivers/infiniband/hw/hfi1/ipoib_tx.c index 8b9cc55db59d8..23c06d86b2921 100644 --- a/drivers/infiniband/hw/hfi1/ipoib_tx.c +++ b/drivers/infiniband/hw/hfi1/ipoib_tx.c @@ -752,7 +752,7 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv) return 0; free_txqs: - for (i--; i >= 0; i--) { + for (i; i >= 0; i--) { struct hfi1_ipoib_txq *txq = &priv->txqs[i]; netif_napi_del(&txq->napi); ~ > > Thanks, > Guangshuo ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-22 15:02 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-11 12:23 [PATCH] IB/hfi1: Fix potential leaks in IPoIB TX queue initialization Guangshuo Li 2026-11-15 13:55 ` Leon Romanovsky 2026-11-19 12:44 ` 李广硕 2026-11-22 15:02 ` Leon Romanovsky
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®