Skip to content

Commit 3e2ab0c

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 9075216 commit 3e2ab0c

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

drivers/net/tun.c

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

17881788
if (!dev)
17891789
return -ENOMEM;
1790+
err = dev_get_valid_name(net, dev, name);
1791+
if (err)
1792+
goto err_free_dev;
17901793

17911794
dev_net_set(dev, net);
17921795
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
@@ -3742,6 +3742,9 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
37423742
unsigned char name_assign_type,
37433743
void (*setup)(struct net_device *),
37443744
unsigned int txqs, unsigned int rxqs);
3745+
int dev_get_valid_name(struct net *net, struct net_device *dev,
3746+
const char *name);
3747+
37453748
#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
37463749
alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, 1, 1)
37473750

net/core/dev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,9 +1115,8 @@ static int dev_alloc_name_ns(struct net *net,
11151115
return ret;
11161116
}
11171117

1118-
static int dev_get_valid_name(struct net *net,
1119-
struct net_device *dev,
1120-
const char *name)
1118+
int dev_get_valid_name(struct net *net, struct net_device *dev,
1119+
const char *name)
11211120
{
11221121
BUG_ON(!net);
11231122

@@ -1133,6 +1132,7 @@ static int dev_get_valid_name(struct net *net,
11331132

11341133
return 0;
11351134
}
1135+
EXPORT_SYMBOL(dev_get_valid_name);
11361136

11371137
/**
11381138
* dev_change_name - change name of a device

0 commit comments

Comments
 (0)