netfilter: nf_tables: release flowtable after rcu grace period on error
Subsystems (2)
PATCH 1/1 netfilter: nf_tables: release flowtable after rcu grace period on error
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit d73f4b53aaaea4c95f245e491aa5eeb8a21874ce ]
Call synchronize_rcu() after unregistering the hooks from error path, since a hook that already refers to this flowtable can be already registered, exposing this flowtable to packet path and nfnetlink_hook control plane.
This error path is rare, it should only happen by reaching the maximum number hooks or by failing to set up to hardware offload, just call synchronize_rcu().
There is a check for already used device hooks by different flowtable that could result in EEXIST at this late stage. The hook parser can be updated to perform this check earlier to this error path really becomes rarely exercised.
Uncovered by KASAN reported as use-after-free from nfnetlink_hook path when dumping hooks.
[ Backport to 5.10.y: 5.10 registers the flowtable hooks before the
transaction is allocated and has no err_flowtable_hooks label. As in the 5.15.y backport of this fix, call synchronize_rcu() in the nft_register_flowtable_net_hooks() failure branch, before the hooks and the flowtable are released. ]
---
Not a clean cherry-pick (see the bracketed note): resolved the same way as the 5.15.y backport already in the stable queue -- synchronize_rcu() in the nft_register_flowtable_net_hooks() failure branch.
Build-tested on arm64; boot-tested under QEMU with KASAN: flowtable create/delete and the failure path run without KASAN reports.
net/netfilter/nf_tables_api.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nf_tables_api.c +1 -0
@@ -7296,6 +7296,7 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk, &flowtable->hook_list, flowtable);if (err <0 ) { +synchronize_rcu ();nft_flowtable_hooks_destroy (&flowtable->hook_list); goto err4; }
Signature · 1 line
2.50.1 (Apple Git-155)
Quoted 4 lines
Call
synchronize_rcu()after unregistering the hooks from error path, since a hook that already refers to this flowtable can be already registered, exposing this flowtable to packet path andnfnetlink_hookcontrol plane.
Queued for 5.10, thanks.
Signature · 2 lines
Thanks, Sasha