RDMA/siw: Reject an MPA reply too short for the IRD/ORD block
Subsystems (2)
PATCH 1/1 RDMA/siw: Reject an MPA reply too short for the IRD/ORD block
From: Andrew Stellman <[email protected]>
When a siw initiator uses enhanced connection setup (MPA v2), siw_proc_mpareply() reads the IRD/ORD block from the reply's private data without checking that the responder sent one. The responder chooses the PD_Length of its reply.
With a PD_Length of 0 there is no private data buffer and siw dereferences NULL:
Unable to handle kernel paging request at virtual address dfff800000000000 KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] Call trace: siw_cm_work_handler+0xfa8/0x1b5c (P) process_one_work+0x5cc/0xc90 worker_thread+0x3ac/0xaa0 kthread+0x36c/0x420 ret_from_fork+0x10/0x20 ---[ end trace 0000000000000000 ]---
With a PD_Length of 1 to 3, siw_cm_upcall() subtracts the 4 byte block from the u8 private data length, and iw_cm copies 253 to 255 bytes from a much smaller buffer. With PD_Length 2 (a 6-byte buffer):
BUG: KASAN: slab-out-of-bounds in kmemdup_noprof+0x48/0x60 Read of size 254 at addr ffff0000da924cc4 by task kworker/u32:3/179 Call trace: kmemdup_noprof+0x48/0x60 cm_event_handler+0x318/0x50c siw_cm_upcall+0x290/0x420 siw_cm_work_handler+0xb84/0x1b5c process_one_work+0x5cc/0xc90 worker_thread+0x3ac/0xaa0 kthread+0x36c/0x420 ret_from_fork+0x10/0x20
Fail the connection when an enhanced reply is shorter than the IRD/ORD block, and only hide the block from the consumer when it is there. The initiator now gets RDMA_CM_EVENT_REJECTED with -ECONNRESET for these replies.
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 Claude Opus 5.5 and reviewed by me.
---
Tested on arm64 QEMU with KASAN, built from rdma for-next 94e81a1f3ffa sources applied to an older checkout (hence the version string). The PD_Length 0 oops came after over-read reports in the same boot (hence the B taint). Each reply's 20-byte MPA header was sent in five writes and its private data one byte at a time. With this patch, PD_Length 0 to 3 and a reject with PD_Length 2 all gave RDMA_CM_EVENT_REJECTED with -ECONNRESET and no KASAN report, and a valid enhanced reply still established.
A reproducer is available on request.
drivers/infiniband/sw/siw/siw_cm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/infiniband/sw/siw/siw_cm.c +10 -1
@@ -392,7 +392,8 @@ static int siw_cm_upcall(struct siw_cep *cep, enum iw_cm_event_type reason, event.private_data = cep->mpa.pdata;/* Hide MPA V2 IRD/ORD control */ -if (cep->enhanced_rdma_conn_est) { +if (cep->enhanced_rdma_conn_est && + pd_len >=sizeof (struct mpa_v2_data )) { event.private_data_len -=sizeof (struct mpa_v2_data ); event.private_data +=
@@ -849,6 +850,14 @@ static int siw_proc_mpareply(struct siw_cep *cep) -ECONNRESET);return -EINVAL ; } +if (be16_to_cpu (rep->params.pd_len) < +sizeof (struct mpa_v2_data )) { +siw_dbg_cep (cep,"mpa reply error: pd_len %u\n" , +be16_to_cpu (rep->params.pd_len)); +siw_cm_upcall (cep,IW_CM_EVENT_CONNECT_REPLY , + -ECONNRESET ); +return -EINVAL ; + } v2 = (struct mpa_v2_data *)cep->mpa.pdata; rep_ird =ntohs (v2->ird) &MPA_IRD_ORD_MASK ; rep_ord =ntohs (v2->ord) &MPA_IRD_ORD_MASK ;
base-commit: 94e81a1f3ffabb388f7d0a9674bb1d3acc067e00
Signature · 1 line
2.53.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 15 lines
From: Andrew Stellman <[email protected]>
When a siw initiator uses enhanced connection setup (MPA v2),
siw_proc_mpareply()reads the IRD/ORD block from the reply's private data without checking that the responder sent one. The responder chooses thePD_Lengthof its reply.With a
PD_Lengthof 0 there is no private data buffer and siw dereferences NULL:Unable to handle kernel paging request at virtual address dfff800000000000 KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] Call trace: siw_cm_work_handler+0xfa8/0x1b5c (P) process_one_work+0x5cc/0xc90
Quoted 6 lines
[ ... ]
The fix and this changelog were drafted with Claude Opus 5.5 and 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