net/rds: fix NULL deref in rds_ib_send_cqe_handler() on masked atomic completion
Subsystems (4)
PATCH 1/1 net/rds: fix NULL deref in rds_ib_send_cqe_handler() on masked atomic completion
rds_ib_xmit_atomic() always programs a masked atomic opcode (IB_WR_MASKED_ATOMIC_CMP_AND_SWP or IB_WR_MASKED_ATOMIC_FETCH_AND_ADD) for every RDS atomic cmsg. But the completion-side switch in rds_ib_send_unmap_op() only handles the non-masked opcodes, so a masked atomic completion falls through to default and returns rm == NULL while send->s_op is left set. rds_ib_send_cqe_handler() then dereferences the NULL rm via rm->m_final_op, oopsing in softirq context. An unprivileged AF_RDS sendmsg() of an atomic cmsg over an active RDS/IB connection triggers it; on hardware that natively accepts masked atomics (mlx4, mlx5) no extra setup is needed.
RDS/IB: rds_ib_send_unmap_op: unexpected opcode 0xd in WR!
Oops: general protection fault [#1] SMP KASAN KASAN: null-ptr-deref in range [0x0000000000000190-0x0000000000000197] RIP: rds_ib_send_cqe_handler+0x25c/0xb10 (net/rds/ib_send.c:282) Call Trace: <IRQ> rds_ib_send_cqe_handler (net/rds/ib_send.c:282) poll_scq (net/rds/ib_cm.c:274) rds_ib_tasklet_fn_send (net/rds/ib_cm.c:294) tasklet_action_common (kernel/softirq.c:943) handle_softirqs (kernel/softirq.c:573) run_ksoftirqd (kernel/softirq.c:479) </IRQ> Kernel panic - not syncing: Fatal exception in interrupt
Handle the masked atomic opcodes in the same case as the non-masked
ones: they map to the same struct rds_message.atomic union member, so the existing container_of()/rds_ib_send_unmap_atomic() body is correct for them.
--- net/rds/ib_send.c | 2 ++ 1 file changed, 2 insertions(+)
net/rds/ib_send.c +2 -0
@@ -170,6 +170,8 @@ static struct rds_message *rds_ib_send_unmap_op(struct rds_ib_connection *ic,break ;case IB_WR_ATOMIC_FETCH_AND_ADD :case IB_WR_ATOMIC_CMP_AND_SWP : +case IB_WR_MASKED_ATOMIC_FETCH_AND_ADD : +case IB_WR_MASKED_ATOMIC_CMP_AND_SWP :if (send->s_op) { rm = container_of(send->s_op, struct rds_message, atomic);rds_ib_send_unmap_atomic (ic, send->s_op, wc_status);
Signature · 1 line
2.43.0
Quoted 31 lines · Weiming Shi
rds_ib_xmit_atomic()always programs a masked atomic opcode (IB_WR_MASKED_ATOMIC_CMP_AND_SWPorIB_WR_MASKED_ATOMIC_FETCH_AND_ADD) for every RDS atomic cmsg. But the completion-side switch inrds_ib_send_unmap_op()only handles the non-masked opcodes, so a masked atomic completion falls through to default and returns rm == NULL whilesend->s_opis left set.rds_ib_send_cqe_handler()then dereferences the NULL rm viarm->m_final_op, oopsing in softirq context. An unprivilegedAF_RDSsendmsg()of an atomic cmsg over an active RDS/IB connection triggers it; on hardware that natively accepts masked atomics (mlx4, mlx5) no extra setup is needed.RDS/IB:
rds_ib_send_unmap_op: unexpected opcode0xdin WR!Oops: general protection fault [#1] SMP KASAN KASAN: null-ptr-deref in range [0x0000000000000190-0x0000000000000197] RIP: rds_ib_send_cqe_handler+0x25c/0xb10 (net/rds/ib_send.c:282) Call Trace: <IRQ> rds_ib_send_cqe_handler (net/rds/ib_send.c:282) poll_scq (net/rds/ib_cm.c:274) rds_ib_tasklet_fn_send (net/rds/ib_cm.c:294) tasklet_action_common (kernel/softirq.c:943) handle_softirqs (kernel/softirq.c:573) run_ksoftirqd (kernel/softirq.c:479) </IRQ> Kernel panic - not syncing: Fatal exception in interruptHandle the masked atomic opcodes in the same case as the non-masked
ones: they map to the same struct rds_message.atomic union member, so the existing container_of()/rds_ib_send_unmap_atomic() body is correct for them.
Quoted 4 lines
Fixes 20c72bd5f5f9 ("RDS: Implement masked atomic operations")Reported-by Xiang Mei <[email protected]>Assisted-by Claude:claude-opus-4-8Signed-off-by Weiming Shi <[email protected]>
Hi Weiming,
Thanks for the thorough writeup, I've traced through the logic and the fix looks correct to me as do the tags. Thanks for catching this!
Allison
Quoted 17 lines
--- net/rds/ib_send.c | 2 ++ 1 file changed, 2 insertions(+)net/rds/ib_send.c +2
-0@@ -170,6 +170,8 @@ static struct rds_message *rds_ib_send_unmap_op(struct rds_ib_connection *ic,break ;case IB_WR_ATOMIC_FETCH_AND_ADD :case IB_WR_ATOMIC_CMP_AND_SWP : +case IB_WR_MASKED_ATOMIC_FETCH_AND_ADD : +case IB_WR_MASKED_ATOMIC_CMP_AND_SWP :if (send->s_op) { rm = container_of(send->s_op, struct rds_message, atomic);rds_ib_send_unmap_atomic (ic, send->s_op, wc_status);
Quoted 49 lines · Allison Henderson
Quoted 31 lines · Weiming Shi
rds_ib_xmit_atomic()always programs a masked atomic opcode (IB_WR_MASKED_ATOMIC_CMP_AND_SWPorIB_WR_MASKED_ATOMIC_FETCH_AND_ADD) for every RDS atomic cmsg. But the completion-side switch inrds_ib_send_unmap_op()only handles the non-masked opcodes, so a masked atomic completion falls through to default and returns rm == NULL whilesend->s_opis left set.rds_ib_send_cqe_handler()then dereferences the NULL rm viarm->m_final_op, oopsing in softirq context. An unprivilegedAF_RDSsendmsg()of an atomic cmsg over an active RDS/IB connection triggers it; on hardware that natively accepts masked atomics (mlx4, mlx5) no extra setup is needed.RDS/IB:
rds_ib_send_unmap_op: unexpected opcode0xdin WR!Oops: general protection fault [#1] SMP KASAN KASAN: null-ptr-deref in range [0x0000000000000190-0x0000000000000197] RIP: rds_ib_send_cqe_handler+0x25c/0xb10 (net/rds/ib_send.c:282) Call Trace: <IRQ> rds_ib_send_cqe_handler (net/rds/ib_send.c:282) poll_scq (net/rds/ib_cm.c:274) rds_ib_tasklet_fn_send (net/rds/ib_cm.c:294) tasklet_action_common (kernel/softirq.c:943) handle_softirqs (kernel/softirq.c:573) run_ksoftirqd (kernel/softirq.c:479) </IRQ> Kernel panic - not syncing: Fatal exception in interruptHandle the masked atomic opcodes in the same case as the non-masked
ones: they map to the same struct rds_message.atomic union member, so the existing container_of()/rds_ib_send_unmap_atomic() body is correct for them.Quoted 4 lines
Fixes 20c72bd5f5f9 ("RDS: Implement masked atomic operations")Reported-by Xiang Mei <[email protected]>Assisted-by Claude:claude-opus-4-8Signed-off-by Weiming Shi <[email protected]>Hi Weiming,
Thanks for the thorough writeup, I've traced through the logic and the fix looks correct to me as do the tags. Thanks for catching this!
Reviewed-by Allison Henderson <[email protected]>Allison
Quoted 4 lines
--- net/rds/ib_send.c | 2 ++ 1 file changed, 2 insertions(+)
Quoted 14 lines
net/rds/ib_send.c static struct rds_message *rds_ib_send_unmap_op(struct rds_ib_connection *ic, · line 177
Quoted 13 lines
net/rds/ib_send.c +2
-0@@ -170,6 +170,8 @@ static struct rds_message *rds_ib_send_unmap_op(struct rds_ib_connection *ic,break ;case IB_WR_ATOMIC_FETCH_AND_ADD :case IB_WR_ATOMIC_CMP_AND_SWP : +case IB_WR_MASKED_ATOMIC_FETCH_AND_ADD : +case IB_WR_MASKED_ATOMIC_CMP_AND_SWP :if (send->s_op) { rm = container_of(send->s_op, struct rds_message, atomic);rds_ib_send_unmap_atomic (ic, send->s_op, wc_status);
Thanks for your review.
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Sat, 6 Jun 2026 12:24:48 -0700 you wrote:
rds_ib_xmit_atomic()always programs a masked atomic opcode (IB_WR_MASKED_ATOMIC_CMP_AND_SWPorIB_WR_MASKED_ATOMIC_FETCH_AND_ADD) for every RDS atomic cmsg. But the completion-side switch inrds_ib_send_unmap_op()only handles the non-masked opcodes, so a masked atomic completion falls through to default and returns rm == NULL whilesend->s_opis left set.rds_ib_send_cqe_handler()then dereferences the NULL rm viarm->m_final_op, oopsing in softirq context. An unprivilegedAF_RDSsendmsg()of an atomic cmsg over an active RDS/IB connection triggers it; on hardware that natively accepts masked atomics (mlx4, mlx5) no extra setup is needed.
Quoted 1 line
[...]
Here is the summary with links:
- [net] net/rds: fix NULL deref in rds_ib_send_cqe_handler() on masked atomic completion
https://git.kernel.org/netdev/net/c/34080db3e70d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html