l2tp: ensure sessions are freed after their PPPOL2TP socket
authorGuillaume Nault <g.nault@alphalink.fr>
Fri, 22 Sep 2017 13:39:23 +0000 (15:39 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 13 Feb 2018 18:32:11 +0000 (18:32 +0000)
commit7823d6b02eb19708df5d1171006dcfc4e892530d
tree54e51791acddc91be1576a174f323032f49c81cd
parent4c563277c65bf9849ecbeb451cef15bc510a1968
l2tp: ensure sessions are freed after their PPPOL2TP socket

commit cdd10c9627496ad25c87ce6394e29752253c69d3 upstream.

If l2tp_tunnel_delete() or l2tp_tunnel_closeall() deletes a session
right after pppol2tp_release() orphaned its socket, then the 'sock'
variable of the pppol2tp_session_close() callback is NULL. Yet the
session is still used by pppol2tp_release().

Therefore we need to take an extra reference in any case, to prevent
l2tp_tunnel_delete() or l2tp_tunnel_closeall() from freeing the session.

Since the pppol2tp_session_close() callback is only set if the session
is associated to a PPPOL2TP socket and that both l2tp_tunnel_delete()
and l2tp_tunnel_closeall() hold the PPPOL2TP socket before calling
pppol2tp_session_close(), we're sure that pppol2tp_session_close() and
pppol2tp_session_destruct() are paired and called in the right order.
So the reference taken by the former will be released by the later.

Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
net/l2tp/l2tp_ppp.c