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 91188C636D3 for ; Fri, 10 Feb 2023 10:33:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232060AbjBJKdF (ORCPT ); Fri, 10 Feb 2023 05:33:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232009AbjBJKdE (ORCPT ); Fri, 10 Feb 2023 05:33:04 -0500 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:237:300::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F3F86D609; Fri, 10 Feb 2023 02:33:00 -0800 (PST) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1pQQi2-0005P7-M8; Fri, 10 Feb 2023 11:32:50 +0100 Date: Fri, 10 Feb 2023 11:32:50 +0100 From: Florian Westphal To: Hangyu Hua Cc: pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] net: netfilter: fix possible refcount leak in ctnetlink_create_conntrack() Message-ID: <20230210103250.GC17303@breakpoint.cc> References: <20230210071730.21525-1-hbh25y@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230210071730.21525-1-hbh25y@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hangyu Hua wrote: > nf_ct_put() needs to be called to put the refcount got by > nf_conntrack_find_get() to avoid refcount leak when > nf_conntrack_hash_check_insert() fails. > > Fixes: 7d367e06688d ("netfilter: ctnetlink: fix soft lockup when netlink adds new entries (v2)") > Signed-off-by: Hangyu Hua > --- > net/netfilter/nf_conntrack_netlink.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c > index 1286ae7d4609..ca4d5bb1ea52 100644 > --- a/net/netfilter/nf_conntrack_netlink.c > +++ b/net/netfilter/nf_conntrack_netlink.c > @@ -2375,12 +2375,15 @@ ctnetlink_create_conntrack(struct net *net, > > err = nf_conntrack_hash_check_insert(ct); > if (err < 0) > - goto err2; > + goto err3; Ouch, looks like this is broken in more than one way? nf_conntrack_hash_check_insert() can call nf_ct_kill() and return an error, in that case ct->master reference is already dropped for us. One way would be to return 0 in that case (in nf_conntrack_hash_check_insert()). What do you think?