netfilter: nft_compat: run checkentry() from .validate
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: nft_compat: run checkentry() from .validate
Several matches and one target check that the hook is correct from checkentry(), however, the basechain is only available from nft_table_validate().
This patch calls checkentry() for matches and targets from the nft_compat expression .validate path for the following matches/target:
- addrtype
- devgroup
- physdev
- policy
- set
- TCPMSS
The xt_match .destroy indirection is also called to restore the xt_set refcounts that is performed by .checkentry. The remaining extensions provide no .destroy interface.
This patch sets the table in the nft_ctx struct in nft_table_validate() which is required by this patch.
The nft_compat_check_match() and nft_compat_check_target() helper functions are added to wrap common code used from .init and .validate path.
The protocol and inverse flags are set to always match from the expression .validate path, this is already checked from the init path.
---
A more self-contained alternative to Florian's:
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
net/netfilter/nf_tables_api.c | 1 + net/netfilter/nft_compat.c | 118 ++++++++++++++++++++++++++++------ 2 files changed, 100 insertions(+), 19 deletions(-)
net/netfilter/nf_tables_api.c +1 -0
@@ -4196,6 +4196,7 @@ static int nft_table_validate(struct net *net, const struct nft_table *table)struct nft_chain *chain;struct nft_ctx ctx = { .net = net, + .table = (struct nft_table *)table, .family = table->family, };int err =0 ;
net/netfilter/nft_compat.c +99 -19
188 lines not on this page · raw message
Signature · 1 line
2.47.3
Florian Westphal
maintainerQuoted 6 lines · Pablo Neira Ayuso
Several matches and one target check that the hook is correct from
checkentry(), however, the basechain is only available fromnft_table_validate().This patch calls
checkentry()for matches and targets from thenft_compatexpression .validate path for the following matches/target:
I worry that this is fragile. Not all ->checkentry callbacks are pure. Some create /proc entries or bump reference counts.
net/netfilter/nft_compat.c static int nft_target_validate(const struct nft_ctx *ctx, · line 401
Quoted 1 line
net/netfilter/nft_compat.c +1
-0+if (!strcmp (target->name,"TCPMSS" )) {
This is missing "SET".
Pablo Neira Ayuso
maintainerQuoted 10 lines · Florian Westphal
Quoted 6 lines · Pablo Neira Ayuso
Several matches and one target check that the hook is correct from
checkentry(), however, the basechain is only available fromnft_table_validate().This patch calls
checkentry()for matches and targets from thenft_compatexpression .validate path for the following matches/target:I worry that this is fragile. Not all ->checkentry callbacks are pure. Some create /proc entries or bump reference counts.
xt_set does bump the reference count. This calls xt.destroy to restore it. I am only calling them for the list of expression you mentioned.
Quoted 3 lines
net/netfilter/nft_compat.c static int nft_target_validate(const struct nft_ctx *ctx, · line 401
Quoted 1 line
net/netfilter/nft_compat.c +1
-0+if (!strcmp (target->name,"TCPMSS" )) {This is missing "SET".
I can add this.
Florian Westphal
maintainerQuoted 6 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal
Quoted 4 lines · Pablo Neira Ayuso
Several matches and one target check that the hook is correct from
checkentry(), however, the basechain is only available fromnft_table_validate().
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
This patch calls
checkentry()for matches and targets from thenft_compatexpression .validate path for the following matches/target:I worry that this is fragile. Not all ->checkentry callbacks are pure. Some create /proc entries or bump reference counts.
xt_setdoes bump the reference count. This calls xt.destroy to restore it. I am only calling them for the list of expression you mentioned.
I worry this will lead to trouble later, e.g. info->priv = kmalloc( ...) -> memory leak.
But OK, at least there is a test case in iptables.git for this.
Pablo Neira Ayuso
maintainerQuoted 10 lines · Florian Westphal
Quoted 9 lines · Pablo Neira Ayuso
Quoted 8 lines · Florian Westphal
Quoted 6 lines · Pablo Neira Ayuso
Several matches and one target check that the hook is correct from
checkentry(), however, the basechain is only available fromnft_table_validate().This patch calls
checkentry()for matches and targets from thenft_compatexpression .validate path for the following matches/target:
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I worry that this is fragile. Not all ->checkentry callbacks are pure. Some create /proc entries or bump reference counts.
xt_setdoes bump the reference count. This calls xt.destroy to restore it. I am only calling them for the list of expression you mentioned.I worry this will lead to trouble later, e.g.
info->priv= kmalloc( ...) -> memory leak.
If someone needs to cover for more extensions, they will have to update the list of extensions covered by the strcmp() check on the extension name.
Quoted 1 line
But OK, at least there is a test case in iptables.git for this.
Yes.
Your approach duplicates .checkentry in some way, you have to make sure what your .validate and .checkentry perform the same check, ie. they are in sync.
The approach proposed in this patch is not universal, because checkentry() is a place where many things happen as you suggested (/proc entries being registered, reference count being bumped,i kmalloc...).
If this needs to be generalized further, maybe checkentry() needs to extended to improve integration with nftables.
Florian Westphal
maintainerQuoted 3 lines · Pablo Neira Ayuso
Your approach duplicates .checkentry in some way, you have to make sure what your .validate and .checkentry perform the same check, ie. they are in sync.
Thats why I updated the affected .checkentry functions to use the validate functions internally -- to make sure the code is called even for classic iptables.
Quoted 2 lines
If this needs to be generalized further, maybe
checkentry()needs to extended to improve integration with nftables.
I hope not. But I don't care, if you prefer your patch then so be it.
I just find it sad we duplicate efforts all the time.
Pablo Neira Ayuso
maintainerQuoted 5 lines · Florian Westphal
Quoted 3 lines · Pablo Neira Ayuso
Your approach duplicates .checkentry in some way, you have to make sure what your .validate and .checkentry perform the same check, ie. they are in sync.
Quoted 8 lines
Thats why I updated the affected .checkentry functions to use the validate functions internally -- to make sure the code is called even for classic iptables.
Quoted 2 lines
If this needs to be generalized further, maybe
checkentry()needs to extended to improve integration with nftables.I hope not. But I don't care, if you prefer your patch then so be it.
I can toss this patch if you prefer, I will post it complete then decide what to do.
Quoted 1 line
I just find it sad we duplicate efforts all the time.
I thought I could provide a more self-contained approach for this nft_compat specific bug.