linux/drivers/infiniband/sw/rxe
Michael Bommarito 1caceeb2d7 RDMA/rxe: insert mcg into mcg_tree only after rxe_mcast_add() succeeds
rxe_get_mcg() publishes a newly allocated multicast group in
rxe->mcg_tree before programming the backing Ethernet multicast address
with rxe_mcast_add(), which runs outside mcg_lock. A local userspace
RDMA client reaches this path with ATTACH_MCAST on a UD QP; if
rxe_mcast_add() then returns an error (for example -ENODEV when the
backing netdev has been removed, or a propagated dev_mc_add() error),
the unwind frees the published group without removing it from the tree.
A later lookup of the same MGID dereferences the freed struct rxe_mcg
from __rxe_lookup_mcg().

Fix this by keeping the new mcg private until rxe_mcast_add() succeeds.
Split the tree publication into __rxe_publish_mcg(), call rxe_mcast_add()
before taking the tree reference, and free the still-private mcg on
failure. Because the group is never visible in mcg_tree until the
multicast address is programmed, no concurrent caller can look it up or
attach a QP to a group that is about to be torn down, so the error path
needs no conditional unwind. If another caller publishes the same MGID
while the address is being programmed, the post-add re-check under
mcg_lock finds the winner; this caller then drops its private object and
balances its own rxe_mcast_add() with rxe_mcast_del() before returning
the winner.

Reproduced by forcing the rxe_mcast_add() error return under KASAN:
without the change the next attach to the same MGID reports a
slab-use-after-free in __rxe_lookup_mcg(); with it the forced failure
returns cleanly. A no-injection attach/detach regression, including a
two-QP shared join/leave and re-attach, stays KASAN- and leak-clean.

Fixes: a926a903b7 ("RDMA/rxe: Do not call  dev_mc_add/del() under a spinlock")
Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com>
Link: https://patch.msgid.link/20260617022728.2770116-1-michael.bommarito@gmail.com
Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
2026-09-01 09:12:02 -04:00
..
Kconfig RDMA/rxe: Remove 32-bit architecture support 2025-04-21 04:16:29 -04:00
Makefile RDMA/rxe: support perf mgmt GET method 2026-05-18 04:58:41 -04:00
rxe_av.c
rxe_comp.c RDMA/rxe: Fix race condition in QP timer handlers 2026-01-28 05:02:30 -05:00
rxe_cq.c RDMA: Properly propagate the number of CQEs as unsigned int 2026-03-30 13:47:44 -04:00
rxe_hdr.h RDMA/rxe: Fix __bth_set_resv6a 2024-08-23 11:42:38 -03:00
rxe_hw_counters.c RDMA/rxe: add SENT/RCVD bytes 2026-05-18 04:58:41 -04:00
rxe_hw_counters.h RDMA/rxe: add SENT/RCVD bytes 2026-05-18 04:58:41 -04:00
rxe_icrc.c RDMA/rxe: switch to using the crc32 library 2025-02-09 04:20:10 -05:00
rxe_loc.h RDMA/rxe: support perf mgmt GET method 2026-05-18 04:58:41 -04:00
rxe_mad.c RDMA/rxe: support perf mgmt GET method 2026-05-18 04:58:41 -04:00
rxe_mcast.c RDMA/rxe: insert mcg into mcg_tree only after rxe_mcast_add() succeeds 2026-09-01 09:12:02 -04:00
rxe_mmap.c RDMA/rxe: Allow queue VMAs to outlive ucontexts 2026-07-26 03:11:00 -04:00
rxe_mr.c RDMA/rxe: Fix integer overflow in mr_check_range() leading to OOB access 2026-09-01 06:20:18 -04:00
rxe_mw.c RDMA/rxe: Check PDs for memory window binds 2026-07-05 09:45:02 -04:00
rxe_net.c net: Use helpers to get/set UDP len tree-wide 2026-07-22 13:47:02 +02:00
rxe_net.h RDMA/rxe: Support RDMA link creation and destruction per net namespace 2026-03-30 13:47:43 -04:00
rxe_ns.c udp_tunnel: Pass struct sock to udp_tunnel_sock_release(). 2026-05-05 17:47:03 -07:00
rxe_ns.h RDMA/rxe: Add net namespace support for IPv4/IPv6 sockets 2026-03-30 13:47:43 -04:00
rxe_odp.c RDMA/rxe: Restore HMM_PFN_WRITE check in ODP write paths 2026-09-01 08:30:34 -04:00
rxe_opcode.c
rxe_opcode.h RDMA//rxe: Optimize send path in rxe_resp.c 2023-06-09 13:18:52 -03:00
rxe_param.h RDMA/rxe: Fix typos in comments 2026-05-29 10:39:10 -03:00
rxe_pool.c RDMA/rxe: Fix the warning "__rxe_cleanup+0x12c/0x170 [rdma_rxe]" 2025-01-14 06:43:53 -05:00
rxe_pool.h
rxe_qp.c RDMA/rxe: Fix OOB in free_rd_atomic_resources() 2026-08-12 07:53:57 -04:00
rxe_queue.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
rxe_queue.h
rxe_recv.c Linux 7.1-rc5 2026-05-25 13:48:00 -03:00
rxe_req.c RDMA/rxe: Validate num_sge/cur_sge before indexing wqe->dma.sge[] 2026-07-20 09:00:40 -04:00
rxe_resp.c RDMA/rxe: Avoid reprocessing the current packet after the QP enters the error state 2026-07-12 07:26:03 -04:00
rxe_srq.c RDMA: Change capability fields in ib_device_attr from int to u32 2026-07-12 04:47:44 -04:00
rxe_task.c RDMA/rxe: Replace use of system_unbound_wq with rxe_wq 2026-03-30 13:47:43 -04:00
rxe_task.h RDMA/rxe: Remove unused rxe_run_task 2025-04-20 11:27:39 -04:00
rxe_verbs.c RDMA/rxe: validate access flags before swapping the MR's PD 2026-09-01 06:05:28 -04:00
rxe_verbs.h RDMA/rxe: add SENT/RCVD bytes 2026-05-18 04:58:41 -04:00
rxe.c RDMA/rxe: Fix typos in comments 2026-05-29 10:39:10 -03:00
rxe.h RDMA/rxe: Replace use of system_unbound_wq with rxe_wq 2026-03-30 13:47:43 -04:00