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)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 11 Nov 2017 13:34:33 +0000 (13:34 +0000)
commit 9ee369a405c57613d7c83a3967780c3e30c52ecc upstream.

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>
[bwh: Backported to 3.2: keep using l2tp_session_inc_refcount()]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
net/l2tp/l2tp_core.c

index 3954b18..8e74e69 100644 (file)
@@ -1715,6 +1715,8 @@ struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunn
 
                l2tp_session_set_header_len(session, tunnel->version);
 
+               l2tp_session_inc_refcount(session);
+
                err = l2tp_session_add_to_tunnel(tunnel, session);
                if (err) {
                        kfree(session);
@@ -1722,10 +1724,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.
-                */
-               l2tp_session_inc_refcount(session);
                l2tp_tunnel_inc_refcount(tunnel);
 
                /* Ensure tunnel socket isn't deleted */