Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
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 rdma-rc] RDMA/siw: Fix NULL dereference when disconnect races the RTR callback
Date: Sat, 28 Nov 2026 09:08:43 -0500	[thread overview]
Message-ID: <20261128140843.59029-1-bugs@stellman-greene.com> (raw)

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]
  Mem abort info:
    ESR = 0x0000000096000005
    EC = 0x25: DABT (current EL), IL = 32 bits
    SET = 0, FnV = 0
    EA = 0, S1PTW = 0
    FSC = 0x05: level 1 translation fault
  Data abort info:
    ISV = 0, ISS = 0x00000005, ISS2 = 0x00000000
    CM = 0, WnR = 0, TnD = 0, TagAccess = 0
    GCS = 0, Overlay = 0, DirtyBit = 0
  [dfff800000000003] address between user and kernel address ranges
  Internal error: Oops: 0000000096000005 [#1]  SMP
  Modules linked in:
  CPU: 0 UID: 1000 PID: 366 Comm: siw037-peer Not tainted 7.4.0-rc4-g7cd8495c0f16-dirty #15 PREEMPT(full)
  Hardware name: linux,dummy-virt (DT)
  pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
  pc : siw_rtr_data_ready+0x218/0x2c0
  lr : siw_rtr_data_ready+0x1ec/0x2c0
  sp : ffff8000800071f0
  x29: ffff800080007270 x28: ffff0000e396cd37 x27: 1fffe0001c942e76
  x26: ffff0000e396cd18 x25: 1fffe0001c942e6a x24: ffff0000e396c848
  x23: ffff0000e80a2c00 x22: ffff0000e846e000 x21: 0000000000000000
  x20: 1ffff00010000e3e x19: ffffd9a666b96d00 x18: ffff0000e846e38c
  x17: 0000000000000000 x16: 1fffe0001c72d974 x15: ffffd9a66521701c
  x14: ffffd9a6653f32c8 x13: 6465736f6c632070 x12: ffff700010000dd9
  x11: 1ffff00010000dd8 x10: ffff700010000dd8 x9 : dfff800000000000
  x8 : ffff800080006ec7 x7 : 0000000000000001 x6 : ffff700010000dd8
  x5 : ffff800080006ec0 x4 : ffff700010000dd9 x3 : 0000000000000000
  x2 : 0000000000000003 x1 : dfff800000000000 x0 : 0000000000000018
  Call trace:
   siw_rtr_data_ready+0x218/0x2c0 (P)
   tcp_data_ready+0xd0/0x3f8
   tcp_data_queue+0x1898/0x506c
   tcp_rcv_established+0x94c/0x2e80
   tcp_v4_do_rcv+0x400/0x660
   tcp_v4_rcv+0x177c/0x314c
   ip_protocol_deliver_rcu+0x64/0x3e0
   ip_local_deliver_finish+0x244/0x440
   ip_local_deliver+0x16c/0x288
   ip_rcv+0x120/0x218
   __netif_receive_skb_one_core+0xf8/0x17c
   __netif_receive_skb+0x24/0x14c
   process_backlog+0x15c/0x428
   __napi_poll+0x90/0x394
   net_rx_action+0x33c/0x8c0
   handle_softirqs+0x368/0x910
   __do_softirq+0x14/0x20
   ____do_softirq+0x10/0x20
   call_on_irq_stack+0x30/0x48
   do_softirq_own_stack+0x1c/0x40
   do_softirq+0xb0/0xc4
   __local_bh_enable_ip+0x208/0x284
   __dev_queue_xmit+0x744/0x2bb8
   ip_finish_output2+0xd48/0x196c
   __ip_finish_output+0x234/0x7a0
   ip_finish_output+0x34/0x2e4
   ip_output+0x15c/0x27c
   __ip_queue_xmit+0x5e0/0x18a0
   ip_queue_xmit+0x44/0x64
   __tcp_transmit_skb+0x15a4/0x3b50
   tcp_write_xmit+0xfa8/0x702c
   __tcp_push_pending_frames+0x88/0x264
   tcp_push+0x400/0x68c
   tcp_sendmsg_locked+0xe34/0x33dc
   tcp_sendmsg+0x38/0x60
   inet_sendmsg+0x90/0xdc
   sock_write_iter+0x220/0x374
   vfs_write+0x9d4/0xcc0
   ksys_write+0x198/0x1e4
   __arm64_sys_write+0x70/0xa0
   invoke_syscall+0x74/0x2c0
   el0_svc_common.constprop.0+0xac/0x230
   do_el0_svc+0x40/0x58
   el0_svc+0x38/0xa0
   el0t_64_sync_handler+0xa0/0xe4
   el0t_64_sync+0x198/0x19c
  Code: d2d00001 f2fbffe1 910062a0 d343fc02 (38e16841)
  ---[ end trace 0000000000000000 ]---
  Kernel panic - not syncing: Oops: Fatal exception in interrupt
  SMP: stopping secondary CPUs
  Kernel Offset: 0x59a5e2a00000 from 0xffff800080000000
  PHYS_OFFSET: 0xfff1000040000000
  CPU features: 0x0,00000000,00600051,12300a01,280ce727
  Memory Limit: none

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.

With the fix and the same delay, the same test ran without a KASAN
report. After reverting the fix, the oops came back. Without the delay,
an MPA v2 connection with a valid RTR frame connected and disconnected
the same way before and after the fix.

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 was drafted with OpenAI GPT-6 (Codex) and this changelog with
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>
---
A reproducer is available on request.

Bernard, the release worker in siw_cm_work_handler() clears cep->qp and
puts the QP before it calls siw_socket_disassoc(), so the cep->qp check
here doesn't serialize against that path. I haven't reproduced a fault
on that path, so I left it alone. Would you want the worker to
disassociate the socket first, as the immediate path in
siw_qp_cm_drop() does?

 drivers/infiniband/sw/siw/siw_cm.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/sw/siw/siw_cm.c b/drivers/infiniband/sw/siw/siw_cm.c
index ed49818793ddeb..8612db3cc94e8c 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)

             reply	other threads:[~2026-11-28 14:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 14:08 Andrew Stellman [this message]
2026-11-28 14:21 ` [PATCH rdma-rc] RDMA/siw: Fix NULL dereference when disconnect races the RTR callback 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=20261128140843.59029-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