tcp: fix a request socket leak
authorEric Dumazet <edumazet@google.com>
Fri, 8 Sep 2017 19:44:47 +0000 (12:44 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 8 Sep 2017 23:07:17 +0000 (16:07 -0700)
While the cited commit fixed a possible deadlock, it added a leak
of the request socket, since reqsk_put() must be called if the BPF
filter decided the ACK packet must be dropped.

Fixes: d624d276d1dd ("tcp: fix possible deadlock in TCP stack vs BPF filter")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/tcp_ipv4.c
net/ipv6/tcp_ipv6.c

index a63486a..d9416b5 100644 (file)
@@ -1669,9 +1669,9 @@ process:
                 */
                sock_hold(sk);
                refcounted = true;
-               if (tcp_filter(sk, skb))
-                       goto discard_and_relse;
-               nsk = tcp_check_req(sk, skb, req, false);
+               nsk = NULL;
+               if (!tcp_filter(sk, skb))
+                       nsk = tcp_check_req(sk, skb, req, false);
                if (!nsk) {
                        reqsk_put(req);
                        goto discard_and_relse;
index 38f76d8..64d94af 100644 (file)
@@ -1460,9 +1460,9 @@ process:
                }
                sock_hold(sk);
                refcounted = true;
-               if (tcp_filter(sk, skb))
-                       goto discard_and_relse;
-               nsk = tcp_check_req(sk, skb, req, false);
+               nsk = NULL;
+               if (!tcp_filter(sk, skb))
+                       nsk = tcp_check_req(sk, skb, req, false);
                if (!nsk) {
                        reqsk_put(req);
                        goto discard_and_relse;