veth: prevent oops caused by netdev destructor
From: Stephen Hemminger <shemminger@vyatta.com> The veth driver will oops if sysfs hooks are open while module is removed. The net device destructor can not point to code in a module; basically there are only two possible safe values: NULL - no destructor, or free_netdev - free on last use Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
6a783c9067
commit
ae0e8e8220
@@ -210,14 +210,11 @@ rx_drop:
|
|||||||
|
|
||||||
static struct net_device_stats *veth_get_stats(struct net_device *dev)
|
static struct net_device_stats *veth_get_stats(struct net_device *dev)
|
||||||
{
|
{
|
||||||
struct veth_priv *priv;
|
struct veth_priv *priv = netdev_priv(dev);
|
||||||
struct net_device_stats *dev_stats;
|
struct net_device_stats *dev_stats = &dev->stats;
|
||||||
int cpu;
|
unsigned int cpu;
|
||||||
struct veth_net_stats *stats;
|
struct veth_net_stats *stats;
|
||||||
|
|
||||||
priv = netdev_priv(dev);
|
|
||||||
dev_stats = &dev->stats;
|
|
||||||
|
|
||||||
dev_stats->rx_packets = 0;
|
dev_stats->rx_packets = 0;
|
||||||
dev_stats->tx_packets = 0;
|
dev_stats->tx_packets = 0;
|
||||||
dev_stats->rx_bytes = 0;
|
dev_stats->rx_bytes = 0;
|
||||||
@@ -225,6 +222,7 @@ static struct net_device_stats *veth_get_stats(struct net_device *dev)
|
|||||||
dev_stats->tx_dropped = 0;
|
dev_stats->tx_dropped = 0;
|
||||||
dev_stats->rx_dropped = 0;
|
dev_stats->rx_dropped = 0;
|
||||||
|
|
||||||
|
if (priv->stats)
|
||||||
for_each_online_cpu(cpu) {
|
for_each_online_cpu(cpu) {
|
||||||
stats = per_cpu_ptr(priv->stats, cpu);
|
stats = per_cpu_ptr(priv->stats, cpu);
|
||||||
|
|
||||||
@@ -261,6 +259,8 @@ static int veth_close(struct net_device *dev)
|
|||||||
netif_carrier_off(dev);
|
netif_carrier_off(dev);
|
||||||
netif_carrier_off(priv->peer);
|
netif_carrier_off(priv->peer);
|
||||||
|
|
||||||
|
free_percpu(priv->stats);
|
||||||
|
priv->stats = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,15 +291,6 @@ static int veth_dev_init(struct net_device *dev)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void veth_dev_free(struct net_device *dev)
|
|
||||||
{
|
|
||||||
struct veth_priv *priv;
|
|
||||||
|
|
||||||
priv = netdev_priv(dev);
|
|
||||||
free_percpu(priv->stats);
|
|
||||||
free_netdev(dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct net_device_ops veth_netdev_ops = {
|
static const struct net_device_ops veth_netdev_ops = {
|
||||||
.ndo_init = veth_dev_init,
|
.ndo_init = veth_dev_init,
|
||||||
.ndo_open = veth_open,
|
.ndo_open = veth_open,
|
||||||
@@ -317,7 +308,7 @@ static void veth_setup(struct net_device *dev)
|
|||||||
dev->netdev_ops = &veth_netdev_ops;
|
dev->netdev_ops = &veth_netdev_ops;
|
||||||
dev->ethtool_ops = &veth_ethtool_ops;
|
dev->ethtool_ops = &veth_ethtool_ops;
|
||||||
dev->features |= NETIF_F_LLTX;
|
dev->features |= NETIF_F_LLTX;
|
||||||
dev->destructor = veth_dev_free;
|
dev->destructor = free_netdev;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user