linux-hardened/net/mac802154
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
..
cfg.c nl802154: add support for security layer 2015-09-30 13:16:44 +02:00
cfg.h mac802154: introduce mac802154_config_ops 2014-11-02 04:51:06 +01:00
driver-ops.h mac802154: tx: fix synced xmit deadlock 2015-12-10 19:17:11 +01:00
ieee802154_i.h drivers: add explicit interrupt.h includes 2017-03-30 11:05:34 -07:00
iface.c net: Fix inconsistent teardown and release of private netdev state. 2017-06-07 15:53:24 -04:00
Kconfig mac802154: select CRYPTO when needed 2015-05-19 19:35:48 +02:00
llsec.c sched/headers: Prepare to use <linux/rcuupdate.h> instead of <linux/rculist.h> in <linux/sched.h> 2017-03-02 08:42:38 +01:00
llsec.h mac802154: Use skcipher 2016-01-27 20:36:05 +08:00
mac_cmd.c mac802154: constify ieee802154_llsec_ops structure 2016-01-04 20:40:41 +01:00
main.c mac802154: Fixes kernel oops when unloading a radio driver 2016-02-23 20:29:40 +01:00
Makefile Makefile: drop -D__CHECK_ENDIAN__ from cflags 2016-12-16 00:13:43 +02:00
mib.c mac802154: remove mib lock 2015-05-23 17:57:08 +02:00
rx.c mac802154: use rate limited warnings for malformed frames 2016-09-19 20:19:34 +02:00
trace.c mac802154: add trace functionality for driver ops 2015-06-02 19:21:09 +02:00
trace.h mac802154: add trace functionality for driver ops 2015-06-02 19:21:09 +02:00
tx.c mac802154: tx: fix synced xmit deadlock 2015-12-10 19:17:11 +01:00
util.c ktime: Cleanup ktime_set() usage 2016-12-25 17:21:22 +01:00