Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Leon Romanovsky" <leon@kernel.org>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH rdma-next 1/3] RDMA/core: Preserve the selected source GID on failed AH modification
Date: Thu, 15 Oct 2026 12:11:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-172785@kernel.org> (raw)
In-Reply-To: <20261015-ib-core-fixes-v1-1-60f6da3ddec3@nvidia.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] rdma: memory leak and UAF due to missing sgid_attr refcount in rvt_modify_ah()
--

commit cfb0c41a87200fc5df90876398650807044c23ad
Author: Leon Romanovsky <leon@kernel.org>

RDMA/core: Preserve the selected source GID on failed AH modification

When an address-handle modification fails, the core replaces its source-GID
reference. This commit ensures the selected source GID is preserved by only
updating ah->sgid_attr when the modification is successful.

> diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
> index edf62652f9d3e..7d52d30362087 100644
> --- a/drivers/infiniband/core/verbs.c
> +++ b/drivers/infiniband/core/verbs.c
> @@ -1011,7 +1011,8 @@ int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr)
>  		ah->device->ops.modify_ah(ah, ah_attr) :
>  		-EOPNOTSUPP;
>  
> -	ah->sgid_attr = rdma_update_sgid_attr(ah_attr, ah->sgid_attr);
> +	if (!ret)
> +		ah->sgid_attr = rdma_update_sgid_attr(ah_attr, ah->sgid_attr);
>  	rdma_unfill_sgid_attr(ah_attr, old_sgid_attr);

[Severity: High]
Does this sequence expose a memory leak and use-after-free in providers
that do a shallow copy of ah_attr?

For example, in drivers/infiniband/sw/rdmavt/ah.c:rvt_modify_ah(), the
structure is shallowly copied:

	ah->attr = *ah_attr;

This causes a memory leak of the old sgid_attr reference because
rdma_put_gid_attr() is not called on the old pointer, and it adopts the
new sgid_attr without incrementing its refcount.

When rdma_modify_ah() finishes, it calls rdma_unfill_sgid_attr() which
drops the temporary refcount that rvt_modify_ah() copied but didn't pin.
This leaves the driver's ah->attr exposed to a dangling pointer.

Later, rvt_destroy_ah() will unconditionally call:

	rdma_destroy_ah_attr(&ah->attr);

This calls rdma_put_gid_attr() on the unheld pointer, resulting in a
refcount underflow and use-after-free.

This path is concretely reachable via the hfi1 provider (for instance,
hfi1_modify_qp0_ah() uses rdma_modify_ah() with IB_AH_GRH enabled). 

Should providers like rdmavt be updated to use rdma_replace_ah_attr()
to properly manage these refcounts?

>  	return ret;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261015-ib-core-fixes-v1-0-60f6da3ddec3@nvidia.com?part=1

  reply	other threads:[~2026-10-15 12:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 11:58 [PATCH rdma-next 0/3] Various core fixes spotted by LLMs Leon Romanovsky
2026-10-15 11:59 ` [PATCH rdma-next 1/3] RDMA/core: Preserve the selected source GID on failed AH modification Leon Romanovsky
2026-10-15 12:11   ` sashiko-bot [this message]
2026-10-15 11:59 ` [PATCH rdma-next 2/3] RDMA/core: Free unpublished port statistics after initial-read failure Leon Romanovsky
2026-10-15 12:09   ` sashiko-bot
2026-10-15 11:59 ` [PATCH rdma-next 3/3] RDMA/core: Reject LAG selection when source MAC lookup fails Leon Romanovsky
2026-10-15 12:15   ` sashiko-bot

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-172785@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=leon@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox