]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
l2tp: initialise session's refcount before making it reachable
authorGuillaume Nault <g.nault@alphalink.fr>
Fri, 25 Aug 2017 14:22:17 +0000 (16:22 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Aug 2017 18:28:33 +0000 (11:28 -0700)
Sessions must be fully initialised before calling
l2tp_session_add_to_tunnel(). Otherwise, there's a short time frame
where partially initialised sessions can be accessed by external users.

Fixes: dbdbc73b4478 ("l2tp: fix duplicate session creation")
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/l2tp/l2tp_core.c

index b0c2d4ae781d2114cdb09269d27768f0632a1776..f363669eae47a668e0f234a884e03fb0c7d17d25 100644 (file)
@@ -1844,6 +1844,8 @@ struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunn
 
                l2tp_session_set_header_len(session, tunnel->version);
 
+               refcount_set(&session->ref_count, 1);
+
                err = l2tp_session_add_to_tunnel(tunnel, session);
                if (err) {
                        kfree(session);
@@ -1851,10 +1853,6 @@ struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunn
                        return ERR_PTR(err);
                }
 
-               /* Bump the reference count. The session context is deleted
-                * only when this drops to zero.
-                */
-               refcount_set(&session->ref_count, 1);
                l2tp_tunnel_inc_refcount(tunnel);
 
                /* Ensure tunnel socket isn't deleted */