l2tp: initialise l2tp_eth sessions before registering them
authorGuillaume Nault <g.nault@alphalink.fr>
Fri, 27 Oct 2017 14:51:51 +0000 (16:51 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sun, 29 Oct 2017 02:16:22 +0000 (11:16 +0900)
commitee28de6bbd78c2e18111a0aef43ea746f28d2073
tree133ee7dfb02cc14e42b9a88043d0ab26d2059513
parent3953ae7b218df4d1e544b98a393666f9ae58a78c
l2tp: initialise l2tp_eth sessions before registering them

Sessions must be initialised before being made externally visible by
l2tp_session_register(). Otherwise the session may be concurrently
deleted before being initialised, which can confuse the deletion path
and eventually lead to kernel oops.

Therefore, we need to move l2tp_session_register() down in
l2tp_eth_create(), but also handle the intermediate step where only the
session or the netdevice has been registered.

We can't just call l2tp_session_register() in ->ndo_init() because
we'd have no way to properly undo this operation in ->ndo_uninit().
Instead, let's register the session and the netdevice in two different
steps and protect the session's device pointer with RCU.

And now that we allow the session's .dev field to be NULL, we don't
need to prevent the netdevice from being removed anymore. So we can
drop the dev_hold() and dev_put() calls in l2tp_eth_create() and
l2tp_eth_dev_uninit().

Fixes: d9e31d17ceba ("l2tp: Add L2TP ethernet pseudowire support")
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/l2tp/l2tp_eth.c