]> rtime.felk.cvut.cz Git - zynq/linux.git/commitdiff
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)
committerDavid S. Miller <davem@davemloft.net>
Wed, 30 Nov 2016 19:14:07 +0000 (14:14 -0500)
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>
net/l2tp/l2tp_ip.c
net/l2tp/l2tp_ip6.c

index 1f57094d31116d5f6dc6a411c577e6087a3abf46..4d1c942cc91bd4db577e945a88a01ffab72386b6 100644 (file)
@@ -183,14 +183,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 af9abfff637ce21a9d51149700310dd47b9def0a..e3fc7786f188d51d555eb9c340008134e6ca9800 100644 (file)
@@ -198,14 +198,15 @@ pass_up:
                read_lock_bh(&l2tp_ip6_lock);
                sk = __l2tp_ip6_bind_lookup(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;