From: Yuansheng Yang <0xbeac@gmail.com>
To: Selvin Xavier <selvin.xavier@broadcom.com>,
Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Cc: linux-rdma@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH] RDMA/bnxt_re: clear sq->swq pointer on error in bnxt_re_setup_qp_swqs()
Date: Sat, 5 Dec 2026 22:52:20 +0800 [thread overview]
Message-ID: <20261205145220.1712012-1-0xbeac@gmail.com> (raw)
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
next reply other threads:[~2026-12-05 14:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 14:52 Yuansheng Yang [this message]
2026-12-05 15:02 ` [PATCH] RDMA/bnxt_re: clear sq->swq pointer on error in bnxt_re_setup_qp_swqs() sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205145220.1712012-1-0xbeac@gmail.com \
--to=0xbeac@gmail.com \
--cc=kalesh-anakkur.purayil@broadcom.com \
--cc=linux-rdma@vger.kernel.org \
--cc=selvin.xavier@broadcom.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox