OSDN Git Service

l2tp: hold socket before dropping lock in l2tp_ip{, 6}_recv()
authorGuillaume Nault <g.nault@alphalink.fr>
Tue, 29 Nov 2016 12:09:45 +0000 (13:09 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 10 Nov 2018 15:41:38 +0000 (07:41 -0800)
[ Upstream commit a3c18422a4b4e108bcf6a2328f48867e1003fd95 ]

Socket must be held while under the protection of the l2tp lock; there
is no guarantee that sk remains valid after the read_unlock_bh() call.

Same issue for l2tp_ip and l2tp_ip6.

Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/l2tp/l2tp_ip.c
net/l2tp/l2tp_ip6.c

index 48ab938..c7e6098 100644 (file)
@@ -184,14 +184,15 @@ pass_up:
 
                read_lock_bh(&l2tp_ip_lock);
                sk = __l2tp_ip_bind_lookup(net, iph->daddr, 0, tunnel_id);
+               if (!sk) {
+                       read_unlock_bh(&l2tp_ip_lock);
+                       goto discard;
+               }
+
+               sock_hold(sk);
                read_unlock_bh(&l2tp_ip_lock);
        }
 
-       if (sk == NULL)
-               goto discard;
-
-       sock_hold(sk);
-
        if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
                goto discard_put;
 
index bcdab1c..5fe0a6f 100644 (file)
@@ -196,14 +196,15 @@ pass_up:
                read_lock_bh(&l2tp_ip6_lock);
                sk = __l2tp_ip6_bind_lookup(&init_net, &iph->daddr,
                                            0, tunnel_id);
+               if (!sk) {
+                       read_unlock_bh(&l2tp_ip6_lock);
+                       goto discard;
+               }
+
+               sock_hold(sk);
                read_unlock_bh(&l2tp_ip6_lock);
        }
 
-       if (sk == NULL)
-               goto discard;
-
-       sock_hold(sk);
-
        if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
                goto discard_put;