Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5884138pxv; Thu, 29 Jul 2021 00:26:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrf702kYXTVwMBeflDbORquxSQqDhJ6R53wCqq7zjkFI5ByFnP3u1XGuz6jHBuCBfuu87n X-Received: by 2002:a02:c95a:: with SMTP id u26mr3352348jao.49.1627543585042; Thu, 29 Jul 2021 00:26:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627543585; cv=none; d=google.com; s=arc-20160816; b=YY18iAgBQZyKeNvhaJGBfe0ZYBHJcRC2a1w5tXDO0GO5UhD/g6Ns/+2pakXwlgYza8 gO+fWVUnZ0Tf8FWD4SLhYyvktBEYAzaJUVW4nVvPhYQCvuTFBA8dyLC8y84WlKGJZf1l DBeWo1nTZwUAd/IBFJbVwDFNb/rCg6zB07Z/CdaTXh7u9qPG3/2SjrbGmmCfaUU8W/kZ 85NAjfIwuOG+GZK7Y2Wt7T34IIfLrTor+Jb8W5cX5izjLOdP2xcfNymV+sQjCmkVwDaa h3NtF18f+E57tzzBdjrsMi1B48lJjjJgazOqORuAQy0HfuATHWM9uQHr4/t30J8EgTpO mqgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=zFCR/bUNAhlTidzxAQSCw/rrrzbhYYFc8pVIgy4vMk4=; b=CfuXiYSP0oLFnXbuSNUbhHfVLHX6aQ+FYjudv80tByzBm64Kt6FXwihDfBmosdMvfR +6ejI2cXfEaa9VjB8F6Sg0ELLStAMfarGE4kU92BiDUNjSxdm6KMxsritp3N/5qtsft0 Qw6n12PqrayOZmf8UxAfo71fPTLS+naJkapsqM0UExfZlYNMUadAq9xSC1BeAVZtBzx0 bzhCL36C0/x/1hB1clNr+OiwmaumS4cF6cTGrPU1U+psTG1I9UCTVucHjnDbGMrwBF8V Norv0ftLoE92/eP8qCUTcRBK0KimmfSTAaw1FX6ton0xqnmQhDc3YhLExRZaTqfsRcwi /06g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d3si2310876ilm.133.2021.07.29.00.26.13; Thu, 29 Jul 2021 00:26:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234724AbhG2HYc (ORCPT + 99 others); Thu, 29 Jul 2021 03:24:32 -0400 Received: from mail.netfilter.org ([217.70.188.207]:40442 "EHLO mail.netfilter.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234634AbhG2HYc (ORCPT ); Thu, 29 Jul 2021 03:24:32 -0400 Received: from netfilter.org (bl11-146-165.dsl.telepac.pt [85.244.146.165]) by mail.netfilter.org (Postfix) with ESMTPSA id E8DA86411D; Thu, 29 Jul 2021 09:23:56 +0200 (CEST) Date: Thu, 29 Jul 2021 09:24:20 +0200 From: Pablo Neira Ayuso To: yajun.deng@linux.dev Cc: kadlec@netfilter.org, fw@strlen.de, roopa@nvidia.com, nikolay@nvidia.com, davem@davemloft.net, kuba@kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, bridge@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] netfilter: nf_conntrack_bridge: Fix not free when error Message-ID: <20210729072420.GA16265@salvia> References: <20210728161849.GA10433@salvia> <20210726035702.11964-1-yajun.deng@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 29, 2021 at 03:19:01AM +0000, yajun.deng@linux.dev wrote: > July 29, 2021 12:18 AM, "Pablo Neira Ayuso" wrote: > > > On Mon, Jul 26, 2021 at 11:57:02AM +0800, Yajun Deng wrote: > > > >> It should be added kfree_skb_list() when err is not equal to zero > >> in nf_br_ip_fragment(). > >> > >> Fixes: 3c171f496ef5 ("netfilter: bridge: add connection tracking system") > >> Signed-off-by: Yajun Deng > >> --- > >> net/bridge/netfilter/nf_conntrack_bridge.c | 12 ++++++++---- > >> 1 file changed, 8 insertions(+), 4 deletions(-) > >> > >> diff --git a/net/bridge/netfilter/nf_conntrack_bridge.c > >> b/net/bridge/netfilter/nf_conntrack_bridge.c > >> index 8d033a75a766..059f53903eda 100644 > >> --- a/net/bridge/netfilter/nf_conntrack_bridge.c > >> +++ b/net/bridge/netfilter/nf_conntrack_bridge.c > >> @@ -83,12 +83,16 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk, > >> > >> skb->tstamp = tstamp; > >> err = output(net, sk, data, skb); > >> - if (err || !iter.frag) > >> - break; > >> - > >> + if (err) { > >> + kfree_skb_list(iter.frag); > >> + return err; > >> + } > >> + > >> + if (!iter.frag) > >> + return 0; > >> + > >> skb = ip_fraglist_next(&iter); > >> } > >> - return err; > > > > Why removing this line above? It enters slow_path: on success. > > > I used return rather than break, it wouldn't enter the slow_path. Right, your patch is correct. > > This patch instead will keep this aligned with IPv6. > > > I think err and !iter.frag are not related, there is no need to put > them in an if statement, We still need to separate them after loop. > So I separate them in loop and use return instead of break. In > addition, if you insist, I will accept your patch. Thanks. Yes, I'd prefer to keep it consistent with existing users of the fragment iterator, see: net/ipv4/ip_output.c net/ipv6/netfilter.c net/ipv6/ip6_output.c they are roughly using the same programming idiom to iterate over the fragments. Would you send a v2?