• Guillaume Nault's avatar
    l2tp: initialise l2tp_eth sessions before registering them · ee28de6b
    Guillaume Nault authored
    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: d9e31d17 ("l2tp: Add L2TP ethernet pseudowire support")
    Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    ee28de6b
l2tp_eth.c 9.42 KB