RDMA/siw: Fix NULL dereference when disconnect races the RTR callback
Subsystems (2)
PATCH 1/1 RDMA/siw: Fix NULL dereference when disconnect races the RTR callback
From: Andrew Stellman <[email protected]>
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: noneTake 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.
---
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(-)
drivers/infiniband/sw/siw/siw_cm.c +9 -2
@@ -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)
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] RDMA/siw: race with siw_cm_work_handler() in siw_rtr_data_ready() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] RDMA/siw: race with siw_cm_work_handler() in siw_rtr_data_ready()
--
commit 79aa7e62cc4f0bc3e76b32bcd12993ddd9a6d3e4
Author: Andrew Stellman <[email protected]>
RDMA/siw: Fix NULL dereference when disconnect races the RTR callback
This commit inlines the QP socket callback assignment in siw_rtr_data_ready() under sk->sk_callback_lock after verifying that sk_to_cep(sk) == cep and cep->qp == qp.
Quoted 10 lines
drivers/infiniband/sw/siw/siw_cm.c +0
-2@@ -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);
drivers/infiniband/sw/siw/siw_cm.c static void siw_rtr_data_ready(struct sock *sk) · line 193
Quoted 10 lines
drivers/infiniband/sw/siw/siw_cm.c +9
-0+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); + } }
[Severity: High]
Can this race with siw_cm_work_handler() to leave a dangling socket pointer in qp->attrs.sk or write to a freed qp?
If the incoming RTR frame is malformed and siw_tcp_rx_data() calls siw_qp_cm_drop(qp, 1), qp->rx_stream.rx_suspend is set and SIW_CM_WORK_CLOSE_LLP is queued on siw_cm_wq, yet siw_rtr_data_ready() still falls through to the if (qp) block after dropping sk_callback_lock.
In siw_cm_work_handler(), the release_cep path closes the QP and drops the CEP's QP reference before disassociating the socket under sk_callback_lock:
drivers/infiniband/sw/siw/siw_cm.c:siw_cm_work_handler() {
...
if (cep->qp) {
struct siw_qp *qp = cep->qp;
...
siw_qp_llp_close(qp);
siw_qp_put(qp);
siw_cep_set_inuse(cep);
cep->qp = NULL;
siw_qp_put(qp);
}
if (s) {
siw_socket_disassoc(s);
sock_release(s);
}
...
}This allows the following interleaving:
<softirq> kworkersiw_rtr_data_ready()
tcp_read_sock()
...
siw_qp_cm_drop(qp, 1)
read_unlock(&sk_callback_lock)
siw_cm_work_handler()
siw_qp_llp_close(qp)
down_write(&qp->state_lock)
qp->attrs.sk = NULL
up_write(&qp->state_lock)
write_lock_bh(&sk_callback_lock)
if (sk_to_cep(sk) == cep &&
cep->qp == qp)
cep->qp = NULL
siw_qp_put(qp)
qp->attrs.sk = cep->sock
write_unlock_bh(&sk_callback_lock)
siw_socket_disassoc(s)
sock_release(s) <-- qp->attrs.sk danglesBecause siw_rtr_data_ready() sets qp->attrs.sk without holding qp->state_lock, it overwrites the NULL written by siw_qp_llp_close() right before sock_release(s) frees the socket. Also, because cep->qp is cleared and siw_qp_put(qp) is called without holding sk_callback_lock, the last QP reference can drop right after cep->qp == qp is checked, making the write to qp->attrs.sk a use-after-free if siw_destroy_qp() is waiting on qp->qp_free.
Note that siw_accept() already sets qp->attrs.sk = cep->sock via siw_qp_modify() before installing the RTR callbacks. Skipping the callback reassignment when qp->rx_stream.rx_suspend is set, and disassociating the socket in siw_cm_work_handler() before closing and releasing cep->qp (as siw_qp_cm_drop() does in its immediate path), would avoid both races.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v2 1/1 RDMA/siw: Fix NULL dereference when disconnect races the RTR callback
In reply to Andrew StellmanFrom: Andrew Stellman <[email protected]>
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.
---
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/[email protected]/
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(-)
drivers/infiniband/sw/siw/siw_cm.c +13 -5
@@ -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);
Signature · 1 line
2.53.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 13 lines
From: Andrew Stellman <[email protected]>
siw_rtr_data_ready()releasessk_callback_lockand then callssiw_qp_socket_assoc(), which readscep->sock->skbefore it takes the write lock. A concurrent disconnect can disassociate the socket and clearcep->sockin 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:
Quoted 8 lines
Unable to handle kernel paging request at virtual address dfff800000000003 KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f][ ... ]
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 <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1