Skip to content

Commit 6f74a45

Browse files
Kirill Tkhaiintel-lab-lkp
authored andcommitted
net: Fix device name resolving crash in default_device_exit()
The following script makes kernel to crash since it can't obtain a name for a device, when the name is occupied by another device: #!/bin/bash ifconfig eth0 down ifconfig eth1 down index=`cat /sys/class/net/eth1/ifindex` ip link set eth1 name dev$index unshare -n sleep 1h & pid=$! while [[ "`readlink /proc/self/ns/net`" == "`readlink /proc/$pid/ns/net`" ]]; do continue; done ip link set dev$index netns $pid ip link set eth0 name dev$index kill -9 $pid Kernel messages: virtio_net virtio1 dev3: renamed from eth1 virtio_net virtio0 dev3: renamed from eth0 default_device_exit: failed to move dev3 to init_net: -17 ------------[ cut here ]------------ kernel BUG at net/core/dev.c:8978! invalid opcode: 0000 [#1] PREEMPT SMP CPU: 1 PID: 276 Comm: kworker/u8:3 Not tainted 4.17.0+ torvalds#292 Workqueue: netns cleanup_net RIP: 0010:default_device_exit+0x9c/0xb0 [stack trace snipped] This patch gives more variability during choosing new name of device and fixes the problem. Signed-off-by: Kirill Tkhai <[email protected]>
1 parent f0dc7f9 commit 6f74a45

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

net/core/dev.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8959,7 +8959,6 @@ static void __net_exit default_device_exit(struct net *net)
89598959
rtnl_lock();
89608960
for_each_netdev_safe(net, dev, aux) {
89618961
int err;
8962-
char fb_name[IFNAMSIZ];
89638962

89648963
/* Ignore unmoveable devices (i.e. loopback) */
89658964
if (dev->features & NETIF_F_NETNS_LOCAL)
@@ -8970,8 +8969,7 @@ static void __net_exit default_device_exit(struct net *net)
89708969
continue;
89718970

89728971
/* Push remaining network devices to init_net */
8973-
snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex);
8974-
err = dev_change_net_namespace(dev, &init_net, fb_name);
8972+
err = dev_change_net_namespace(dev, &init_net, "dev%d");
89758973
if (err) {
89768974
pr_emerg("%s: failed to move %s to init_net: %d\n",
89778975
__func__, dev->name, err);

0 commit comments

Comments
 (0)