Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net: hsr: fix memory leak on slave unregistration by removing synced VLANs
@ 2026-07-07  8:23 Eric Dumazet
  2026-07-07 11:38 ` Felix Maurer
  2026-07-14 20:45 ` Fernando Fernandez Mancera
  0 siblings, 2 replies; 6+ messages in thread
From: Eric Dumazet @ 2026-07-07  8:23 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, Andrew Lunn, netdev, eric.dumazet, Eric Dumazet,
	syzbot+456957213f32970c0762

When an HSR master device is brought UP, it auto-adds VLAN 0 via
vlan_vid0_add(), which propagates VID 0 to its slave devices.

If a slave device is later unregistered while HSR is active (e.g., during
netns cleanup or interface destruction), hsr_del_port() is called to
detach the slave port from the HSR master. However, hsr_del_port() currently
does not delete the VLAN IDs that were synced to the slave device by HSR.

As a result, the slave device retains a refcount on VID 0 (and any other
synced VLANs). When the slave device is destroyed, its vlan_info /
vlan_vid_info structure remains allocated, leading to a memory leak.

Fix this by calling vlan_vids_del_by_dev(port->dev, master->dev) in
hsr_del_port() before unlinking the slave device, matching the cleanup
behavior in bonding and team drivers.

Fixes: 1a8a63a5305e ("net: hsr: Add VLAN CTAG filter support")
Reported-by: syzbot+456957213f32970c0762@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/6a4cb6ca.57639fcc.86d58.000b.GAE@google.com/T/#u
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/hsr/hsr_slave.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c
index d9af9e65f72f07b1997b80c85db16d812fbda488..2d1e3ea72088e35d5d870b4cc86dd2f789670394 100644
--- a/net/hsr/hsr_slave.c
+++ b/net/hsr/hsr_slave.c
@@ -242,6 +242,7 @@ void hsr_del_port(struct hsr_port *port)
 		netdev_rx_handler_unregister(port->dev);
 		if (!port->hsr->fwd_offloaded)
 			dev_set_promiscuity(port->dev, -1);
+		vlan_vids_del_by_dev(port->dev, master->dev);
 		netdev_upper_dev_unlink(port->dev, master->dev);
 		if (hsr->prot_version == PRP_V1 &&
 		    port->type == HSR_PT_SLAVE_B) {
-- 
2.55.0.795.g602f6c329a-goog


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

* Re: [PATCH net] net: hsr: fix memory leak on slave unregistration by removing synced VLANs
  2026-07-07  8:23 [PATCH net] net: hsr: fix memory leak on slave unregistration by removing synced VLANs Eric Dumazet
@ 2026-07-07 11:38 ` Felix Maurer
  2026-07-14 20:45 ` Fernando Fernandez Mancera
  1 sibling, 0 replies; 6+ messages in thread
From: Felix Maurer @ 2026-07-07 11:38 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Andrew Lunn, netdev, eric.dumazet, syzbot+456957213f32970c0762

On Tue, Jul 07, 2026 at 08:23:27AM +0000, Eric Dumazet wrote:
> When an HSR master device is brought UP, it auto-adds VLAN 0 via
> vlan_vid0_add(), which propagates VID 0 to its slave devices.
>
> If a slave device is later unregistered while HSR is active (e.g., during
> netns cleanup or interface destruction), hsr_del_port() is called to
> detach the slave port from the HSR master. However, hsr_del_port() currently
> does not delete the VLAN IDs that were synced to the slave device by HSR.
>
> As a result, the slave device retains a refcount on VID 0 (and any other
> synced VLANs). When the slave device is destroyed, its vlan_info /
> vlan_vid_info structure remains allocated, leading to a memory leak.
>
> Fix this by calling vlan_vids_del_by_dev(port->dev, master->dev) in
> hsr_del_port() before unlinking the slave device, matching the cleanup
> behavior in bonding and team drivers.
>
> Fixes: 1a8a63a5305e ("net: hsr: Add VLAN CTAG filter support")
> Reported-by: syzbot+456957213f32970c0762@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/netdev/6a4cb6ca.57639fcc.86d58.000b.GAE@google.com/T/#u
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Looks good to me, thank you!

Reviewed-by: Felix Maurer <fmaurer@redhat.com>

> ---
>  net/hsr/hsr_slave.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c
> index d9af9e65f72f07b1997b80c85db16d812fbda488..2d1e3ea72088e35d5d870b4cc86dd2f789670394 100644
> --- a/net/hsr/hsr_slave.c
> +++ b/net/hsr/hsr_slave.c
> @@ -242,6 +242,7 @@ void hsr_del_port(struct hsr_port *port)
>  		netdev_rx_handler_unregister(port->dev);
>  		if (!port->hsr->fwd_offloaded)
>  			dev_set_promiscuity(port->dev, -1);
> +		vlan_vids_del_by_dev(port->dev, master->dev);
>  		netdev_upper_dev_unlink(port->dev, master->dev);
>  		if (hsr->prot_version == PRP_V1 &&
>  		    port->type == HSR_PT_SLAVE_B) {
> --
> 2.55.0.795.g602f6c329a-goog
>


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

* Re: [PATCH net] net: hsr: fix memory leak on slave unregistration by removing synced VLANs
  2026-07-07  8:23 [PATCH net] net: hsr: fix memory leak on slave unregistration by removing synced VLANs Eric Dumazet
  2026-07-07 11:38 ` Felix Maurer
@ 2026-07-14 20:45 ` Fernando Fernandez Mancera
  2026-07-21  1:12   ` Jakub Kicinski
  1 sibling, 1 reply; 6+ messages in thread
From: Fernando Fernandez Mancera @ 2026-07-14 20:45 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Andrew Lunn, netdev, eric.dumazet, syzbot+456957213f32970c0762

> When an HSR master device is brought UP, it auto-adds VLAN 0 via
> vlan_vid0_add(), which propagates VID 0 to its slave devices.
> 
> If a slave device is later unregistered while HSR is active (e.g., during
> netns cleanup or interface destruction), hsr_del_port() is called to
> detach the slave port from the HSR master. However, hsr_del_port() currently
> does not delete the VLAN IDs that were synced to the slave device by HSR.
> 
> As a result, the slave device retains a refcount on VID 0 (and any other
> synced VLANs). When the slave device is destroyed, its vlan_info /
> vlan_vid_info structure remains allocated, leading to a memory leak.
> 
> Fix this by calling vlan_vids_del_by_dev(port->dev, master->dev) in
> hsr_del_port() before unlinking the slave device, matching the cleanup
> behavior in bonding and team drivers.
> 
> Fixes: 1a8a63a5305e ("net: hsr: Add VLAN CTAG filter support")
> Reported-by: syzbot+456957213f32970c0762@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/netdev/6a4cb6ca.57639fcc.86d58.000b.GAE@google.com/T/#u
> Signed-off-by: Eric Dumazet <edumazet@google.com>
>

Reviewed-by: Fernando Fernandez Mancera <fmancera@suse.de>

Thanks!

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

* Re: [PATCH net] net: hsr: fix memory leak on slave unregistration by removing synced VLANs
  2026-07-14 20:45 ` Fernando Fernandez Mancera
@ 2026-07-21  1:12   ` Jakub Kicinski
  2026-07-21  8:59     ` Paolo Abeni
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2026-07-21  1:12 UTC (permalink / raw)
  To: Fernando Fernandez Mancera
  Cc: Eric Dumazet, David S . Miller, Paolo Abeni, Simon Horman,
	Andrew Lunn, netdev, eric.dumazet, syzbot+456957213f32970c0762

On Tue, 14 Jul 2026 22:45:24 +0200 Fernando Fernandez Mancera wrote:
> > When an HSR master device is brought UP, it auto-adds VLAN 0 via
> > vlan_vid0_add(), which propagates VID 0 to its slave devices.
> > 
> > If a slave device is later unregistered while HSR is active (e.g., during
> > netns cleanup or interface destruction), hsr_del_port() is called to
> > detach the slave port from the HSR master. However, hsr_del_port() currently
> > does not delete the VLAN IDs that were synced to the slave device by HSR.
> > 
> > As a result, the slave device retains a refcount on VID 0 (and any other
> > synced VLANs). When the slave device is destroyed, its vlan_info /
> > vlan_vid_info structure remains allocated, leading to a memory leak.
> > 
> > Fix this by calling vlan_vids_del_by_dev(port->dev, master->dev) in
> > hsr_del_port() before unlinking the slave device, matching the cleanup
> > behavior in bonding and team drivers.
> > 
> > Fixes: 1a8a63a5305e ("net: hsr: Add VLAN CTAG filter support")
> > Reported-by: syzbot+456957213f32970c0762@syzkaller.appspotmail.com
> > Closes: https://lore.kernel.org/netdev/6a4cb6ca.57639fcc.86d58.000b.GAE@google.com/T/#u
> > Signed-off-by: Eric Dumazet <edumazet@google.com>
> 
> Reviewed-by: Fernando Fernandez Mancera <fmancera@suse.de>

Just to confirm - is the sashiko review a false positive?
https://sashiko.dev/#/patchset/20260707082327.3238690-1-edumazet%40google.com

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

* Re: [PATCH net] net: hsr: fix memory leak on slave unregistration by removing synced VLANs
  2026-07-21  1:12   ` Jakub Kicinski
@ 2026-07-21  8:59     ` Paolo Abeni
  2026-07-21 10:05       ` Eric Dumazet
  0 siblings, 1 reply; 6+ messages in thread
From: Paolo Abeni @ 2026-07-21  8:59 UTC (permalink / raw)
  To: Jakub Kicinski, Fernando Fernandez Mancera, Eric Dumazet
  Cc: David S . Miller, Simon Horman, Andrew Lunn, netdev, eric.dumazet,
	syzbot+456957213f32970c0762

On 7/21/26 3:12 AM, Jakub Kicinski wrote:
> On Tue, 14 Jul 2026 22:45:24 +0200 Fernando Fernandez Mancera wrote:
>>> When an HSR master device is brought UP, it auto-adds VLAN 0 via
>>> vlan_vid0_add(), which propagates VID 0 to its slave devices.
>>>
>>> If a slave device is later unregistered while HSR is active (e.g., during
>>> netns cleanup or interface destruction), hsr_del_port() is called to
>>> detach the slave port from the HSR master. However, hsr_del_port() currently
>>> does not delete the VLAN IDs that were synced to the slave device by HSR.
>>>
>>> As a result, the slave device retains a refcount on VID 0 (and any other
>>> synced VLANs). When the slave device is destroyed, its vlan_info /
>>> vlan_vid_info structure remains allocated, leading to a memory leak.
>>>
>>> Fix this by calling vlan_vids_del_by_dev(port->dev, master->dev) in
>>> hsr_del_port() before unlinking the slave device, matching the cleanup
>>> behavior in bonding and team drivers.
>>>
>>> Fixes: 1a8a63a5305e ("net: hsr: Add VLAN CTAG filter support")
>>> Reported-by: syzbot+456957213f32970c0762@syzkaller.appspotmail.com
>>> Closes: https://lore.kernel.org/netdev/6a4cb6ca.57639fcc.86d58.000b.GAE@google.com/T/#u
>>> Signed-off-by: Eric Dumazet <edumazet@google.com>
>>
>> Reviewed-by: Fernando Fernandez Mancera <fmancera@suse.de>
> 
> Just to confirm - is the sashiko review a false positive?
> https://sashiko.dev/#/patchset/20260707082327.3238690-1-edumazet%40google.com

I'm sorry, meanwhile PW archived the patch; a repost is needed.

Thanks,

Paolo


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

* Re: [PATCH net] net: hsr: fix memory leak on slave unregistration by removing synced VLANs
  2026-07-21  8:59     ` Paolo Abeni
@ 2026-07-21 10:05       ` Eric Dumazet
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2026-07-21 10:05 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: Jakub Kicinski, Fernando Fernandez Mancera, David S . Miller,
	Simon Horman, Andrew Lunn, netdev, eric.dumazet,
	syzbot+456957213f32970c0762

On Tue, Jul 21, 2026 at 10:59 AM Paolo Abeni <pabeni@redhat.com> wrote:
>
> On 7/21/26 3:12 AM, Jakub Kicinski wrote:
> > On Tue, 14 Jul 2026 22:45:24 +0200 Fernando Fernandez Mancera wrote:
> >>> When an HSR master device is brought UP, it auto-adds VLAN 0 via
> >>> vlan_vid0_add(), which propagates VID 0 to its slave devices.
> >>>
> >>> If a slave device is later unregistered while HSR is active (e.g., during
> >>> netns cleanup or interface destruction), hsr_del_port() is called to
> >>> detach the slave port from the HSR master. However, hsr_del_port() currently
> >>> does not delete the VLAN IDs that were synced to the slave device by HSR.
> >>>
> >>> As a result, the slave device retains a refcount on VID 0 (and any other
> >>> synced VLANs). When the slave device is destroyed, its vlan_info /
> >>> vlan_vid_info structure remains allocated, leading to a memory leak.
> >>>
> >>> Fix this by calling vlan_vids_del_by_dev(port->dev, master->dev) in
> >>> hsr_del_port() before unlinking the slave device, matching the cleanup
> >>> behavior in bonding and team drivers.
> >>>
> >>> Fixes: 1a8a63a5305e ("net: hsr: Add VLAN CTAG filter support")
> >>> Reported-by: syzbot+456957213f32970c0762@syzkaller.appspotmail.com
> >>> Closes: https://lore.kernel.org/netdev/6a4cb6ca.57639fcc.86d58.000b.GAE@google.com/T/#u
> >>> Signed-off-by: Eric Dumazet <edumazet@google.com>
> >>
> >> Reviewed-by: Fernando Fernandez Mancera <fmancera@suse.de>
> >
> > Just to confirm - is the sashiko review a false positive?
> > https://sashiko.dev/#/patchset/20260707082327.3238690-1-edumazet%40google.com
>
> I'm sorry, meanwhile PW archived the patch; a repost is needed.

In any case, I think Sashiko was right, I will send a V2 incorporating
their feedback.

Thanks!

diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c
index d9af9e65f72f07b1997b80c85db16d812fbda488..01c73b4b50ddd89afa74defa37fa83d40c401cf8
100644
--- a/net/hsr/hsr_slave.c
+++ b/net/hsr/hsr_slave.c
@@ -242,6 +242,8 @@ void hsr_del_port(struct hsr_port *port)
                netdev_rx_handler_unregister(port->dev);
                if (!port->hsr->fwd_offloaded)
                        dev_set_promiscuity(port->dev, -1);
+               if (port->type == HSR_PT_SLAVE_A || port->type ==
HSR_PT_SLAVE_B)
+                       vlan_vids_del_by_dev(port->dev, master->dev);
                netdev_upper_dev_unlink(port->dev, master->dev);
                if (hsr->prot_version == PRP_V1 &&
                    port->type == HSR_PT_SLAVE_B) {

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

end of thread, other threads:[~2026-07-21 10:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-07  8:23 [PATCH net] net: hsr: fix memory leak on slave unregistration by removing synced VLANs Eric Dumazet
2026-07-07 11:38 ` Felix Maurer
2026-07-14 20:45 ` Fernando Fernandez Mancera
2026-07-21  1:12   ` Jakub Kicinski
2026-07-21  8:59     ` Paolo Abeni
2026-07-21 10:05       ` Eric Dumazet

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