From: Andrew Stellman <bugs@stellman-greene.com>
To: Bernard Metzler <bernard.metzler@linux.dev>
Cc: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 rdma-rc] RDMA/siw: Fix NULL dereference when disconnect races the RTR callback
Date: Sat, 28 Nov 2026 15:24:52 -0500 [thread overview]
Message-ID: <20261128202452.45307-1-bugs@stellman-greene.com> (raw)
In-Reply-To: <20261128140843.59029-1-bugs@stellman-greene.com>
From: Andrew Stellman <astellman@stellman-greene.com>
siw_rtr_data_ready() releases sk_callback_lock and then calls
siw_qp_socket_assoc(), which reads cep->sock->sk before it takes the
write lock. A concurrent disconnect can disassociate the socket and
clear cep->sock in that gap.
In QEMU (arm64) on mainline as of 2026-11-28 with KASAN, a test server
accepted an MPA v2 connection that waits for the peer's RTR frame. The
server calls rdma_disconnect() when it gets the ESTABLISHED event. The
peer sent an incomplete RTR header. With a test-only one second delay
added after the callback unlock, this oopsed:
Unable to handle kernel paging request at virtual address dfff800000000003
KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f]
Internal error: Oops: 0000000096000005 [#1] SMP
pc : siw_rtr_data_ready+0x218/0x2c0
lr : siw_rtr_data_ready+0x1ec/0x2c0
Call trace:
siw_rtr_data_ready+0x218/0x2c0 (P)
tcp_data_ready+0xd0/0x3f8
tcp_data_queue+0x1898/0x506c
tcp_rcv_established+0x94c/0x2e80
Take the callback's socket write lock and check that the socket still
belongs to the same CEP and QP before installing the QP callbacks. If
it doesn't, do nothing.
That check relies on the socket being disassociated before the QP is
released. siw_cm_work_handler() closes and puts the QP before it calls
siw_socket_disassoc(), so move siw_socket_disassoc() first, as
siw_qp_cm_drop() already does. The worker now restores the socket's
original callbacks before closing the QP. The ordering problem was
found by code review; I have not reproduced a fault on that path.
With the patch and the same one-second test-only delay, the incomplete
RTR header and rdma_disconnect() test ran without a KASAN report.
Without the delay, a valid RTR frame connected and disconnected the
same way as on mainline.
The issue was found by Claude Opus 5.5 running Quality Playbook, an
LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix and this changelog were drafted with OpenAI GPT-6 (Codex) and
Claude Opus 5.5, and both were reviewed by me.
Fixes: 6c52fdc244b5 ("rdma/siw: connection management")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
v2: Disassociate the socket before the release worker closes the QP,
as asked in v1 and following Sashiko's review of it:
https://lore.kernel.org/linux-rdma/20261128140843.59029-1-bugs@stellman-greene.com/
The RTR callback hunk is unchanged.
A reproducer is available on request.
drivers/infiniband/sw/siw/siw_cm.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/infiniband/sw/siw/siw_cm.c b/drivers/infiniband/sw/siw/siw_cm.c
index ed49818793ddeb..9fa25c287dc1d8 100644
--- a/drivers/infiniband/sw/siw/siw_cm.c
+++ b/drivers/infiniband/sw/siw/siw_cm.c
@@ -181,8 +181,15 @@ static void siw_rtr_data_ready(struct sock *sk)
siw_cm_upcall(cep, IW_CM_EVENT_ESTABLISHED, 0);
out:
read_unlock(&sk->sk_callback_lock);
- if (qp)
- siw_qp_socket_assoc(cep, qp);
+ if (qp) {
+ write_lock_bh(&sk->sk_callback_lock);
+ if (sk_to_cep(sk) == cep && cep->qp == qp) {
+ qp->attrs.sk = cep->sock;
+ sk->sk_data_ready = siw_qp_llp_data_ready;
+ sk->sk_write_space = siw_qp_llp_write_space;
+ }
+ write_unlock_bh(&sk->sk_callback_lock);
+ }
}
static void siw_sk_assign_rtr_upcalls(struct siw_cep *cep)
@@ -1214,6 +1221,9 @@ static void siw_cm_work_handler(struct work_struct *w)
cep->state = SIW_EPSTATE_CLOSED;
+ if (s)
+ siw_socket_disassoc(s);
+
if (cep->qp) {
struct siw_qp *qp = cep->qp;
/*
@@ -1230,10 +1240,8 @@ static void siw_cm_work_handler(struct work_struct *w)
cep->qp = NULL;
siw_qp_put(qp);
}
- if (s) {
- siw_socket_disassoc(s);
+ if (s)
sock_release(s);
- }
if (cep->cm_id) {
siw_free_cm_id(cep);
siw_cep_put(cep);
--
2.53.0
prev parent reply other threads:[~2026-11-28 20:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 14:08 [PATCH rdma-rc] RDMA/siw: Fix NULL dereference when disconnect races the RTR callback Andrew Stellman
2026-11-28 14:21 ` sashiko-bot
2026-11-28 20:24 ` Andrew Stellman [this message]
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=20261128202452.45307-1-bugs@stellman-greene.com \
--to=bugs@stellman-greene.com \
--cc=bernard.metzler@linux.dev \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@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