Skip to content

Commit d163a92

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: arp_tables: add pre_exit hook for table unregister
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: b9e69e1 ("netfilter: xtables: don't hook tables by default") Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 7ee3c61 commit d163a92

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

include/linux/netfilter_arp/arp_tables.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ extern void *arpt_alloc_initial_table(const struct xt_table *);
5252
int arpt_register_table(struct net *net, const struct xt_table *table,
5353
const struct arpt_replace *repl,
5454
const struct nf_hook_ops *ops, struct xt_table **res);
55-
void arpt_unregister_table(struct net *net, struct xt_table *table,
56-
const struct nf_hook_ops *ops);
55+
void arpt_unregister_table(struct net *net, struct xt_table *table);
56+
void arpt_unregister_table_pre_exit(struct net *net, struct xt_table *table,
57+
const struct nf_hook_ops *ops);
5758
extern unsigned int arpt_do_table(struct sk_buff *skb,
5859
const struct nf_hook_state *state,
5960
struct xt_table *table);

net/ipv4/netfilter/arp_tables.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,10 +1539,15 @@ int arpt_register_table(struct net *net,
15391539
return ret;
15401540
}
15411541

1542-
void arpt_unregister_table(struct net *net, struct xt_table *table,
1543-
const struct nf_hook_ops *ops)
1542+
void arpt_unregister_table_pre_exit(struct net *net, struct xt_table *table,
1543+
const struct nf_hook_ops *ops)
15441544
{
15451545
nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks));
1546+
}
1547+
EXPORT_SYMBOL(arpt_unregister_table_pre_exit);
1548+
1549+
void arpt_unregister_table(struct net *net, struct xt_table *table)
1550+
{
15461551
__arpt_unregister_table(net, table);
15471552
}
15481553

net/ipv4/netfilter/arptable_filter.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,24 @@ static int __net_init arptable_filter_table_init(struct net *net)
5656
return err;
5757
}
5858

59+
static void __net_exit arptable_filter_net_pre_exit(struct net *net)
60+
{
61+
if (net->ipv4.arptable_filter)
62+
arpt_unregister_table_pre_exit(net, net->ipv4.arptable_filter,
63+
arpfilter_ops);
64+
}
65+
5966
static void __net_exit arptable_filter_net_exit(struct net *net)
6067
{
6168
if (!net->ipv4.arptable_filter)
6269
return;
63-
arpt_unregister_table(net, net->ipv4.arptable_filter, arpfilter_ops);
70+
arpt_unregister_table(net, net->ipv4.arptable_filter);
6471
net->ipv4.arptable_filter = NULL;
6572
}
6673

6774
static struct pernet_operations arptable_filter_net_ops = {
6875
.exit = arptable_filter_net_exit,
76+
.pre_exit = arptable_filter_net_pre_exit,
6977
};
7078

7179
static int __init arptable_filter_init(void)

0 commit comments

Comments
 (0)