Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb0fb36

Browse files
jasowangdavem330
authored andcommitted
tuntap: attach queue 0 before registering netdevice
We attach queue 0 after registering netdevice currently. This leads to call netif_set_real_num_{tx|rx}_queues() after registering the netdevice. Since we allow tun/tap has a maximum of 1024 queues, this may lead a huge number of uevents to be injected to userspace since we create 2048 kobjects and then remove 2046. Solve this problem by attaching queue 0 and set the real number of queues before registering netdevice. Reported-by: Jiri Slaby <[email protected]> Tested-by: Jiri Slaby <[email protected]> Signed-off-by: Jason Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 092a5fc commit eb0fb36

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

drivers/net/tun.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,6 @@ static int tun_attach(struct tun_struct *tun, struct file *file)
493493

494494
tun_set_real_num_queues(tun);
495495

496-
if (tun->numqueues == 1)
497-
netif_carrier_on(tun->dev);
498-
499496
/* device is allowed to go away first, so no need to hold extra
500497
* refcnt.
501498
*/
@@ -1612,6 +1609,10 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
16121609
TUN_USER_FEATURES;
16131610
dev->features = dev->hw_features;
16141611

1612+
err = tun_attach(tun, file);
1613+
if (err < 0)
1614+
goto err_free_dev;
1615+
16151616
err = register_netdevice(tun->dev);
16161617
if (err < 0)
16171618
goto err_free_dev;
@@ -1621,9 +1622,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
16211622
device_create_file(&tun->dev->dev, &dev_attr_group))
16221623
pr_err("Failed to create tun sysfs files\n");
16231624

1624-
err = tun_attach(tun, file);
1625-
if (err < 0)
1626-
goto err_free_dev;
1625+
netif_carrier_on(tun->dev);
16271626
}
16281627

16291628
tun_debug(KERN_INFO, tun, "tun_set_iff\n");

0 commit comments

Comments
 (0)