Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH] RDMA/irdma: fix double free of close_entry in TIME_WAIT teardown
@ 2026-11-04  2:53 Wentao Liang
  2026-11-04  7:10 ` Krzysztof Kozlowski
  2026-11-05 15:57 ` sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2026-11-04  2:53 UTC (permalink / raw)
  To: Tatyana Nikolova, Jason Gunthorpe, Leon Romanovsky; +Cc: linux-rdma

irdma_handle_close_entry() drops the cm_node reference held by the close
timer before releasing cm_node->close_entry.  If that put is the last
one, irdma_rem_ref_cm_node() runs irdma_destroy_connection(), which
still sees a non-NULL close_entry and calls
irdma_handle_close_entry(cm_node, 0).  That nested call frees the
close_entry and clears the pointer, and the outer call then frees the
same object once more.

Free the close_entry and clear cm_node->close_entry before dropping the
reference, so that a release triggered from that put observes a clean
cm_node.

Fixes: 146b9756f14c ("RDMA/irdma: Add connection manager")
Cc: stable@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/infiniband/hw/irdma/cm.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/hw/irdma/cm.c b/drivers/infiniband/hw/irdma/cm.c
index 91c0e7298283..d8b8939d6abd 100644
--- a/drivers/infiniband/hw/irdma/cm.c
+++ b/drivers/infiniband/hw/irdma/cm.c
@@ -1243,13 +1243,15 @@ static void irdma_handle_close_entry(struct irdma_cm_node *cm_node,
 		} else {
 			spin_unlock_irqrestore(&iwqp->lock, flags);
 		}
-	} else if (rem_node) {
-		/* TIME_WAIT state */
-		irdma_rem_ref_cm_node(cm_node);
 	}
 
 	kfree(close_entry);
 	cm_node->close_entry = NULL;
+
+	if (!iwqp && rem_node) {
+		/* TIME_WAIT state */
+		irdma_rem_ref_cm_node(cm_node);
+	}
 }
 
 /**
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-05 15:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04  2:53 [PATCH] RDMA/irdma: fix double free of close_entry in TIME_WAIT teardown Wentao Liang
2026-11-04  7:10 ` Krzysztof Kozlowski
2026-11-05 15:57 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox