* [PATCH] RDMA/bnxt_re: clear sq->swq pointer on error in bnxt_re_setup_qp_swqs()
@ 2026-12-05 14:52 Yuansheng Yang
2026-12-05 15:02 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Yuansheng Yang @ 2026-12-05 14:52 UTC (permalink / raw)
To: Selvin Xavier, Kalesh AP; +Cc: linux-rdma, stable
In bnxt_re_setup_qp_swqs(), which only runs for kernel QPs
(!qplqp->is_user; user QPs return early at the top of the function), if
rq->swq allocation fails when !qplqp->srq after sq->swq has already been
allocated, the error path frees sq->swq via kfree(sq->swq) without
resetting sq->swq to NULL.
Both callers, bnxt_qplib_create_qp1() and bnxt_qplib_create_qp(), destroy
the firmware QP and propagate the error back to bnxt_re_create_qp(),
whose free_hwq unwind label calls bnxt_qplib_free_qp_res(). Because
qp->sq.swq is still non-NULL, bnxt_qplib_free_qp_res() calls
kfree(qp->sq.swq) a second time on the already-freed buffer:
BUG: KASAN: double-free in bnxt_qplib_free_qp_res
Call Trace:
kfree
bnxt_qplib_free_qp_res
bnxt_re_create_qp
Clear sq->swq to NULL after freeing it in bnxt_re_setup_qp_swqs() so
subsequent cleanup via bnxt_qplib_free_qp_res() is safe.
Fixes: 13f9a813eee5 ("RDMA/bnxt_re: Refactor bnxt_qplib_create_qp() function")
Cc: stable@vger.kernel.org
Signed-off-by: Yuansheng Yang <0xbeac@gmail.com>
---
Compiled drivers/infiniband/hw/bnxt_re/qplib_fp.o with W=1 on x86_64
(0 warnings, 0 errors) and verified on v7.4-rc5 in an x86_64 KASAN QEMU
guest via bnxt_qplib_create_qp() failing on rq->swq allocation followed
by bnxt_qplib_free_qp_res(): before this fix, KASAN reports a
double-free in bnxt_qplib_free_qp_res(); after this fix, 10/10
iterations unwind cleanly with qp->sq.swq == NULL and 0 KASAN, BUG, or
WARNING diagnostics.
drivers/infiniband/hw/bnxt_re/qplib_fp.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/infiniband/hw/bnxt_re/qplib_fp.c b/drivers/infiniband/hw/bnxt_re/qplib_fp.c
index 5301e4f21..aee7407dc 100644
--- a/drivers/infiniband/hw/bnxt_re/qplib_fp.c
+++ b/drivers/infiniband/hw/bnxt_re/qplib_fp.c
@@ -832,6 +832,7 @@ static int bnxt_re_setup_qp_swqs(struct bnxt_qplib_qp *qplqp)
return 0;
free_sq_swq:
kfree(sq->swq);
+ sq->swq = NULL;
return rc;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] RDMA/bnxt_re: clear sq->swq pointer on error in bnxt_re_setup_qp_swqs()
2026-12-05 14:52 [PATCH] RDMA/bnxt_re: clear sq->swq pointer on error in bnxt_re_setup_qp_swqs() Yuansheng Yang
@ 2026-12-05 15:02 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-05 15:02 UTC (permalink / raw)
To: Yuansheng Yang; +Cc: linux-rdma
> In bnxt_re_setup_qp_swqs(), which only runs for kernel QPs
> (!qplqp->is_user; user QPs return early at the top of the function), if
> rq->swq allocation fails when !qplqp->srq after sq->swq has already been
> allocated, the error path frees sq->swq via kfree(sq->swq) without
> resetting sq->swq to NULL.
>
> Both callers, bnxt_qplib_create_qp1() and bnxt_qplib_create_qp(), destroy
> the firmware QP and propagate the error back to bnxt_re_create_qp(),
> whose free_hwq unwind label calls bnxt_qplib_free_qp_res(). Because
> qp->sq.swq is still non-NULL, bnxt_qplib_free_qp_res() calls
> kfree(qp->sq.swq) a second time on the already-freed buffer:
>
> BUG: KASAN: double-free in bnxt_qplib_free_qp_res
> Call Trace:
> kfree
> bnxt_qplib_free_qp_res
> bnxt_re_create_qp
>
> Clear sq->swq to NULL after freeing it in bnxt_re_setup_qp_swqs() so
> subsequent cleanup via bnxt_qplib_free_qp_res() is safe.
>
> Fixes: 13f9a813eee5 ("RDMA/bnxt_re: Refactor bnxt_qplib_create_qp() function")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yuansheng Yang <0xbeac@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205145220.1712012-1-0xbeac@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 15:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 14:52 [PATCH] RDMA/bnxt_re: clear sq->swq pointer on error in bnxt_re_setup_qp_swqs() Yuansheng Yang
2026-12-05 15:02 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox