linux/drivers/net
David S. Miller cf124db566 net: Fix inconsistent teardown and release of private netdev state.
Network devices can allocate reasources and private memory using
netdev_ops->ndo_init().  However, the release of these resources
can occur in one of two different places.

Either netdev_ops->ndo_uninit() or netdev->destructor().

The decision of which operation frees the resources depends upon
whether it is necessary for all netdev refs to be released before it
is safe to perform the freeing.

netdev_ops->ndo_uninit() presumably can occur right after the
NETDEV_UNREGISTER notifier completes and the unicast and multicast
address lists are flushed.

netdev->destructor(), on the other hand, does not run until the
netdev references all go away.

Further complicating the situation is that netdev->destructor()
almost universally does also a free_netdev().

This creates a problem for the logic in register_netdevice().
Because all callers of register_netdevice() manage the freeing
of the netdev, and invoke free_netdev(dev) if register_netdevice()
fails.

If netdev_ops->ndo_init() succeeds, but something else fails inside
of register_netdevice(), it does call ndo_ops->ndo_uninit().  But
it is not able to invoke netdev->destructor().

This is because netdev->destructor() will do a free_netdev() and
then the caller of register_netdevice() will do the same.

However, this means that the resources that would normally be released
by netdev->destructor() will not be.

Over the years drivers have added local hacks to deal with this, by
invoking their destructor parts by hand when register_netdevice()
fails.

Many drivers do not try to deal with this, and instead we have leaks.

Let's close this hole by formalizing the distinction between what
private things need to be freed up by netdev->destructor() and whether
the driver needs unregister_netdevice() to perform the free_netdev().

netdev->priv_destructor() performs all actions to free up the private
resources that used to be freed by netdev->destructor(), except for
free_netdev().

netdev->needs_free_netdev is a boolean that indicates whether
free_netdev() should be done at the end of unregister_netdevice().

Now, register_netdevice() can sanely release all resources after
ndo_ops->ndo_init() succeeds, by invoking both ndo_ops->ndo_uninit()
and netdev->priv_destructor().

And at the end of unregister_netdevice(), we invoke
netdev->priv_destructor() and optionally call free_netdev().

Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-07 15:53:24 -04:00
..
appletalk Annotate hardware config module parameters in drivers/net/appletalk/ 2017-04-20 12:02:32 +01:00
arcnet Annotate hardware config module parameters in drivers/net/arcnet/ 2017-04-20 12:02:32 +01:00
bonding net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
caif net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
can net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
cris
dsa net: dsa: mv88e6xxx: Add missing static to stub functions 2017-05-30 14:07:53 -04:00
ethernet net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
fddi format-security: move static strings to const 2017-05-08 17:15:14 -07:00
fjes
hamradio net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
hippi Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-05-09 15:42:31 -07:00
hyperv netvsc: make sure napi enabled before vmbus_open 2017-05-04 11:08:36 -04:00
ieee802154 ieee802154: don't select COMMON_CLK 2017-04-22 10:28:40 +02:00
ipvlan net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
irda Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-05-15 15:50:49 -07:00
phy net: phy: fix kernel-doc warnings 2017-06-05 11:28:50 -04:00
plip
ppp
slip net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
team net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
usb net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
vmxnet3 vmxnet3: ensure that adapter is in proper state during force_close 2017-05-12 12:23:52 -04:00
wan net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
wimax drivers: net: wimax: i2400m: i2400m-usb: Use time_after for time comparison 2017-05-09 09:40:33 -04:00
wireless net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
xen-netback
dummy.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
eql.c
geneve.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
gtp.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
ifb.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
Kconfig VSOCK: Add vsockmon device 2017-04-24 12:35:56 -04:00
LICENSE.SRC
loopback.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
macsec.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
macvlan.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
macvtap.c
Makefile VSOCK: Add vsockmon device 2017-04-24 12:35:56 -04:00
mdio.c
mii.c
netconsole.c
nlmon.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
ntb_netdev.c
rionet.c
sb1000.c
Space.c
sungem_phy.c
tap.c
tun.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
veth.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
virtio_net.c virtio_net: lower limit on buffer size 2017-06-02 14:32:34 -04:00
vrf.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
vsockmon.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
vxlan.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
xen-netfront.c xen-netfront: avoid crashing on resume after a failure in talk_to_netback() 2017-05-11 21:38:50 -04:00