From: Paolo Abeni <pabeni@redhat.com>
To: jiayuan.chen@linux.dev
Cc: ap420073@gmail.com, dsahern@kernel.org, horms@kernel.org,
kuba@kernel.org, jiayuan.chen@shopee.com, edumazet@google.com,
pabeni@redhat.com, linux-kernel@vger.kernel.org,
davem@davemloft.net, netdev@vger.kernel.org,
syzbot+afbcf622635e98bf40d2@syzkaller.appspotmail.com
Subject: Re: [net,v1] net/ipv6: mcast: fix circular locking dependency in __ipv6_dev_mc_inc()
Date: Thu, 19 Mar 2026 13:33:36 +0100 [thread overview]
Message-ID: <20260319123336.216876-1-pabeni@redhat.com> (raw)
In-Reply-To: <20260317111208.62667-1-jiayuan.chen@linux.dev>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net/ipv6: mcast: fix circular locking dependency in __ipv6_dev_mc_inc()
This commit fixes a circular locking dependency deadlock by moving the
GFP_KERNEL allocation outside the mc_lock critical section. The fix
splits mca_alloc() into allocation and initialization phases and also
moves inet6_ifmcaddr_notify() outside the lock.
Link: https://lore.kernel.org/all/69b7dc76.050a0220.248e02.0113.GAE@google.com/T/
> diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
> --- a/net/ipv6/mcast.c
> +++ b/net/ipv6/mcast.c
[ ... ]
> @@ -953,25 +957,23 @@ static int __ipv6_dev_mc_inc(struct net_device *dev,
> mc->mca_users++;
> ip6_mc_add_src(idev, &mc->mca_addr, mode, 0, NULL, 0);
> mutex_unlock(&idev->mc_lock);
> + kfree(mc_alloced);
> in6_dev_put(idev);
> return 0;
> }
> }
>
> - mc = mca_alloc(idev, addr, mode);
> - if (!mc) {
> - mutex_unlock(&idev->mc_lock);
> - in6_dev_put(idev);
> - return -ENOMEM;
> - }
> + mca_init(idev, addr, mode, mc_alloced);
> + mc = mc_alloced;
>
> rcu_assign_pointer(mc->next, idev->mc_list);
> rcu_assign_pointer(idev->mc_list, mc);
>
> mld_del_delrec(idev, mc);
> igmp6_group_added(mc);
> + mutex_unlock(&idev->mc_lock);
> +
> inet6_ifmcaddr_notify(dev, mc, RTM_NEWMULTICAST);
> - mutex_unlock(&idev->mc_lock);
^^^^
Can this lead to a use-after-free on mc?
After mutex_unlock(&idev->mc_lock), the mc object has been published to
idev->mc_list with mca_refcnt=1. At this point, a concurrent
ipv6_mc_destroy_dev() could acquire mc_lock, iterate mc_list, and call
ma_put() on mc:
net/ipv6/mcast.c:ipv6_mc_destroy_dev() {
mutex_lock(&idev->mc_lock);
while ((mc = rcu_dereference_protected(idev->mc_list, ...)) != NULL) {
...
ma_put(mc);
}
mutex_unlock(&idev->mc_lock);
}
Since mca_refcnt starts at 1 (set by mca_init), ma_put() would decrement
it to 0 and call kfree_rcu(mc, rcu):
net/ipv6/mcast.c:ma_put() {
if (refcount_dec_and_test(&mc->mca_refcnt)) {
in6_dev_put(mc->idev);
kfree_rcu(mc, rcu);
}
}
Then inet6_ifmcaddr_notify() calls nlmsg_new(..., GFP_KERNEL) which can
sleep and create an RCU quiescent state, allowing the kfree_rcu callback
to execute and free mc before inet6_fill_ifmcaddr() accesses mc->idev,
mc->idev->dev->ifindex, and mc->mca_addr.
Should the fix take an additional refcount on mc (refcount_inc(&mc->mca_refcnt))
before releasing mc_lock, then drop it with ma_put(mc) after
inet6_ifmcaddr_notify() returns?
>
> return 0;
> }
prev parent reply other threads:[~2026-03-19 12:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 11:12 [PATCH net v1] net/ipv6: mcast: fix circular locking dependency in __ipv6_dev_mc_inc() Jiayuan Chen
2026-03-19 1:15 ` Jakub Kicinski
2026-03-19 3:04 ` Jiayuan Chen
2026-03-19 3:26 ` Jakub Kicinski
2026-03-19 4:12 ` Jiayuan Chen
2026-03-19 12:44 ` Paolo Abeni
2026-03-19 15:36 ` Wouter Verhelst
2026-03-23 6:54 ` Kuniyuki Iwashima
2026-03-19 12:33 ` Paolo Abeni [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=20260319123336.216876-1-pabeni@redhat.com \
--to=pabeni@redhat.com \
--cc=ap420073@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jiayuan.chen@linux.dev \
--cc=jiayuan.chen@shopee.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=syzbot+afbcf622635e98bf40d2@syzkaller.appspotmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox