]> git.hungrycats.org Git - linux/commitdiff
tcp: release sk_frag.page in tcp_disconnect
authorLi RongQing <lirongqing@baidu.com>
Fri, 26 Jan 2018 08:40:41 +0000 (16:40 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 12 Feb 2018 06:07:19 +0000 (07:07 +0100)
[ Upstream commit 9b42d55a66d388e4dd5550107df051a9637564fc ]

socket can be disconnected and gets transformed back to a listening
socket, if sk_frag.page is not released, which will be cloned into
a new socket by sk_clone_lock, but the reference count of this page
is increased, lead to a use after free or double free issue

Signed-off-by: Li RongQing <lirongqing@baidu.com>
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/ipv4/tcp.c

index 8e053ad7cae260c545b254e8164a1c4a0487db5e..c821f5d6872076e15f0d7a9183826e717036068f 100644 (file)
@@ -2434,6 +2434,12 @@ int tcp_disconnect(struct sock *sk, int flags)
 
        WARN_ON(inet->inet_num && !icsk->icsk_bind_hash);
 
+       if (sk->sk_frag.page) {
+               put_page(sk->sk_frag.page);
+               sk->sk_frag.page = NULL;
+               sk->sk_frag.offset = 0;
+       }
+
        sk->sk_error_report(sk);
        return err;
 }