netfilter: nf_tables: fix updating/deleting devices in an existing netdev chain
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: nf_tables: fix updating/deleting devices in an existing netdev chain
Updating netdev basechain is broken in many ways.
Keeping a list of pending hooks to be added/deleted in the transaction object does not mix well with table flag updates (ie. setting dormant flag in table) which operate on the existing basechain hook list. Instead, add/delete hook to/from the basechain hook list and allocate one transaction object per new device to refers to the hook to add/delete.
Add an 'inactive' flag that is set on to identify devices that has been already deleted, so double deletion in one batch is not possible.
For chain updates, several transaction objects are allocated: one or more for the new devices, and another one for policy/stats/name updates.
Moreover, skip hook unregistration if table is in dormant state. Otherwise, commit/abort path try to unregister hooks which are enabled, triggering a WARN_ON splat from the netfilter hook core. Delete hook object from basechain hook list through rcu variant, then release it after rcu grace period.
And dumping the list of hook basechain requires RCU list iteration.
This also fixes a memleak of chain stats in case the error path is exercised and remove useless basechain hook ops pointer fetch when updating devices in chain.
--- include/net/netfilter/nf_tables.h | 7 +- net/netfilter/nf_tables_api.c | 164 +++++++++++++++++++----------- 2 files changed, 106 insertions(+), 65 deletions(-)
include/net/netfilter/nf_tables.h +4 -3
@@ -1169,6 +1169,7 @@ struct nft_hook {struct list_head list;struct nf_hook_ops ops;struct rcu_head rcu; +bool inactive; };/**
@@ -1656,7 +1657,7 @@ struct nft_trans_chain {bool bound;u32 chain_id;struct nft_base_chain *basechain; -struct list_head hook_list; +struct nft_hook *hook; };#define nft_trans_chain (trans) \
@@ -1675,8 +1676,8 @@ struct nft_trans_chain { (((struct nft_trans_chain *)trans->data)->chain_id)#define nft_trans_basechain (trans) \ (((struct nft_trans_chain *)trans->data)->basechain) -#define nft_trans_chain_hooks (trans) \ - (((struct nft_trans_chain *)trans->data)->hook_list) +#define nft_trans_chain_hook (trans) \ + (((struct nft_trans_chain *)trans->data)->hook)struct nft_trans_table {bool update;
net/netfilter/nf_tables_api.c +102 -62
308 lines not on this page · raw message
Signature · 1 line
2.30.2
Florian Westphal
maintainerQuoted 11 lines · Pablo Neira Ayuso
Updating netdev basechain is broken in many ways.
Keeping a list of pending hooks to be added/deleted in the transaction object does not mix well with table flag updates (ie. setting dormant flag in table) which operate on the existing basechain hook list. Instead, add/delete hook to/from the basechain hook list and allocate one transaction object per new device to refers to the hook to add/delete.
Add an 'inactive' flag that is set on to identify devices that has been already deleted, so double deletion in one batch is not possible.
Do you think it makes sense to remove dormant flag support for the netdev family?
It would avoid the register/unregister entanglements and might reduce headaches down the road.
IOW, do you think dormant flag toggling is useful for netdev family?
Pablo Neira Ayuso
maintainerQuoted 13 lines · Florian Westphal
Quoted 11 lines · Pablo Neira Ayuso
Updating netdev basechain is broken in many ways.
Keeping a list of pending hooks to be added/deleted in the transaction object does not mix well with table flag updates (ie. setting dormant flag in table) which operate on the existing basechain hook list. Instead, add/delete hook to/from the basechain hook list and allocate one transaction object per new device to refers to the hook to add/delete.
Add an 'inactive' flag that is set on to identify devices that has been already deleted, so double deletion in one batch is not possible.
Quoted 7 lines
Do you think it makes sense to remove dormant flag support for the netdev family?
It would avoid the register/unregister entanglements and might reduce headaches down the road.
IOW, do you think dormant flag toggling is useful for netdev family?
I would disable it for the netdev family, yes.
Pablo Neira Ayuso
maintainerQuoted 17 lines · Pablo Neira Ayuso
Quoted 16 lines · Florian Westphal
Quoted 11 lines · Pablo Neira Ayuso
Updating netdev basechain is broken in many ways.
Keeping a list of pending hooks to be added/deleted in the transaction object does not mix well with table flag updates (ie. setting dormant flag in table) which operate on the existing basechain hook list. Instead, add/delete hook to/from the basechain hook list and allocate one transaction object per new device to refers to the hook to add/delete.
Add an 'inactive' flag that is set on to identify devices that has been already deleted, so double deletion in one batch is not possible.
Do you think it makes sense to remove dormant flag support for the netdev family?
Quoted 6 lines
Quoted 4 lines
It would avoid the register/unregister entanglements and might reduce headaches down the road.
IOW, do you think dormant flag toggling is useful for netdev family?
I would disable it for the netdev family, yes.
As a side note, the flowtable already does not support for the dormant flag.