Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] RDMA/ucma: reject a second join of the same multicast address
@ 2026-11-19 12:41 Andrey Misiurov
  0 siblings, 0 replies; only message in thread
From: Andrey Misiurov @ 2026-11-19 12:41 UTC (permalink / raw)
  To: Jason Gunthorpe, Leon Romanovsky
  Cc: linux-rdma, Quanye Yang, linux-kernel, Andrey Misiurov, stable

ucma_process_join() lets one cm_id join the same multicast address twice,
creating two ucma_multicast objects (A and B) and, via
rdma_join_multicast(), two cma_multicast entries that both point back at
the ucma object.

rdma_leave_multicast() matches a leave only by sockaddr and destroys the
first entry it finds. So LEAVE_MCAST on A destroys B's cma_multicast and
frees ucma object A, while A's cma_multicast stays on the list with a
context pointing at freed memory. The next event for it is a use-after-free:

  BUG: KASAN: slab-use-after-free in ucma_create_uevent+0xb11/0xb70 [rdma_ucm]
  Workqueue: rdma_cm cma_iboe_join_work_handler [rdma_cm]
  Call Trace:
   ucma_create_uevent+0xb11/0xb70 [rdma_ucm]
   ucma_event_handler+0xd5/0xa10 [rdma_ucm]
   cma_cm_event_handler+0x98/0x310 [rdma_cm]
   cma_iboe_join_work_handler+0xac/0x170 [rdma_cm]
   process_scheduled_works+0xb59/0x1890
   worker_thread+0x470/0xe40
   kthread+0x33a/0x450
   ret_from_fork+0x59/0x90
   ret_from_fork_asm+0x1a/0x30

Any user with access to /dev/infiniband/rdma_cm can trigger it.

Reject a second join of an address already joined on the same cm_id. The
incomplete fix 662ade4de9ff ("RDMA/ucma: Serialize join and leave on
copy_to_user failure") left this path open.

Fixes: 662ade4de9ff ("RDMA/ucma: Serialize join and leave on copy_to_user failure")
Cc: stable@vger.kernel.org
Signed-off-by: Andrey Misiurov <amisiurov@cloudlinux.com>
---
Found during a backport review.

Reproduced on debian13 6.12.88 debug (KASAN=y) over Soft-RoCE: two joins of
one address on a cm_id, then LEAVE -> the KASAN use-after-free above within
one run. With the fix the second join returns -EADDRINUSE and the run is clean.

 drivers/infiniband/core/ucma.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -1509,7 +1509,7 @@
 {
 	struct rdma_ucm_create_id_resp resp;
 	struct ucma_context *ctx;
-	struct ucma_multicast *mc;
+	struct ucma_multicast *mc, *tmp;
 	struct sockaddr *addr;
 	int ret;
 	u8 join_state;
@@ -1544,6 +1544,13 @@
 	memcpy(&mc->addr, addr, cmd->addr_size);
 
 	xa_lock(&multicast_table);
+	/* leave matches by address only; refuse a duplicate */
+	list_for_each_entry(tmp, &ctx->mc_list, list)
+		if (!memcmp(&tmp->addr, addr, cmd->addr_size)) {
+			ret = -EADDRINUSE;
+			goto err_free_mc;
+		}
+
 	if (__xa_alloc(&multicast_table, &mc->id, NULL, xa_limit_32b,
 		     GFP_KERNEL)) {
 		ret = -ENOMEM;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-19 12:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 12:41 [PATCH] RDMA/ucma: reject a second join of the same multicast address Andrey Misiurov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox