I have found a memleak in ipvlan, here is the detail. ipvlan forwards ndo_vlan_rx_add_vid/ndo_vlan_rx_kill_vid to its lower device via vlan_vid_add()/vlan_vid_del(), which takes a reference of the vid on the lower device. The kill path is guarded by vlan_hw_filter_capable() in vlan_kill_rx_filter_info(): when the device no longer advertises NETIF_F_HW_VLAN_CTAG_FILTER, ndo_vlan_rx_kill_vid is skipped. The filter feature is inherited from the lower device, so turning off the rx-vlan-filter of the lower device (e.g. via ethtool) also clears it on the ipvlan device and breaks the add/kill pairing: when the ipvlan device is later unregistered, the references it took on the lower device are never released, and the vlan_info/vlan_vid_info objects leak once the lower device is unregistered as well. Reproducer (kmemleak, e.g. on bond0 which exposes rx-vlan-filter in its hw_features): ip link add bond0 type bond && ip link set bond0 up ip link add ipv0 link bond0 type ipvlan mode l2 ip link set ipv0 up ethtool -K bond0 rx-vlan-filter off ip link del ipv0 ip link del bond0 echo scan > /sys/kernel/debug/kmemleak BUG: memory leak unreferenced object 0xffff0000d148e000 (size 256): comm "syz.2.759", pid 4740, jiffies 4295212514 (age 1787.924s) hex dump (first 32 bytes): 00 00 fc b7 00 00 ff ff 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: create_object usr/src/kernels/mm/kmemleak.c:766 [inline] kmemleak_alloc+0xb4/0xd0 usr/src/kernels/mm/kmemleak.c:1038 kmemleak_alloc_recursive usr/src/kernels/include/linux/kmemleak.h:42 [inline] slab_post_alloc_hook usr/src/kernels/mm/slab.h:774 [inline] slab_alloc_node usr/src/kernels/mm/slub.c:3543 [inline] __kmem_cache_alloc_node+0x340/0x470 usr/src/kernels/mm/slub.c:3582 kmalloc_trace+0x44/0x100 usr/src/kernels/mm/slab_common.c:1050 kmalloc usr/src/kernels/include/linux/slab.h:609 [inline] kzalloc usr/src/kernels/include/linux/slab.h:730 [inline] vlan_info_alloc usr/src/kernels/net/8021q/vlan_core.c:153 [inline] vlan_vid_add+0x1a0/0x438 usr/src/kernels/net/8021q/vlan_core.c:329 ipvlan_vlan_rx_add_vid+0x44/0x60 usr/src/kernels/drivers/net/ipvlan/ipvlan_main.c:422 vlan_add_rx_filter_info.part.0+0x78/0xa8 usr/src/kernels/net/8021q/vlan_core.c:211 vlan_add_rx_filter_info usr/src/kernels/net/8021q/vlan_core.c:171 [inline] __vlan_vid_add usr/src/kernels/net/8021q/vlan_core.c:306 [inline] vlan_vid_add+0x344/0x438 usr/src/kernels/net/8021q/vlan_core.c:336 vlan_vid0_add usr/src/kernels/net/8021q/vlan.c:372 [inline] vlan_device_event+0x544/0x1110 usr/src/kernels/net/8021q/vlan.c:413 notifier_call_chain+0xd0/0x1e0 usr/src/kernels/kernel/notifier.c:93 raw_notifier_call_chain+0x44/0x60 usr/src/kernels/kernel/notifier.c:461 call_netdevice_notifiers_info+0xa0/0x160 usr/src/kernels/net/core/dev.c:2040 call_netdevice_notifiers_extack usr/src/kernels/net/core/dev.c:2078 [inline] call_netdevice_notifiers usr/src/kernels/net/core/dev.c:2092 [inline] __dev_notify_flags+0x10c/0x210 usr/src/kernels/net/core/dev.c:8872 rtnl_configure_link+0x130/0x180 usr/src/kernels/net/core/rtnetlink.c:3379 rtnl_newlink_create+0x268/0x660 usr/src/kernels/net/core/rtnetlink.c:3566 __rtnl_newlink+0x99c/0x9f0 usr/src/kernels/net/core/rtnetlink.c:3778 rtnl_newlink+0x6c/0xa8 usr/src/kernels/net/core/rtnetlink.c:3791 BUG: memory leak unreferenced object 0xffff0000d40e3280 (size 32): comm "syz.2.759", pid 4740, jiffies 4295212514 (age 1787.924s) hex dump (first 32 bytes): a0 e0 48 d1 00 00 ff ff a0 e0 48 d1 00 00 ff ff ..H.......H..... 81 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: create_object usr/src/kernels/mm/kmemleak.c:766 [inline] kmemleak_alloc+0xb4/0xd0 usr/src/kernels/mm/kmemleak.c:1038 kmemleak_alloc_recursive usr/src/kernels/include/linux/kmemleak.h:42 [inline] slab_post_alloc_hook usr/src/kernels/mm/slab.h:774 [inline] slab_alloc_node usr/src/kernels/mm/slub.c:3543 [inline] __kmem_cache_alloc_node+0x340/0x470 usr/src/kernels/mm/slub.c:3582 kmalloc_trace+0x44/0x100 usr/src/kernels/mm/slab_common.c:1050 kmalloc usr/src/kernels/include/linux/slab.h:609 [inline] kzalloc usr/src/kernels/include/linux/slab.h:730 [inline] vlan_vid_info_alloc usr/src/kernels/net/8021q/vlan_core.c:196 [inline] __vlan_vid_add usr/src/kernels/net/8021q/vlan_core.c:302 [inline] vlan_vid_add+0x20c/0x438 usr/src/kernels/net/8021q/vlan_core.c:336 ipvlan_vlan_rx_add_vid+0x44/0x60 usr/src/kernels/drivers/net/ipvlan/ipvlan_main.c:422 vlan_add_rx_filter_info.part.0+0x78/0xa8 usr/src/kernels/net/8021q/vlan_core.c:211 vlan_add_rx_filter_info usr/src/kernels/net/8021q/vlan_core.c:171 [inline] __vlan_vid_add usr/src/kernels/net/8021q/vlan_core.c:306 [inline] vlan_vid_add+0x344/0x438 usr/src/kernels/net/8021q/vlan_core.c:336 vlan_vid0_add usr/src/kernels/net/8021q/vlan.c:372 [inline] vlan_device_event+0x544/0x1110 usr/src/kernels/net/8021q/vlan.c:413 notifier_call_chain+0xd0/0x1e0 usr/src/kernels/kernel/notifier.c:93 raw_notifier_call_chain+0x44/0x60 usr/src/kernels/kernel/notifier.c:461 call_netdevice_notifiers_info+0xa0/0x160 usr/src/kernels/net/core/dev.c:2040 call_netdevice_notifiers_extack usr/src/kernels/net/core/dev.c:2078 [inline] call_netdevice_notifiers usr/src/kernels/net/core/dev.c:2092 [inline] __dev_notify_flags+0x10c/0x210 usr/src/kernels/net/core/dev.c:8872 rtnl_configure_link+0x130/0x180 usr/src/kernels/net/core/rtnetlink.c:3379 rtnl_newlink_create+0x268/0x660 usr/src/kernels/net/core/rtnetlink.c:3566 __rtnl_newlink+0x99c/0x9f0 usr/src/kernels/net/core/rtnetlink.c:3778 rtnl_newlink+0x6c/0xa8 usr/src/kernels/net/core/rtnetlink.c:3791 Fix this in the NETDEV_FEAT_CHANGE handler: when a filter feature bit is about to be cleared, drop the vid references the ipvlan device holds on the lower device for that protocol while the bit is still set (otherwise vlan_kill_rx_filter_info() skips them too), and push them back if the filtering capability returns. This is the same per-protocol handling that vlan_drop_rx_ctag/stag_filter_info() and vlan_get_rx_ctag/stag_filter_info() give a device whose own features change, so reuse those helpers. macvlan is not affected: it propagates the feature changes with netdev_update_features(), so the vid references on the lower device are dropped and re-added automatically by vlan_drop_rx_{ctag,stag}_filter_info()/vlan_get_rx_{ctag,stag}_filter_info() in __netdev_update_features(). ipvlan assigns dev->features directly and bypasses that cleanup. Fixes: 2ad7bf363841 ("ipvlan: Initial check-in of the IPVLAN driver.") Closes: https://lore.kernel.org/netdev/6a4cb6ca.57639fcc.86d58.000b.GAE@google.com/ Signed-off-by: zhusicong --- drivers/net/ipvlan/ipvlan_main.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c @@ -869,10 +869,42 @@ case NETDEV_FEAT_CHANGE: list_for_each_entry(ipvlan, &port->ipvlans, pnode) { - ipvlan->dev->features = dev->features & IPVLAN_FEATURES; + netdev_features_t old_features = ipvlan->dev->features; + netdev_features_t new_features = + dev->features & IPVLAN_FEATURES; + int err = 0; + + /* IPVLAN_FEATURES includes the vlan filter bits. + * When the physical device loses one of them, the + * vid references this device holds on it must be + * dropped while the bit is still set, otherwise + * vlan_kill_rx_filter_info() skips them and they + * are never released. Push them back when the + * filtering capability returns. + */ + if (old_features & ~new_features & + NETIF_F_HW_VLAN_CTAG_FILTER) + vlan_drop_rx_ctag_filter_info(ipvlan->dev); + if (old_features & ~new_features & + NETIF_F_HW_VLAN_STAG_FILTER) + vlan_drop_rx_stag_filter_info(ipvlan->dev); + + ipvlan->dev->features = new_features; netif_inherit_tso_max(ipvlan->dev, dev); ipvlan->dev->needed_headroom = dev->needed_headroom; ipvlan->dev->needed_tailroom = dev->needed_tailroom; + + if (new_features & ~old_features & + NETIF_F_HW_VLAN_CTAG_FILTER) + err |= vlan_get_rx_ctag_filter_info(ipvlan->dev); + if (new_features & ~old_features & + NETIF_F_HW_VLAN_STAG_FILTER) + err |= vlan_get_rx_stag_filter_info(ipvlan->dev); + if (err) + netdev_err(ipvlan->dev, + "failed to sync vlan ids to %s\n", + dev->name); + netdev_features_change(ipvlan->dev); } break; -- 2.43.0