netfilter: nftables: fix possible UAF over chains from packet path in netns
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 2 Feb 2021 15:07:37 +0000 (16:07 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Feb 2021 10:02:25 +0000 (11:02 +0100)
commit0a0e5d47670b753d3dbf88f3c77a97a30864d9bd
tree1aab62ede58b58dc356e4ccb1359fad3fd05fab1
parentef8f281a653006e14b8d2999fe934e890e51e71b
netfilter: nftables: fix possible UAF over chains from packet path in netns

[ Upstream commit 767d1216bff82507c945e92fe719dff2083bb2f4 ]

Although hooks are released via call_rcu(), chain and rule objects are
immediately released while packets are still walking over these bits.

This patch adds the .pre_exit callback which is invoked before
synchronize_rcu() in the netns framework to stay safe.

Remove a comment which is not valid anymore since the core does not use
synchronize_net() anymore since 8c873e219970 ("netfilter: core: free
hooks with call_rcu").

Suggested-by: Florian Westphal <fw@strlen.de>
Fixes: df05ef874b28 ("netfilter: nf_tables: release objects on netns destruction")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/netfilter/nf_tables_api.c