Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Andrey Misiurov <amisiurov@cloudlinux.com>
To: Jason Gunthorpe <jgg@nvidia.com>, Leon Romanovsky <leonro@nvidia.com>
Cc: linux-rdma@vger.kernel.org, Quanye Yang <quanyeyang@proton.me>,
	linux-kernel@vger.kernel.org,
	Andrey Misiurov <amisiurov@cloudlinux.com>,
	stable@vger.kernel.org
Subject: [PATCH] RDMA/ucma: reject a second join of the same multicast address
Date: Thu, 19 Nov 2026 13:41:53 +0100	[thread overview]
Message-ID: <20261119124153.1745521-1-amisiurov@cloudlinux.com> (raw)

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;

                 reply	other threads:[~2026-11-19 12:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119124153.1745521-1-amisiurov@cloudlinux.com \
    --to=amisiurov@cloudlinux.com \
    --cc=jgg@nvidia.com \
    --cc=leonro@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=quanyeyang@proton.me \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox