Commit 412c4bfc authored by YueHaibing's avatar YueHaibing Committed by Kelsey Skunberg

net-sysfs: call dev_hold if kobject_init_and_add success

In netdev_queue_add_kobject and rx_queue_add_kobject,
if sysfs_create_group failed, kobject_put will call
netdev_queue_release to decrease dev refcont, however
dev_hold has not be called. So we will see this while
unregistering dev:

unregister_netdevice: waiting for bcsh0 to become free. Usage count = -1
Reported-by: default avatarHulk Robot <hulkci@huawei.com>
Fixes: d0d66837 ("net: don't decrement kobj reference count on init failure")
Signed-off-by: default avatarYueHaibing <yuehaibing@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>

CVE-2019-20811

(backported from commit a3e23f71)
[ William Breathitt Gray: context adjustments ]
Signed-off-by: default avatarWilliam Breathitt Gray <william.gray@canonical.com>
Acked-by: default avatarThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Acked-by: default avatarColin Ian King <colin.king@canonical.com>
Signed-off-by: default avatarIan May <ian.may@canonical.com>
Signed-off-by: default avatarKelsey Skunberg <kelsey.skunberg@canonical.com>
parent a0e3c3e0
...@@ -895,6 +895,8 @@ static int rx_queue_add_kobject(struct net_device *dev, int index) ...@@ -895,6 +895,8 @@ static int rx_queue_add_kobject(struct net_device *dev, int index)
if (error) if (error)
goto exit; goto exit;
dev_hold(queue->dev);
if (dev->sysfs_rx_queue_group) { if (dev->sysfs_rx_queue_group) {
error = sysfs_create_group(kobj, dev->sysfs_rx_queue_group); error = sysfs_create_group(kobj, dev->sysfs_rx_queue_group);
if (error) if (error)
...@@ -902,7 +904,6 @@ static int rx_queue_add_kobject(struct net_device *dev, int index) ...@@ -902,7 +904,6 @@ static int rx_queue_add_kobject(struct net_device *dev, int index)
} }
kobject_uevent(kobj, KOBJ_ADD); kobject_uevent(kobj, KOBJ_ADD);
dev_hold(queue->dev);
return error; return error;
exit: exit:
...@@ -1291,6 +1292,8 @@ static int netdev_queue_add_kobject(struct net_device *dev, int index) ...@@ -1291,6 +1292,8 @@ static int netdev_queue_add_kobject(struct net_device *dev, int index)
if (error) if (error)
goto exit; goto exit;
dev_hold(queue->dev);
#ifdef CONFIG_BQL #ifdef CONFIG_BQL
error = sysfs_create_group(kobj, &dql_group); error = sysfs_create_group(kobj, &dql_group);
if (error) if (error)
...@@ -1298,7 +1301,6 @@ static int netdev_queue_add_kobject(struct net_device *dev, int index) ...@@ -1298,7 +1301,6 @@ static int netdev_queue_add_kobject(struct net_device *dev, int index)
#endif #endif
kobject_uevent(kobj, KOBJ_ADD); kobject_uevent(kobj, KOBJ_ADD);
dev_hold(queue->dev);
return 0; return 0;
exit: exit:
......
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