[PATCH] tcp: release sk_frag.page in tcp_disconnect

Subsystems: networking [general], networking [tcp], the rest

STALE3121d

2 messages, 2 authors, 2018-01-29 · open the first message on its own page

[PATCH] tcp: release sk_frag.page in tcp_disconnect

From: Li RongQing <hidden>
Date: 2018-01-26 08:40:55

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 <redacted>
Cc: Eric Dumazet <edumazet@google.com>
---
 net/ipv4/tcp.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index f08eebe60446..73f068406519 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2431,6 +2431,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;
 }
-- 
2.11.0

Re: [PATCH] tcp: release sk_frag.page in tcp_disconnect

From: David Miller <davem@davemloft.net>
Date: 2018-01-29 22:57:38

From: Li RongQing <redacted>
Date: Fri, 26 Jan 2018 16:40:41 +0800
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 <redacted>
Cc: Eric Dumazet <edumazet@google.com>
Applied and queued up for -stable, thank you.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help