Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2678082pxb; Mon, 19 Apr 2021 11:03:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPdJrNNwRvvvYAGiA0Sfi6xcAUcALu7Za/iIllIf4U4ssYTi1FPrMNHW0Kp3KblhsigxqL X-Received: by 2002:aa7:d3d3:: with SMTP id o19mr10835396edr.282.1618855391680; Mon, 19 Apr 2021 11:03:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618855391; cv=none; d=google.com; s=arc-20160816; b=i8oL8f2FShsRMgdlh2QZzm6hNq/Pr3dWMbrO4a/l/2ERza0N3kbiZ0kp3j4sD8ZMO5 pD9MHCiOe4kQbMwqKa8QW+WDoMUvNMIhMC3hfOCzi6dCY/FamJOSx+MF3p9jyiNvFZhK p7bwtkf+z72tN31kjJ3T4mJr5L9esT5+m4awqJJK58JwQpGVV7gucbP9oYub/5/OanN6 inodtyIprmx6rlv9NBBaGqi7DZA5Si1ZHvEa3zsSHiHl+3LqPqR8CgQ9xJbqr42Lqqpa BOdHD8Scbk4ZE/vJyDxKhDjsbj8K9ujsrh1LgnYovDWum31e4zdBJrD7/pDq9JkN+fjx EqcQ== 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=ijSSw7zipEjQ7l1lpCiwwCw1tLQW1OT3ieAZkSj3Lbs=; b=t4U0P8Z2znglX4EIwFssygPhHISB9gUbjuL0H2KPR1/nV0OfJycKLlH/mZbACLeD7d LIBrS4aN62tWLfGTBlBZDv4oBkZDMDbBY6B0m7wjARFEFThqJljJVh3UbHU6xb4aGaQf I37Rs2rqKQMn28a2L6VUtYIAIDHrbxaJaSsXzNJS6lom2MOHQy8OBo/4AeOUAnAQHp8f dt87QZm5hAiGShIt92WuYKOah6fMg/EPpJ7E4a/YedIq5B+rBof+tf/i34z05dt5KjJB yHT0T7b/o1thX8kljBK4+j8v78OXDtdDlq5bvH+INtupXXr9dmDZ4PAp4ieiK080Z8R0 +YxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wyBWPOTS; 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 nd11si12635514ejc.470.2021.04.19.11.02.43; Mon, 19 Apr 2021 11:03:11 -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=wyBWPOTS; 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 S241561AbhDSNh0 (ORCPT + 99 others); Mon, 19 Apr 2021 09:37:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:34806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242038AbhDSNZN (ORCPT ); Mon, 19 Apr 2021 09:25:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A8B3B61362; Mon, 19 Apr 2021 13:20:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618838422; bh=1OarIeLCVES0OTSjS05sKAClCAnu8OAY2sXZi8tGmio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wyBWPOTSLiqB+njb4eDpzIyeHCS4Pw9JOONQ/djPRLGzZ7PsqkroqJFq0rOzpLBts mmjYK0Z+gd51n1TMCW+5IRejmDBrydxr4ZW6T9mCS23zXduEGHJ7zkfifXpheFzga9 fMPdv6PUMtmgbB8feyTjkYPA0/IARvHbnAdVEkGQ= 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.4 53/73] netfilter: arp_tables: add pre_exit hook for table unregister Date: Mon, 19 Apr 2021 15:06:44 +0200 Message-Id: <20210419130525.541101201@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130523.802169214@linuxfoundation.org> References: <20210419130523.802169214@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 @@ -1580,10 +1580,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)