Sashiko reports that the following race is possible while dismantling
the flowtable with hardware offload:
CPU0 CPU1 (kworker)
nf_tables_commit()
list_del_rcu(&flowtable->list)
nft_unregister_flowtable_net_hooks()
nf_tables_commit_release()
schedule_work(&destroy_work)
mutex_unlock(&commit_mutex)
nf_tables_trans_destroy_work()
synchronize_rcu()
...
unregister_netdevice()
nf_tables_flowtable_event()
/* flowtable not in
* table->flowtables, ops->dev
* stays on flowtable->hook_list
*/
free_netdev(dev)
nf_tables_flowtable_destroy()
nft_flowtable_hooks_destroy()
...
flowtable->data.type->setup(
..., ops->dev,
FLOW_BLOCK_UNBIND)
<-- use-after-free
A netdevice event could happen in between the commit and commit_release.
After commit, the flowtable has been removed from the table list,
therefore, it is not reachable by the flowtable netdevice handler so the
hook cannot be unregistered and a stale reference to the netdevice
remains in place, leading to possible UaF from the commit_release path
when accessing the netdevice.
Fix this by flushing the pending destroy work before handling netdevice
events.
Signed-off-by: Pablo Neira Ayuso <pab…@netfilter.org>
---
net/netfilter/nf_tables_api.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 0189375e4063..9ea8789f5664 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -9929,6 +9929,8 @@ static int nf_tables_flowtable_event(struct notifier_block *this,
nft_net = nft_pernet(net);
mutex_lock(&nft_net->commit_mutex);
+ nf_tables_trans_destroy_flush_work(net);
+
if (event == NETDEV_CHANGENAME) {
if (__nf_tables_flowtable_event(NETDEV_REGISTER, dev, true)) {
ret = NOTIFY_BAD;
--
2.47.3