Skip to content

Commit de0083c

Browse files
TaeheeYoodavem330
authored andcommitted
hsr: avoid to create proc file after unregister
When an interface is being deleted, "/proc/net/dev_snmp6/<interface name>" is deleted. The function for this is addrconf_ifdown() in the addrconf_notify() and it is called by notification, which is NETDEV_UNREGISTER. But, if NETDEV_CHANGEMTU is triggered after NETDEV_UNREGISTER, this proc file will be created again. This recreated proc file will be deleted by netdev_wati_allrefs(). Before netdev_wait_allrefs() is called, creating a new HSR interface routine can be executed and It tries to create a proc file but it will find an un-deleted proc file. At this point, it warns about it. To avoid this situation, it can use ->dellink() instead of ->ndo_uninit() to release resources because ->dellink() is called before NETDEV_UNREGISTER. So, a proc file will not be recreated. Test commands ip link add dummy0 type dummy ip link add dummy1 type dummy ip link set dummy0 mtu 1300 #SHELL1 while : do ip link add hsr0 type hsr slave1 dummy0 slave2 dummy1 done #SHELL2 while : do ip link del hsr0 done Splat looks like: [ 9888.980852][ T2752] proc_dir_entry 'dev_snmp6/hsr0' already registered [ 9888.981797][ C2] WARNING: CPU: 2 PID: 2752 at fs/proc/generic.c:372 proc_register+0x2d5/0x430 [ 9888.981798][ C2] Modules linked in: hsr dummy veth openvswitch nsh nf_conncount nf_nat nf_conntrack nf_defrag_ipv6x [ 9888.981814][ C2] CPU: 2 PID: 2752 Comm: ip Tainted: G W 5.8.0-rc1+ #616 [ 9888.981815][ C2] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 9888.981816][ C2] RIP: 0010:proc_register+0x2d5/0x430 [ 9888.981818][ C2] Code: fc ff df 48 89 fa 48 c1 ea 03 80 3c 02 00 0f 85 65 01 00 00 49 8b b5 e0 00 00 00 48 89 ea 40 [ 9888.981819][ C2] RSP: 0018:ffff8880628dedf0 EFLAGS: 00010286 [ 9888.981821][ C2] RAX: dffffc0000000008 RBX: ffff888028c69170 RCX: ffffffffaae09a62 [ 9888.981822][ C2] RDX: 0000000000000001 RSI: 0000000000000008 RDI: ffff88806c9f75ac [ 9888.981823][ C2] RBP: ffff888028c693f4 R08: ffffed100d9401bd R09: ffffed100d9401bd [ 9888.981824][ C2] R10: ffffffffaddf406f R11: 0000000000000001 R12: ffff888028c69308 [ 9888.981825][ C2] R13: ffff8880663584c8 R14: dffffc0000000000 R15: ffffed100518d27e [ 9888.981827][ C2] FS: 00007f3876b3b0c0(0000) GS:ffff88806c800000(0000) knlGS:0000000000000000 [ 9888.981828][ C2] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 9888.981829][ C2] CR2: 00007f387601a8c0 CR3: 000000004101a002 CR4: 00000000000606e0 [ 9888.981830][ C2] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 9888.981831][ C2] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 9888.981832][ C2] Call Trace: [ 9888.981833][ C2] ? snmp6_seq_show+0x180/0x180 [ 9888.981834][ C2] proc_create_single_data+0x7c/0xa0 [ 9888.981835][ C2] snmp6_register_dev+0xb0/0x130 [ 9888.981836][ C2] ipv6_add_dev+0x4b7/0xf60 [ 9888.981837][ C2] addrconf_notify+0x684/0x1ca0 [ 9888.981838][ C2] ? __mutex_unlock_slowpath+0xd0/0x670 [ 9888.981839][ C2] ? kasan_unpoison_shadow+0x30/0x40 [ 9888.981840][ C2] ? wait_for_completion+0x250/0x250 [ 9888.981841][ C2] ? inet6_ifinfo_notify+0x100/0x100 [ 9888.981842][ C2] ? dropmon_net_event+0x227/0x410 [ 9888.981843][ C2] ? notifier_call_chain+0x90/0x160 [ 9888.981844][ C2] ? inet6_ifinfo_notify+0x100/0x100 [ 9888.981845][ C2] notifier_call_chain+0x90/0x160 [ 9888.981846][ C2] register_netdevice+0xbe5/0x1070 [ ... ] Reported-by: [email protected] Fixes: e0a4b99 ("hsr: use upper/lower device infrastructure") Signed-off-by: Taehee Yoo <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b835a71 commit de0083c

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

net/hsr/hsr_device.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static void hsr_announce(struct timer_list *t)
339339
rcu_read_unlock();
340340
}
341341

342-
static void hsr_del_ports(struct hsr_priv *hsr)
342+
void hsr_del_ports(struct hsr_priv *hsr)
343343
{
344344
struct hsr_port *port;
345345

@@ -356,31 +356,12 @@ static void hsr_del_ports(struct hsr_priv *hsr)
356356
hsr_del_port(port);
357357
}
358358

359-
/* This has to be called after all the readers are gone.
360-
* Otherwise we would have to check the return value of
361-
* hsr_port_get_hsr().
362-
*/
363-
static void hsr_dev_destroy(struct net_device *hsr_dev)
364-
{
365-
struct hsr_priv *hsr = netdev_priv(hsr_dev);
366-
367-
hsr_debugfs_term(hsr);
368-
hsr_del_ports(hsr);
369-
370-
del_timer_sync(&hsr->prune_timer);
371-
del_timer_sync(&hsr->announce_timer);
372-
373-
hsr_del_self_node(hsr);
374-
hsr_del_nodes(&hsr->node_db);
375-
}
376-
377359
static const struct net_device_ops hsr_device_ops = {
378360
.ndo_change_mtu = hsr_dev_change_mtu,
379361
.ndo_open = hsr_dev_open,
380362
.ndo_stop = hsr_dev_close,
381363
.ndo_start_xmit = hsr_dev_xmit,
382364
.ndo_fix_features = hsr_fix_features,
383-
.ndo_uninit = hsr_dev_destroy,
384365
};
385366

386367
static struct device_type hsr_type = {

net/hsr/hsr_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
#include <linux/netdevice.h>
1212
#include "hsr_main.h"
1313

14+
void hsr_del_ports(struct hsr_priv *hsr);
1415
void hsr_dev_setup(struct net_device *dev);
1516
int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
1617
unsigned char multicast_spec, u8 protocol_version,
1718
struct netlink_ext_ack *extack);
1819
void hsr_check_carrier_and_operstate(struct hsr_priv *hsr);
1920
bool is_hsr_master(struct net_device *dev);
2021
int hsr_get_max_mtu(struct hsr_priv *hsr);
21-
2222
#endif /* __HSR_DEVICE_H */

net/hsr/hsr_main.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include <linux/netdevice.h>
9+
#include <net/rtnetlink.h>
910
#include <linux/rculist.h>
1011
#include <linux/timer.h>
1112
#include <linux/etherdevice.h>
@@ -100,8 +101,10 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
100101
master = hsr_port_get_hsr(port->hsr, HSR_PT_MASTER);
101102
hsr_del_port(port);
102103
if (hsr_slave_empty(master->hsr)) {
103-
unregister_netdevice_queue(master->dev,
104-
&list_kill);
104+
const struct rtnl_link_ops *ops;
105+
106+
ops = master->dev->rtnl_link_ops;
107+
ops->dellink(master->dev, &list_kill);
105108
unregister_netdevice_many(&list_kill);
106109
}
107110
}
@@ -144,9 +147,9 @@ static int __init hsr_init(void)
144147

145148
static void __exit hsr_exit(void)
146149
{
147-
unregister_netdevice_notifier(&hsr_nb);
148150
hsr_netlink_exit();
149151
hsr_debugfs_remove_root();
152+
unregister_netdevice_notifier(&hsr_nb);
150153
}
151154

152155
module_init(hsr_init);

net/hsr/hsr_netlink.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
8383
return hsr_dev_finalize(dev, link, multicast_spec, hsr_version, extack);
8484
}
8585

86+
static void hsr_dellink(struct net_device *dev, struct list_head *head)
87+
{
88+
struct hsr_priv *hsr = netdev_priv(dev);
89+
90+
del_timer_sync(&hsr->prune_timer);
91+
del_timer_sync(&hsr->announce_timer);
92+
93+
hsr_debugfs_term(hsr);
94+
hsr_del_ports(hsr);
95+
96+
hsr_del_self_node(hsr);
97+
hsr_del_nodes(&hsr->node_db);
98+
99+
unregister_netdevice_queue(dev, head);
100+
}
101+
86102
static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
87103
{
88104
struct hsr_priv *hsr = netdev_priv(dev);
@@ -118,6 +134,7 @@ static struct rtnl_link_ops hsr_link_ops __read_mostly = {
118134
.priv_size = sizeof(struct hsr_priv),
119135
.setup = hsr_dev_setup,
120136
.newlink = hsr_newlink,
137+
.dellink = hsr_dellink,
121138
.fill_info = hsr_fill_info,
122139
};
123140

0 commit comments

Comments
 (0)