Commit 0ad646c8 authored by Cong Wang's avatar Cong Wang Committed by David S. Miller

tun: call dev_get_valid_name() before register_netdevice()

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: 96442e42 ("tuntap: choose the txq based on rxq")
Reported-by: default avatarDmitry Alexeev <avekceeb@gmail.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2459b4c6
...@@ -2027,6 +2027,9 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) ...@@ -2027,6 +2027,9 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
if (!dev) if (!dev)
return -ENOMEM; return -ENOMEM;
err = dev_get_valid_name(net, dev, name);
if (err)
goto err_free_dev;
dev_net_set(dev, net); dev_net_set(dev, net);
dev->rtnl_link_ops = &tun_link_ops; dev->rtnl_link_ops = &tun_link_ops;
......
...@@ -3694,6 +3694,9 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, ...@@ -3694,6 +3694,9 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
unsigned char name_assign_type, unsigned char name_assign_type,
void (*setup)(struct net_device *), void (*setup)(struct net_device *),
unsigned int txqs, unsigned int rxqs); unsigned int txqs, unsigned int rxqs);
int dev_get_valid_name(struct net *net, struct net_device *dev,
const char *name);
#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \ #define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, 1, 1) alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, 1, 1)
......
...@@ -1147,8 +1147,7 @@ static int dev_alloc_name_ns(struct net *net, ...@@ -1147,8 +1147,7 @@ static int dev_alloc_name_ns(struct net *net,
return ret; return ret;
} }
static int dev_get_valid_name(struct net *net, int dev_get_valid_name(struct net *net, struct net_device *dev,
struct net_device *dev,
const char *name) const char *name)
{ {
BUG_ON(!net); BUG_ON(!net);
...@@ -1165,6 +1164,7 @@ static int dev_get_valid_name(struct net *net, ...@@ -1165,6 +1164,7 @@ static int dev_get_valid_name(struct net *net,
return 0; return 0;
} }
EXPORT_SYMBOL(dev_get_valid_name);
/** /**
* dev_change_name - change name of a device * dev_change_name - change name of a device
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment