Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp579656iog; Mon, 13 Jun 2022 08:30:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v0NgWCDPRSrPE+UOedyYXTSe1pa/XBmij59C8GS/kZKEnZgdMbWM3S2SJzhbTiB0qwHeTY X-Received: by 2002:a17:903:120b:b0:168:98a9:221f with SMTP id l11-20020a170903120b00b0016898a9221fmr364287plh.48.1655134249309; Mon, 13 Jun 2022 08:30:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134249; cv=none; d=google.com; s=arc-20160816; b=PGru0KUfI2XpUAKn3CutjhnFTItAaWPwMeJ7gEJPENS4kVHqtg0J13sAa15nZ8exUa inMWEnF0HYbw48H8nqhPJtbEtTgR246W2veJns8WQaKJY7b4xCRdWFGw7ik+x3OXKwA2 5x6O2ZlngFRt1aWO4Xfsb60glcVO+ah/pSsxAqK9p2sVJ5GPsgTYoAn8QzLOPx3FdRtk LVFkZmn7q4LzzaGKxJpGTXP7Zg7HE+klc03aVVIMmlTMff4DIG1VNvursvBmr1jE47ol u0lS+wfRvewDnxy37UGInkK27sjYIWN8i1ifyEHJhWICThcAJzMnTqRcY5IhD3/mN0xG DZqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GpzYiUva5pb05g4LYjwgxdNAF2QuawwHkKZhua89Vqs=; b=bX2f/sai1Jbbx0XiVGN/TzBf2PSoWKJIizPFc6p26WKqaWYYq/vPWmEUgCGsD3X32q T9zzPnAiJi/JQbIfNkoY7oqmgTNwYOvR2Nwq6/D83afkkSLrrrQdAKeVvDffS6/IAw9F Rh5MzWUePVOiwiKdcME0gfIk0hTubF/6T95+t7ooSPFiaaX3EbNAFQjmLWlfbbkY9vbE L8WlOViqw72sy6AtxvRBYjnslxZtbLfwZKijPB9q8O4kbFiguXl/t/RzOvJh5aZLjVsG MIRjc+a5TvvKYZQSG43IqwnVr9PYxA0cPPkzmTwrxhpMRtWt7DaybygS2pB7RN/a0LZD 7Yog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Hc5kjFjG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r4-20020a63e504000000b003fe26a09fe1si9929414pgh.477.2022.06.13.08.30.36; Mon, 13 Jun 2022 08:30:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Hc5kjFjG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359644AbiFMNQP (ORCPT + 99 others); Mon, 13 Jun 2022 09:16:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359265AbiFMNJp (ORCPT ); Mon, 13 Jun 2022 09:09:45 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CEE62228B; Mon, 13 Jun 2022 04:19:47 -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 sin.source.kernel.org (Postfix) with ESMTPS id CCCCDCE1171; Mon, 13 Jun 2022 11:19:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3F0FC3411F; Mon, 13 Jun 2022 11:19:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655119184; bh=nhelgjtfwercjsWb3CXAIGQG0vmigIT3Yb/l51/AOec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hc5kjFjGdOcRyp7qP7VhR4IMK477EKaMVQB2cgYikbIxKxcgai+cJBd5P74F24uco bbJyGXQxunTgYX9eeQqqZNaDb7f72eWK8C4naMi/BWedgzcg5LFtZDE5Eo8eUNOf7H 2h8O5uE/+AMV3KSWHHkA4mUPfC246fPQODnBzH70= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.15 134/247] netfilter: nf_tables: delete flowtable hooks via transaction list Date: Mon, 13 Jun 2022 12:10:36 +0200 Message-Id: <20220613094927.023405347@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pablo Neira Ayuso [ Upstream commit b6d9014a3335194590abdd2a2471ef5147a67645 ] Remove inactive bool field in nft_hook object that was introduced in abadb2f865d7 ("netfilter: nf_tables: delete devices from flowtable"). Move stale flowtable hooks to transaction list instead. Deleting twice the same device does not result in ENOENT. Fixes: abadb2f865d7 ("netfilter: nf_tables: delete devices from flowtable") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- include/net/netfilter/nf_tables.h | 1 - net/netfilter/nf_tables_api.c | 31 ++++++------------------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h index d52a5d776e76..2af1c2c64128 100644 --- a/include/net/netfilter/nf_tables.h +++ b/include/net/netfilter/nf_tables.h @@ -1053,7 +1053,6 @@ struct nft_stats { struct nft_hook { struct list_head list; - bool inactive; struct nf_hook_ops ops; struct rcu_head rcu; }; diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 5833fe17be43..b19974073156 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -1835,7 +1835,6 @@ static struct nft_hook *nft_netdev_hook_alloc(struct net *net, goto err_hook_dev; } hook->ops.dev = dev; - hook->inactive = false; return hook; @@ -7517,6 +7516,7 @@ static int nft_delflowtable_hook(struct nft_ctx *ctx, { const struct nlattr * const *nla = ctx->nla; struct nft_flowtable_hook flowtable_hook; + LIST_HEAD(flowtable_del_list); struct nft_hook *this, *hook; struct nft_trans *trans; int err; @@ -7532,7 +7532,7 @@ static int nft_delflowtable_hook(struct nft_ctx *ctx, err = -ENOENT; goto err_flowtable_del_hook; } - hook->inactive = true; + list_move(&hook->list, &flowtable_del_list); } trans = nft_trans_alloc(ctx, NFT_MSG_DELFLOWTABLE, @@ -7545,6 +7545,7 @@ static int nft_delflowtable_hook(struct nft_ctx *ctx, nft_trans_flowtable(trans) = flowtable; nft_trans_flowtable_update(trans) = true; INIT_LIST_HEAD(&nft_trans_flowtable_hooks(trans)); + list_splice(&flowtable_del_list, &nft_trans_flowtable_hooks(trans)); nft_flowtable_hook_release(&flowtable_hook); nft_trans_commit_list_add_tail(ctx->net, trans); @@ -7552,13 +7553,7 @@ static int nft_delflowtable_hook(struct nft_ctx *ctx, return 0; err_flowtable_del_hook: - list_for_each_entry(this, &flowtable_hook.list, list) { - hook = nft_hook_list_find(&flowtable->hook_list, this); - if (!hook) - break; - - hook->inactive = false; - } + list_splice(&flowtable_del_list, &flowtable->hook_list); nft_flowtable_hook_release(&flowtable_hook); return err; @@ -8413,17 +8408,6 @@ void nft_chain_del(struct nft_chain *chain) list_del_rcu(&chain->list); } -static void nft_flowtable_hooks_del(struct nft_flowtable *flowtable, - struct list_head *hook_list) -{ - struct nft_hook *hook, *next; - - list_for_each_entry_safe(hook, next, &flowtable->hook_list, list) { - if (hook->inactive) - list_move(&hook->list, hook_list); - } -} - static void nf_tables_module_autoload_cleanup(struct net *net) { struct nftables_pernet *nft_net = nft_pernet(net); @@ -8768,8 +8752,6 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb) break; case NFT_MSG_DELFLOWTABLE: if (nft_trans_flowtable_update(trans)) { - nft_flowtable_hooks_del(nft_trans_flowtable(trans), - &nft_trans_flowtable_hooks(trans)); nf_tables_flowtable_notify(&trans->ctx, nft_trans_flowtable(trans), &nft_trans_flowtable_hooks(trans), @@ -8850,7 +8832,6 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action) struct nftables_pernet *nft_net = nft_pernet(net); struct nft_trans *trans, *next; struct nft_trans_elem *te; - struct nft_hook *hook; if (action == NFNL_ABORT_VALIDATE && nf_tables_validate(net) < 0) @@ -8981,8 +8962,8 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action) break; case NFT_MSG_DELFLOWTABLE: if (nft_trans_flowtable_update(trans)) { - list_for_each_entry(hook, &nft_trans_flowtable(trans)->hook_list, list) - hook->inactive = false; + list_splice(&nft_trans_flowtable_hooks(trans), + &nft_trans_flowtable(trans)->hook_list); } else { trans->ctx.table->use++; nft_clear(trans->ctx.net, nft_trans_flowtable(trans)); -- 2.35.1