Commit 9ee369a4 authored by Guillaume Nault's avatar Guillaume Nault Committed by David S. Miller

l2tp: initialise session's refcount before making it reachable

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: dbdbc73b ("l2tp: fix duplicate session creation")
Signed-off-by: default avatarGuillaume Nault <g.nault@alphalink.fr>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4c228682
...@@ -1844,6 +1844,8 @@ struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunn ...@@ -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); l2tp_session_set_header_len(session, tunnel->version);
refcount_set(&session->ref_count, 1);
err = l2tp_session_add_to_tunnel(tunnel, session); err = l2tp_session_add_to_tunnel(tunnel, session);
if (err) { if (err) {
kfree(session); kfree(session);
...@@ -1851,10 +1853,6 @@ struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunn ...@@ -1851,10 +1853,6 @@ struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunn
return ERR_PTR(err); 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); l2tp_tunnel_inc_refcount(tunnel);
/* Ensure tunnel socket isn't deleted */ /* Ensure tunnel socket isn't deleted */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment