mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next] ipv4: igmp: remove multicast group from hash table on device destruction
@ 2026-06-09 12:26 Yuyang Huang
  2026-06-10  7:50 ` Nicolas Dichtel
  0 siblings, 1 reply; 6+ messages in thread
From: Yuyang Huang @ 2026-06-09 12:26 UTC (permalink / raw)
  To: Yuyang Huang
  Cc: David S. Miller, David Ahern, Eric Dumazet, Ido Schimmel,
	Jakub Kicinski, Paolo Abeni, Simon Horman, linux-kernel, netdev

When a device is destroyed under RTNL, ip_mc_destroy_dev() iterates through
the multicast list and calls ip_ma_put() on each membership, scheduling
them for RCU reclamation. However, they are not unlinked from the device's
multicast hash table (mc_hash).

Since the device remains published in dev->ip_ptr until after
ip_mc_destroy_dev() completes, concurrent RCU readers traversing mc_hash
can still locate and access the multicast group after its refcount is
decremented. If the RCU callback runs and frees the group while a reader is
accessing it, a use-after-free occurs.

Fix this by unlinking the multicast group from mc_hash using
ip_mc_hash_remove() before scheduling it for reclamation.

Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
---
 net/ipv4/igmp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index b6337a47c141..af38073a822d 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -1923,6 +1923,7 @@ void ip_mc_destroy_dev(struct in_device *in_dev)
 
 	while ((i = rtnl_dereference(in_dev->mc_list)) != NULL) {
 		in_dev->mc_list = i->next_rcu;
+		ip_mc_hash_remove(in_dev, i);
 		WRITE_ONCE(in_dev->mc_count, in_dev->mc_count - 1);
 		ip_mc_clear_src(i);
 		ip_ma_put(i);
-- 
2.54.0.1099.g489fc7bff1-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] ipv4: igmp: remove multicast group from hash table on device destruction
  2026-06-09 12:26 [PATCH net-next] ipv4: igmp: remove multicast group from hash table on device destruction Yuyang Huang
@ 2026-06-10  7:50 ` Nicolas Dichtel
  2026-06-10  8:37   ` Yuyang Huang
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Dichtel @ 2026-06-10  7:50 UTC (permalink / raw)
  To: Yuyang Huang
  Cc: David S. Miller, David Ahern, Eric Dumazet, Ido Schimmel,
	Jakub Kicinski, Paolo Abeni, Simon Horman, linux-kernel, netdev

Le 09/06/2026 à 14:26, Yuyang Huang a écrit :
> When a device is destroyed under RTNL, ip_mc_destroy_dev() iterates through
> the multicast list and calls ip_ma_put() on each membership, scheduling
> them for RCU reclamation. However, they are not unlinked from the device's
> multicast hash table (mc_hash).
> 
> Since the device remains published in dev->ip_ptr until after
> ip_mc_destroy_dev() completes, concurrent RCU readers traversing mc_hash
> can still locate and access the multicast group after its refcount is
> decremented. If the RCU callback runs and frees the group while a reader is
> accessing it, a use-after-free occurs.
> 
> Fix this by unlinking the multicast group from mc_hash using
> ip_mc_hash_remove() before scheduling it for reclamation.
> 
> Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
A 'Fixes' tag may be useful for backports.

Regards,
Nicolas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] ipv4: igmp: remove multicast group from hash table on device destruction
  2026-06-10  7:50 ` Nicolas Dichtel
@ 2026-06-10  8:37   ` Yuyang Huang
  2026-06-10  8:52     ` Nicolas Dichtel
  0 siblings, 1 reply; 6+ messages in thread
From: Yuyang Huang @ 2026-06-10  8:37 UTC (permalink / raw)
  To: nicolas.dichtel
  Cc: David S. Miller, David Ahern, Eric Dumazet, Ido Schimmel,
	Jakub Kicinski, Paolo Abeni, Simon Horman, linux-kernel, netdev

On Wed, Jun 10, 2026 at 4:50 PM Nicolas Dichtel
<nicolas.dichtel@6wind.com> wrote:
>
> Le 09/06/2026 à 14:26, Yuyang Huang a écrit :
> > When a device is destroyed under RTNL, ip_mc_destroy_dev() iterates through
> > the multicast list and calls ip_ma_put() on each membership, scheduling
> > them for RCU reclamation. However, they are not unlinked from the device's
> > multicast hash table (mc_hash).
> >
> > Since the device remains published in dev->ip_ptr until after
> > ip_mc_destroy_dev() completes, concurrent RCU readers traversing mc_hash
> > can still locate and access the multicast group after its refcount is
> > decremented. If the RCU callback runs and frees the group while a reader is
> > accessing it, a use-after-free occurs.
> >
> > Fix this by unlinking the multicast group from mc_hash using
> > ip_mc_hash_remove() before scheduling it for reclamation.
> >
> > Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
> A 'Fixes' tag may be useful for backports.

Thanks for the suggestion. Per discussion in the following thread, we
don't need to add the Fixes tag for a trivial fix.

https://lore.kernel.org/netdev/20260604101728.GA771160@shredder/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] ipv4: igmp: remove multicast group from hash table on device destruction
  2026-06-10  8:37   ` Yuyang Huang
@ 2026-06-10  8:52     ` Nicolas Dichtel
  2026-06-10 10:56       ` Yuyang Huang
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Dichtel @ 2026-06-10  8:52 UTC (permalink / raw)
  To: Yuyang Huang
  Cc: David S. Miller, David Ahern, Eric Dumazet, Ido Schimmel,
	Jakub Kicinski, Paolo Abeni, Simon Horman, linux-kernel, netdev

Le 10/06/2026 à 10:37, Yuyang Huang a écrit :
> On Wed, Jun 10, 2026 at 4:50 PM Nicolas Dichtel
> <nicolas.dichtel@6wind.com> wrote:
>>
>> Le 09/06/2026 à 14:26, Yuyang Huang a écrit :
>>> When a device is destroyed under RTNL, ip_mc_destroy_dev() iterates through
>>> the multicast list and calls ip_ma_put() on each membership, scheduling
>>> them for RCU reclamation. However, they are not unlinked from the device's
>>> multicast hash table (mc_hash).
>>>
>>> Since the device remains published in dev->ip_ptr until after
>>> ip_mc_destroy_dev() completes, concurrent RCU readers traversing mc_hash
>>> can still locate and access the multicast group after its refcount is
>>> decremented. If the RCU callback runs and frees the group while a reader is
>>> accessing it, a use-after-free occurs.
>>>
>>> Fix this by unlinking the multicast group from mc_hash using
>>> ip_mc_hash_remove() before scheduling it for reclamation.
>>>
>>> Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
>> A 'Fixes' tag may be useful for backports.
> 
> Thanks for the suggestion. Per discussion in the following thread, we
> don't need to add the Fixes tag for a trivial fix.
> 
> https://lore.kernel.org/netdev/20260604101728.GA771160@shredder/

I probably misunderstood the commit, but you are talking about a
'use-after-free', which doesn't seem trivial for me.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] ipv4: igmp: remove multicast group from hash table on device destruction
  2026-06-10  8:52     ` Nicolas Dichtel
@ 2026-06-10 10:56       ` Yuyang Huang
  2026-06-14  0:29         ` Yuyang Huang
  0 siblings, 1 reply; 6+ messages in thread
From: Yuyang Huang @ 2026-06-10 10:56 UTC (permalink / raw)
  To: nicolas.dichtel
  Cc: David S. Miller, David Ahern, Eric Dumazet, Ido Schimmel,
	Jakub Kicinski, Paolo Abeni, Simon Horman, linux-kernel, netdev

>I probably misunderstood the commit, but you are talking about a
>'use-after-free', which doesn't seem trivial for me.

This patch is a follow up for fixing sashiko's review comment in
previous patch series:

* https://lore.kernel.org/netdev/95adff35-ee56-49d3-8567-382ac17810b3@redhat.com/
* https://sashiko.dev/#/patchset/20260531030705.3754389-1-yuyanghuang%40google.com

This is a long-standing bug, not a recent regression. Given that my
previous patch series fixing the data race in the igmp/mld code path
did not qualify for a 'Fixes' tag, I am unsure if these follow-up
patches warrant one.

In https://lwn.net/Articles/1074171/, Linus mentioned

```
So people: start looking closer at your pull requests, and ask
yourself: "Is this really a regression or serious enough that it
shouldn't just go into the development pile?".
```

My takeaway is if the bug is not a recent regression or series enough
bug, the patches should goes into the net-next instead of net.

Thanks,
Yuyang

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] ipv4: igmp: remove multicast group from hash table on device destruction
  2026-06-10 10:56       ` Yuyang Huang
@ 2026-06-14  0:29         ` Yuyang Huang
  0 siblings, 0 replies; 6+ messages in thread
From: Yuyang Huang @ 2026-06-14  0:29 UTC (permalink / raw)
  To: nicolas.dichtel
  Cc: David S. Miller, David Ahern, Eric Dumazet, Ido Schimmel,
	Jakub Kicinski, Paolo Abeni, Simon Horman, linux-kernel, netdev

If there is a strong preference for adding a Fixes tag, I will include
it in the v2 patch.

Thanks,
Yuyang

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-06-14  0:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-09 12:26 [PATCH net-next] ipv4: igmp: remove multicast group from hash table on device destruction Yuyang Huang
2026-06-10  7:50 ` Nicolas Dichtel
2026-06-10  8:37   ` Yuyang Huang
2026-06-10  8:52     ` Nicolas Dichtel
2026-06-10 10:56       ` Yuyang Huang
2026-06-14  0:29         ` Yuyang Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®