[PATCH] IB/ipoib: re-lookup mcast and pin ah across lock drop in ipoib_mcast_send()

From: Bin Luo (University of Electronic Science and Technology of China)

Date: Thu Nov 26 2026 - 01:51:41 EST


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@xxxxxxxxx>
---
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.

.../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