Skip to content

Commit aa13454

Browse files
congwangBrian Maly
authored andcommitted
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: 96442e4 ("tuntap: choose the txq based on rxq") Reported-by: Dmitry Alexeev <[email protected]> Cc: Jason Wang <[email protected]> Cc: "Michael S. Tsirkin" <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]> (cherry picked from commit 0ad646c) Orabug: 29925555 CVE: CVE-2018-7191 Reviewed-by: Somasundaram Krishnasamy <[email protected]> Signed-off-by: Allen Pais <[email protected]> Signed-off-by: Brian Maly <[email protected]>
1 parent a3a1a6e commit aa13454

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
@@ -1635,6 +1635,9 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
16351635

16361636
if (!dev)
16371637
return -ENOMEM;
1638+
err = dev_get_valid_name(net, dev, name);
1639+
if (err)
1640+
goto err_free_dev;
16381641

16391642
dev_net_set(dev, net);
16401643
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
@@ -3449,6 +3449,9 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
34493449
unsigned char name_assign_type,
34503450
void (*setup)(struct net_device *),
34513451
unsigned int txqs, unsigned int rxqs);
3452+
int dev_get_valid_name(struct net *net, struct net_device *dev,
3453+
const char *name);
3454+
34523455
#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
34533456
alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, 1, 1)
34543457

net/core/dev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,9 +1088,8 @@ static int dev_alloc_name_ns(struct net *net,
10881088
return ret;
10891089
}
10901090

1091-
static int dev_get_valid_name(struct net *net,
1092-
struct net_device *dev,
1093-
const char *name)
1091+
int dev_get_valid_name(struct net *net, struct net_device *dev,
1092+
const char *name)
10941093
{
10951094
BUG_ON(!net);
10961095

@@ -1106,6 +1105,7 @@ static int dev_get_valid_name(struct net *net,
11061105

11071106
return 0;
11081107
}
1108+
EXPORT_SYMBOL(dev_get_valid_name);
11091109

11101110
/**
11111111
* dev_change_name - change name of a device

0 commit comments

Comments
 (0)