]> asedeno.scripts.mit.edu Git - linux.git/commit
netfilter: nf_tables: close race between netns exit and rmmod
authorFlorian Westphal <fw@strlen.de>
Mon, 11 Jun 2018 11:20:36 +0000 (13:20 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 12 Jun 2018 17:28:18 +0000 (19:28 +0200)
commit0a2cf5ee432c2e8718af3553a56a3760d767b736
tree2d1f23b1be2546c3b5ee5511f74e469123f40b65
parent71ad00c50d77e507138c792a9646b53c16f22e11
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>
net/netfilter/nf_tables_api.c
net/netfilter/nft_chain_filter.c