aboutsummaryrefslogtreecommitdiffstats
path: root/net/netfilter/nft_chain_filter.c
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2018-06-11 13:20:36 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-06-12 19:28:18 +0200
commit0a2cf5ee432c2e8718af3553a56a3760d767b736 (patch)
tree2d1f23b1be2546c3b5ee5511f74e469123f40b65 /net/netfilter/nft_chain_filter.c
parentnetfilter: nf_tables: fix module unload race (diff)
downloadlinux-dev-0a2cf5ee432c2e8718af3553a56a3760d767b736.tar.xz
linux-dev-0a2cf5ee432c2e8718af3553a56a3760d767b736.zip
netfilter: nf_tables: close race between netns exit and rmmod
If net namespace is exiting while nf_tables module is being removed we can oops: BUG: unable to handle kernel NULL pointer dereference at 0000000000000040 IP: nf_tables_flowtable_event+0x43/0xf0 [nf_tables] PGD 0 P4D 0 Oops: 0000 [#1] SMP PTI Modules linked in: nf_tables(-) nfnetlink [..] unregister_netdevice_notifier+0xdd/0x130 nf_tables_module_exit+0x24/0x3a [nf_tables] SyS_delete_module+0x1c5/0x240 do_syscall_64+0x74/0x190 Avoid this by attempting to take reference on the net namespace from the notifiers. If it fails the namespace is exiting already, and nft core is taking care of cleanup work. We also need to make sure the netdev hook type gets removed before netns ops removal, else notifier might be invoked with device event for a netns where net->nft was never initialised (because pernet ops was removed beforehand). Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net/netfilter/nft_chain_filter.c')
-rw-r--r--net/netfilter/nft_chain_filter.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/net/netfilter/nft_chain_filter.c b/net/netfilter/nft_chain_filter.c
index 84c902477a91..d21834bed805 100644
--- a/net/netfilter/nft_chain_filter.c
+++ b/net/netfilter/nft_chain_filter.c
@@ -318,6 +318,10 @@ static int nf_tables_netdev_event(struct notifier_block *this,
event != NETDEV_CHANGENAME)
return NOTIFY_DONE;
+ ctx.net = maybe_get_net(ctx.net);
+ if (!ctx.net)
+ return NOTIFY_DONE;
+
nfnl_lock(NFNL_SUBSYS_NFTABLES);
list_for_each_entry(table, &ctx.net->nft.tables, list) {
if (table->family != NFPROTO_NETDEV)
@@ -334,6 +338,7 @@ static int nf_tables_netdev_event(struct notifier_block *this,
}
}
nfnl_unlock(NFNL_SUBSYS_NFTABLES);
+ put_net(ctx.net);
return NOTIFY_DONE;
}