Skip to content

Commit aa9ab97

Browse files
congwanggregkh
authored andcommitted
tun: call dev_get_valid_name() before register_netdevice()
[ Upstream commit 0ad646c ] register_netdevice() could fail early when we have an invalid dev name, in which case ->ndo_uninit() is not called. For tun device, this is a problem because a timer etc. are already initialized and it expects ->ndo_uninit() to clean them up. We could move these initializations into a ->ndo_init() so that register_netdevice() knows better, however this is still complicated due to the logic in tun_detach(). Therefore, I choose to just call dev_get_valid_name() before register_netdevice(), which is quicker and much easier to audit. And for this specific case, it is already enough. Fixes: 96442e4 ("tuntap: choose the txq based on rxq") Reported-by: Dmitry Alexeev <avekceeb@gmail.com> Cc: Jason Wang <jasowang@redhat.com> Cc: "Michael S. Tsirkin" <mst@redhat.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4531b5b commit aa9ab97

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

drivers/net/tun.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,9 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
18131813

18141814
if (!dev)
18151815
return -ENOMEM;
1816+
err = dev_get_valid_name(net, dev, name);
1817+
if (err)
1818+
goto err_free_dev;
18161819

18171820
dev_net_set(dev, net);
18181821
dev->rtnl_link_ops = &tun_link_ops;

include/linux/netdevice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3702,6 +3702,9 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
37023702
unsigned char name_assign_type,
37033703
void (*setup)(struct net_device *),
37043704
unsigned int txqs, unsigned int rxqs);
3705+
int dev_get_valid_name(struct net *net, struct net_device *dev,
3706+
const char *name);
3707+
37053708
#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
37063709
alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, 1, 1)
37073710

net/core/dev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,8 @@ static int dev_alloc_name_ns(struct net *net,
11461146
return ret;
11471147
}
11481148

1149-
static int dev_get_valid_name(struct net *net,
1150-
struct net_device *dev,
1151-
const char *name)
1149+
int dev_get_valid_name(struct net *net, struct net_device *dev,
1150+
const char *name)
11521151
{
11531152
BUG_ON(!net);
11541153

@@ -1164,6 +1163,7 @@ static int dev_get_valid_name(struct net *net,
11641163

11651164
return 0;
11661165
}
1166+
EXPORT_SYMBOL(dev_get_valid_name);
11671167

11681168
/**
11691169
* dev_change_name - change name of a device

0 commit comments

Comments
 (0)