All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leonro@nvidia.com>
To: "Bin Luo (University of Electronic Science and Technology of
	China)" <luob87709@gmail.com>
Cc: <jgg@nvidia.com>, <linux-rdma@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] IB/ipoib: re-lookup mcast and pin ah across lock drop in ipoib_mcast_send()
Date: Thu, 26 Nov 2026 21:00:51 +0200	[thread overview]
Message-ID: <20261126190051.GX774860@unreal> (raw)
In-Reply-To: <20261126065125.1082-1-luob87709@gmail.com>

On Thu, Nov 26, 2026 at 02:51:25PM +0800, Bin Luo (University of Electronic Science and Technology of China) wrote:
> In ipoib_mcast_send(), priv->lock is dropped around ipoib_neigh_get()
> and reacquired without re-validating mcast. During that window,
> ipoib_mcast_dev_flush() can unlink mcast from priv->multicast_list and
> priv->multicast_tree, and ipoib_mcast_free() can run
> ipoib_del_neighs_by_gid() and ipoib_put_ah(mcast->ah) before blocking
> on netif_tx_lock_bh().
> 
> When ipoib_mcast_send() reacquires priv->lock, it can attach a newly
> allocated neigh onto the dying mcast->neigh_list (leaving a dangling
> list pointer once ipoib_mcast_free() calls kfree(mcast)) and access
> mcast->ah after its reference was dropped. Furthermore, mcast->ah is
> dereferenced after priv->lock is released without holding a dedicated
> reference when neigh allocation fails.
> 
> Re-lookup mcast with __ipoib_mcast_find() after reacquiring priv->lock,
> drop the skb if mcast or mcast->ah is gone, and take a reference on ah
> under priv->lock across rn->send().
> 
> Fixes: b63b70d87741 ("IPoIB: Use a private hash table for path lookup in xmit path")
> Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
> ---
> Found by code inspection. Compile-tested on x86_64 with W=1 and KASAN (drivers/infiniband/ulp/ipoib/ipoib_multicast.o); not runtime-tested on InfiniBand hardware.

To exercise the KASAN paths, you need to run the code. Are you saying the code
has not been tested at all?

Thanks

> 
>  .../infiniband/ulp/ipoib/ipoib_multicast.c    | 21 +++++++++++++++----
>  1 file changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
> index 379b783..81393a2 100644
> --- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
> +++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
> @@ -792,25 +792,38 @@ void ipoib_mcast_send(struct net_device *dev, u8 *daddr, struct sk_buff *skb)
>  		}
>  	} else {
>  		struct ipoib_neigh *neigh;
> +		struct ipoib_ah *ah;
>  
>  		spin_unlock_irqrestore(&priv->lock, flags);
>  		neigh = ipoib_neigh_get(dev, daddr);
>  		spin_lock_irqsave(&priv->lock, flags);
> +		mcast = __ipoib_mcast_find(dev, mgid);
> +		if (!mcast || !mcast->ah) {
> +			++dev->stats.tx_dropped;
> +			dev_kfree_skb_any(skb);
> +			spin_unlock_irqrestore(&priv->lock, flags);
> +			if (neigh)
> +				ipoib_neigh_put(neigh);
> +			return;
> +		}
> +		ah = mcast->ah;
> +		kref_get(&ah->ref);
>  		if (!neigh) {
>  			neigh = ipoib_neigh_alloc(daddr, dev);
>  			/* Make sure that the neigh will be added only
>  			 * once to mcast list.
>  			 */
>  			if (neigh && list_empty(&neigh->list)) {
> -				kref_get(&mcast->ah->ref);
> -				neigh->ah	= mcast->ah;
> +				kref_get(&ah->ref);
> +				neigh->ah	= ah;
>  				neigh->ah->valid = 1;
>  				list_add_tail(&neigh->list, &mcast->neigh_list);
>  			}
>  		}
>  		spin_unlock_irqrestore(&priv->lock, flags);
> -		mcast->ah->last_send = rn->send(dev, skb, mcast->ah->ah,
> -						IB_MULTICAST_QPN);
> +		ah->last_send = rn->send(dev, skb, ah->ah,
> +					 IB_MULTICAST_QPN);
> +		ipoib_put_ah(ah);
>  		if (neigh)
>  			ipoib_neigh_put(neigh);
>  		return;
> -- 
> 2.43.0
> 
> 

      parent reply	other threads:[~2026-11-26 19:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  6:51 [PATCH] IB/ipoib: re-lookup mcast and pin ah across lock drop in ipoib_mcast_send() Bin Luo (University of Electronic Science and Technology of China)
2026-11-26  6:59 ` sashiko-bot
2026-11-26 19:00 ` Leon Romanovsky [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=20261126190051.GX774860@unreal \
    --to=leonro@nvidia.com \
    --cc=jgg@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=luob87709@gmail.com \
    /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.