Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2574801pxb; Mon, 19 Apr 2021 08:45:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrqLU4DuxT84BqHnOOxg3aiJQ9+94Q/Ajd8UgMceFCk0+MAjikE0MZ4+K382yEizEfepWi X-Received: by 2002:aa7:cd83:: with SMTP id x3mr26100026edv.373.1618847100602; Mon, 19 Apr 2021 08:45:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618847100; cv=none; d=google.com; s=arc-20160816; b=ru8bvo8QsurgjU7TcqyrZC4oa+k8EGXiPRSy98e3LlwK/URQzEnTFS7rHtF7dyed1S 4Pl8hp3murhItmf1jJwIgaXkCqzGr2tF5VfrsuSrF8GdgTZwyTEHZbJF26zNAWjAl1s1 1Tfnaf8OeBVm1jY0YRzBDz78GtQRpzQiIYvG+2tg1oj54nnJMn88iMS4bdWQ1VNmoh1n DLNBu2xiUa7rBUVcIPi+JR/m++nV2DBcG6WdYWgYcp4uzC25LnGoRJpisz+bFxw8/vE7 TRTqlxZwixnn5+/nNQJPGSca4DeNjkHP30o7a9mytNOs5jzSUvyxoCUFEmywzafxpZt6 EohQ== 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=T9p2dWgicqGgzRgOD94RvmWCIcShFVHFvaODZlQC/sMmMwTE0oxV1dug1kcP81WqJN LNs5HZ03kht3BYnHMFkTVmzK+gsmeEk0wLpxoHuChV42B97JL2TlrT3l4L/7kTgp8q7U wjxxW3G6VU2G63aCqo+Eb+F2+uq6a+hZEsKlY8WNnMnXRj0WdGDw9QtP8PrnOEQu3qtn nhjzMzvlMZLsT27e+SqTaXFZ+vLzXABvtR3/dFqZkCZZnpY+/mKyW4EZGS7WPsxQD9mF oloZt2U9AiGnF2/b5q09ZxhzP4NI74pumloOMKVUU8t3itnP3MTdE5I2/s+VXL+bHy6r gQVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zVjk7rHe; 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 re25si11660569ejb.425.2021.04.19.08.44.37; Mon, 19 Apr 2021 08:45:00 -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=zVjk7rHe; 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 S241918AbhDSN0b (ORCPT + 99 others); Mon, 19 Apr 2021 09:26:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:55076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241221AbhDSNUO (ORCPT ); Mon, 19 Apr 2021 09:20:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 794F061279; Mon, 19 Apr 2021 13:15:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618838158; bh=Lbk80MNig+UIuRJUxCC3+Dw+4iJ7T+KUui0Vdx35Osg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zVjk7rHeeMOlgTFMn/Z2hB6fecWyy6WoXXRCiJvRF2VDDBhzTxZP5mGoKtt3PV1mH RjQsA3c3Q5mGmxl6jotPdpO+UafT4VMSLAgxiEdZ1ryWoTrdya+QjXCeTW/ufZ2/Er 36L5u+3Sfx7Tod5HqDrbav9FU0gUby/CKxs0qUeU= 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.10 063/103] netfilter: arp_tables: add pre_exit hook for table unregister Date: Mon, 19 Apr 2021 15:06:14 +0200 Message-Id: <20210419130529.975113676@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130527.791982064@linuxfoundation.org> References: <20210419130527.791982064@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)