From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A184EC54EE9 for ; Sun, 18 Sep 2022 15:30:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229593AbiIRPa1 (ORCPT ); Sun, 18 Sep 2022 11:30:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229579AbiIRPa0 (ORCPT ); Sun, 18 Sep 2022 11:30:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B7651AD92 for ; Sun, 18 Sep 2022 08:30:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 04B1FB81057 for ; Sun, 18 Sep 2022 15:30:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62464C433C1; Sun, 18 Sep 2022 15:30:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663515022; bh=EQ3FUZipllq04TfMzQSP7mtwHMu+ssXrH9a3NQtDCSo=; h=Date:Subject:To:References:From:In-Reply-To:From; b=LkJ+44f9dGLyXfS97f9qbK/ohyvU0eO3+0+u5Ixwi8eDTp1thp7mkHB/AEHdfCDs0 BYFsnugivhlG8bQYtNoRysF3IBN3+vp0k3o6ThMb680RfAVwcOpJGCLa0fkBrD0di5 EgstcPBQ9w523uqiydnDKr/7x6QwFEaWFZNeD8Go8T08E7+3xdXdS/MWpU3oPrynib oPfB/I1jDxlD3Fb7bUDD1IaaOKjqtnYtO4wufGAugzlCwQG/t5iuMuj6LYkmpUCVJA olLIHZwaeDpWzXhDCubbeydwpwe+elMm6Ea1oCOTY4ZOekS6BKiFyRfExjg6vznu1r jTy9PNSGrG0Tg== Message-ID: <69a43dc8-c545-1187-7185-4b85215b726d@kernel.org> Date: Sun, 18 Sep 2022 09:30:21 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH] ipv4: ping: Fix potential use-after-free bug Content-Language: en-US To: Liang He , davem@davemloft.net, yoshfuji@linux-ipv6.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org References: <20220916100727.4096852-1-windhl@126.com> From: David Ahern In-Reply-To: <20220916100727.4096852-1-windhl@126.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 9/16/22 4:07 AM, Liang He wrote: > In ping_unhash(), we should move sock_put(sk) after any possible > access point as the put function may free the object. unhash handlers are called from sk_common_release which still has a reference on the sock, so not really going to hit a UAF. I do agree that it does not read correctly to 'put' a reference then continue using the object. ie., the put should be moved to the end like you have here. This is more of a tidiness exercise than a need to backport to stable kernels. > > Fixes: c319b4d76b9e ("net: ipv4: add IPPROTO_ICMP socket kind") > Signed-off-by: Liang He > --- > > I have found other places containing similar code patterns. > > net/ipv4/ping.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c > index b83c2bd9d722..f90c86d37ffc 100644 > --- a/net/ipv4/ping.c > +++ b/net/ipv4/ping.c > @@ -157,10 +157,10 @@ void ping_unhash(struct sock *sk) > spin_lock(&ping_table.lock); > if (sk_hashed(sk)) { > hlist_nulls_del_init_rcu(&sk->sk_nulls_node); > - sock_put(sk); > isk->inet_num = 0; > isk->inet_sport = 0; > sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); > + sock_put(sk); > } > spin_unlock(&ping_table.lock); > }