From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-co1nam03on0127.outbound.protection.outlook.com ([104.47.40.127]:41117 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032381AbeCAPeA (ORCPT ); Thu, 1 Mar 2018 10:34:00 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Li RongQing , "David S . Miller" , Sasha Levin Subject: [added to the 4.1 stable tree] tcp: release sk_frag.page in tcp_disconnect Date: Thu, 1 Mar 2018 15:25:53 +0000 Message-ID: <20180301152116.1486-312-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Li RongQing This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ 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 Cc: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/tcp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 6c9c147a5fff..94a4b28e5da6 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2235,6 +2235,12 @@ int tcp_disconnect(struct sock *sk, int flags) =20 WARN_ON(inet->inet_num && !icsk->icsk_bind_hash); =20 + if (sk->sk_frag.page) { + put_page(sk->sk_frag.page); + sk->sk_frag.page =3D NULL; + sk->sk_frag.offset =3D 0; + } + sk->sk_error_report(sk); return err; } --=20 2.14.1