Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2547453pxb; Mon, 19 Apr 2021 08:10:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9x6CVkfQMtVDTdXYvGBbCcl3/wRY70sIidoxaEk9bbYQO1M2ITq/qweooWNGj8aOtzhpp X-Received: by 2002:a17:902:6504:b029:ec:9f20:344f with SMTP id b4-20020a1709026504b02900ec9f20344fmr7940183plk.34.1618845031828; Mon, 19 Apr 2021 08:10:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618845031; cv=none; d=google.com; s=arc-20160816; b=quwnCNPCPKgTEXGz7LMYqFcMDVoPBW3ZDpLh1M0re/apn7YFkUmkTmyEjUM/2vkzNU PtRLNPVc922N5/c4HxAX7pc0wrAUxwBGdlnBC69lEQipq0WQjbFIz07TvsU3mtFo3haW iGgLoOgGotWImj/e699pFaR5voqKIYhqkvbZgl0p5/OAbXFB3+QnUsu5/tpe1/q7FUrk 71gJUC7Vr5z8dHIugw8qS6QuxTebNf//8TlyC0g5476hMuarw6msT0CQ3G5rEfpjTXPo k0XkFe3CAwBw8D6Mktq7SX8gi7xEGgWZ2+HOnInDAaF6NqMkjnQPK2guAuNkiZZ9fgtQ C1aQ== 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=CQqfn0IaGGL4SsxNgUyoqYsQjWdxjl3d4ovodY2GJuQ=; b=ohuEl7Ta0NqKVtnCg0Nl3jeH8OEiUb4bWzRDSu33KEq6spTfkmpA2ptY0dnV2GKAW3 2pw8qUNblfqVTxZKZMv2kXCboCjX15mbR3XgsOukJNza6ftIWMbMLaS8wMOIXNbwUyKk jJEXmZgoy5Wo0UDxGHznwoMFePnUB/ulpZl/VeZTpNrgceQk/H05790L79b6IS/iVU+C HnoOnlr4gakwCERqFYxo3+ZeFh4ZvatV28gRa74oHFzAaicRYTirv0YZxzgIb0Cbvfx5 LoYuYnQs8tLEywOwI/YGGOkDDvDamePvcrYFOtNqra8DZ5qwf1Z2nSyTcMhV2gGnevVG SwJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qDjIfat7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f7si20996843pgk.522.2021.04.19.08.10.19; Mon, 19 Apr 2021 08:10:31 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qDjIfat7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240237AbhDSNNS (ORCPT + 99 others); Mon, 19 Apr 2021 09:13:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:47128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239710AbhDSNLQ (ORCPT ); Mon, 19 Apr 2021 09:11:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0A44F61288; Mon, 19 Apr 2021 13:10:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618837846; bh=Lbk80MNig+UIuRJUxCC3+Dw+4iJ7T+KUui0Vdx35Osg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qDjIfat7Y/BWc3QaCLBF+lVzfSmsKCEX8E7Qn4ko2ldYQ62CtQ9diIrYBjTXjLbv/ 5p//nJi8NLS+YOaiTFgI8a9ozCDhlDfz0aQYP7RLVY8rFpYzQdBjlB49OozPRswPch 0oNAcD045vjM/45QjjLVyCkgOq3moiyfu+JOm8Ak= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Westphal , Pablo Neira Ayuso Subject: [PATCH 5.11 076/122] netfilter: arp_tables: add pre_exit hook for table unregister Date: Mon, 19 Apr 2021 15:05:56 +0200 Message-Id: <20210419130532.757166072@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130530.166331793@linuxfoundation.org> References: <20210419130530.166331793@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Florian Westphal commit d163a925ebbc6eb5b562b0f1d72c7e817aa75c40 upstream. Same problem that also existed in iptables/ip(6)tables, when arptable_filter is removed there is no longer a wait period before the table/ruleset is free'd. Unregister the hook in pre_exit, then remove the table in the exit function. This used to work correctly because the old nf_hook_unregister API did unconditional synchronize_net. The per-net hook unregister function uses call_rcu instead. Fixes: b9e69e127397 ("netfilter: xtables: don't hook tables by default") Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- include/linux/netfilter_arp/arp_tables.h | 5 +++-- net/ipv4/netfilter/arp_tables.c | 9 +++++++-- net/ipv4/netfilter/arptable_filter.c | 10 +++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) --- a/include/linux/netfilter_arp/arp_tables.h +++ b/include/linux/netfilter_arp/arp_tables.h @@ -52,8 +52,9 @@ extern void *arpt_alloc_initial_table(co int arpt_register_table(struct net *net, const struct xt_table *table, const struct arpt_replace *repl, const struct nf_hook_ops *ops, struct xt_table **res); -void arpt_unregister_table(struct net *net, struct xt_table *table, - const struct nf_hook_ops *ops); +void arpt_unregister_table(struct net *net, struct xt_table *table); +void arpt_unregister_table_pre_exit(struct net *net, struct xt_table *table, + const struct nf_hook_ops *ops); extern unsigned int arpt_do_table(struct sk_buff *skb, const struct nf_hook_state *state, struct xt_table *table); --- a/net/ipv4/netfilter/arp_tables.c +++ b/net/ipv4/netfilter/arp_tables.c @@ -1541,10 +1541,15 @@ out_free: return ret; } -void arpt_unregister_table(struct net *net, struct xt_table *table, - const struct nf_hook_ops *ops) +void arpt_unregister_table_pre_exit(struct net *net, struct xt_table *table, + const struct nf_hook_ops *ops) { nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks)); +} +EXPORT_SYMBOL(arpt_unregister_table_pre_exit); + +void arpt_unregister_table(struct net *net, struct xt_table *table) +{ __arpt_unregister_table(net, table); } --- a/net/ipv4/netfilter/arptable_filter.c +++ b/net/ipv4/netfilter/arptable_filter.c @@ -56,16 +56,24 @@ static int __net_init arptable_filter_ta return err; } +static void __net_exit arptable_filter_net_pre_exit(struct net *net) +{ + if (net->ipv4.arptable_filter) + arpt_unregister_table_pre_exit(net, net->ipv4.arptable_filter, + arpfilter_ops); +} + static void __net_exit arptable_filter_net_exit(struct net *net) { if (!net->ipv4.arptable_filter) return; - arpt_unregister_table(net, net->ipv4.arptable_filter, arpfilter_ops); + arpt_unregister_table(net, net->ipv4.arptable_filter); net->ipv4.arptable_filter = NULL; } static struct pernet_operations arptable_filter_net_ops = { .exit = arptable_filter_net_exit, + .pre_exit = arptable_filter_net_pre_exit, }; static int __init arptable_filter_init(void)