]> git.baikalelectronics.ru Git - kernel.git/commit
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)
commitb789a4619b240b42e50f38dbcf301d6d08925212
tree133ee7dfb02cc14e42b9a88043d0ab26d2059513
parente3a67800bb13ba24f3bef64620504e8ed00b99cf
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: 9911951a94eb ("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