From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Dumazet Subject: Re: [PATCH] net: clean the sk_frag.page of new cloned socket Date: Thu, 25 Jan 2018 04:44:05 -0800 Message-ID: <1516884245.3715.48.camel@gmail.com> References: <1516882089-28575-1-git-send-email-lirongqing@baidu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: edumazet@google.com To: Li RongQing , netdev@vger.kernel.org Return-path: Received: from mail-io0-f195.google.com ([209.85.223.195]:39933 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751391AbeAYMoI (ORCPT ); Thu, 25 Jan 2018 07:44:08 -0500 Received: by mail-io0-f195.google.com with SMTP id b198so8507163iof.6 for ; Thu, 25 Jan 2018 04:44:08 -0800 (PST) In-Reply-To: <1516882089-28575-1-git-send-email-lirongqing@baidu.com> Sender: netdev-owner@vger.kernel.org List-ID: On Thu, 2018-01-25 at 20:08 +0800, Li RongQing wrote: > Clean the sk_frag.page of new cloned socket, otherwise it will release > twice wrongly since the reference count of this sk_frag page is not > increased. > > sk_clone_lock() is used to clone a new socket from sock which is in > listening state and has not sk_frag.page, but a socket has sent data > and can gets transformed back to a listening socket, will allocate an > tcp_sock through sk_clone_lock() when a new connection comes in. > > Signed-off-by: Li RongQing > Cc: Eric Dumazet > --- > net/core/sock.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/net/core/sock.c b/net/core/sock.c > index c0b5b2f17412..c845856f26da 100644 > --- a/net/core/sock.c > +++ b/net/core/sock.c > @@ -1738,6 +1738,8 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority) > sk_refcnt_debug_inc(newsk); > sk_set_socket(newsk, NULL); > newsk->sk_wq = NULL; > + newsk->sk_frag.page = NULL; > + newsk->sk_frag.offset = 0; > > if (newsk->sk_prot->sockets_allocated) > sk_sockets_allocated_inc(newsk); Good catch. I suspect this was discovered by some syzkaller/syzbot run ? I would rather move that in tcp_disconnect() that only fuzzers use, instead of doing this on every clone and slowing down normal users.