From: sashiko-bot@kernel.org
To: "Andrey Misiurov" <amisiurov@cloudlinux.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH] RDMA/ucma: reject a second join of the same multicast address
Date: Thu, 19 Nov 2026 12:51:28 +0000 [thread overview]
Message-ID: <sashiko-outbox-223119@kernel.org> (raw)
In-Reply-To: <20261119124153.1745521-1-amisiurov@cloudlinux.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Critical] RDMA/ucma: UAF race between ucma_leave_multicast() and
ucma_process_join()
- [High] RDMA/ucma: TOCTOU race in ucma_process_join() across
__xa_alloc() lock drop
--
commit 92134efcefe26ef534f470da9d6476bb2827da65
Author: Andrey Misiurov <amisiurov@cloudlinux.com>
RDMA/ucma: reject a second join of the same multicast address
This commit rejects duplicate multicast joins for the same address on a
ucma_context by checking ctx->mc_list under multicast_table's XArray lock
before allocating an ID.
> diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
> index a15182f7a7c5b..3f39de52bc9a6 100644
> --- a/drivers/infiniband/core/ucma.c
> +++ b/drivers/infiniband/core/ucma.c
> @@ -1509,7 +1509,7 @@ static ssize_t ucma_process_join(struct ucma_file *file,
> {
> 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 @@ static ssize_t ucma_process_join(struct ucma_file *file,
> 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;
> + }
[Severity: Critical]
Can a concurrent ucma_leave_multicast() and ucma_process_join() for the
same address bypass this check and cause a use-after-free of the leaving
ucma_multicast?
ucma_leave_multicast() removes the old entry from ctx->mc_list and drops
multicast_table's xa_lock before acquiring ctx->mutex to call
rdma_leave_multicast(). A join entering in that window will not see the
address on ctx->mc_list and can take ctx->mutex first:
CPU0 (leave mc_A) CPU1 (re-join same addr, mc_B)
ucma_leave_multicast()
xa_lock(&multicast_table)
list_del(&mc_A->list)
xa_unlock(&multicast_table)
ucma_process_join()
xa_lock(&multicast_table)
/* mc_A already unlinked */
list_add_tail(&mc_B->list,
&ctx->mc_list)
xa_unlock(&multicast_table)
mutex_lock(&ctx->mutex)
rdma_join_multicast(..., mc_B)
/* prepends cma_mc_B to
id_priv->mc_list */
mutex_unlock(&ctx->mutex)
mutex_lock(&ctx->mutex)
rdma_leave_multicast()
/* matches by addr from head,
destroys cma_mc_B instead
of cma_mc_A */
mutex_unlock(&ctx->mutex)
kfree(mc_A)
cma_iboe_join_work_handler()
...
ucma_create_uevent()
/* dereferences mc_A */
<-- use-after-free
Because rdma_join_multicast() inserts at the head of id_priv->mc_list with
list_add(), CPU0's rdma_leave_multicast() destroys CPU1's newly joined
cma_multicast entry while leaving cma_mc_A active and pointing to freed
mc_A. Checking and updating ctx->mc_list (or serializing the join and
leave operations) under ctx->mutex would close this window.
> +
> if (__xa_alloc(&multicast_table, &mc->id, NULL, xa_limit_32b,
> GFP_KERNEL)) {
> ret = -ENOMEM;
[Severity: High]
Can two concurrent joins of the same address both pass the duplicate check
when __xa_alloc() drops multicast_table's xa_lock to allocate an XArray
node?
Because __xa_alloc() is called with GFP_KERNEL before mc is added to
ctx->mc_list, __xas_nomem() will drop and reacquire multicast_table's
xa_lock if it needs to allocate a radix_tree_node:
CPU0 CPU1
ucma_process_join()
xa_lock(&multicast_table)
/* checks ctx->mc_list: empty */
__xa_alloc(..., GFP_KERNEL)
__xas_nomem()
xas_unlock_type()
ucma_process_join()
xa_lock(&multicast_table)
/* checks ctx->mc_list: still empty */
__xa_alloc(...)
list_add_tail(&mc1->list,
&ctx->mc_list)
xa_unlock(&multicast_table)
xas_lock_type()
list_add_tail(&mc0->list,
&ctx->mc_list)
xa_unlock(&multicast_table)
Both joins then succeed for the same address on the same cm_id, recreating
the duplicate cma_multicast state and subsequent use-after-free on leave.
Inserting mc into ctx->mc_list before __xa_alloc() (and unlinking it if
__xa_alloc() fails), or serializing under ctx->mutex, avoids this race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119124153.1745521-1-amisiurov@cloudlinux.com?part=1
prev parent reply other threads:[~2026-11-19 12:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 12:41 [PATCH] RDMA/ucma: reject a second join of the same multicast address Andrey Misiurov
2026-11-19 12:51 ` sashiko-bot [this message]
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=sashiko-outbox-223119@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=amisiurov@cloudlinux.com \
--cc=linux-rdma@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.