netfilter: nf_tables: validate catch-all set elements
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v2 1/1 netfilter: nf_tables: validate catch-all set elements
catch-all set element might jump/goto to chain that uses expressions that require validation.
Fixes aaa31047a6d2 ("netfilter: nftables: add catch-all set element support")
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v2: pass nft_set_elem object to nft_setelem_validate()
include/net/netfilter/nf_tables.h | 4 ++ net/netfilter/nf_tables_api.c | 64 ++++++++++++++++++++++++++++--- net/netfilter/nft_lookup.c | 36 ++--------------- 3 files changed, 66 insertions(+), 38 deletions(-)
include/net/netfilter/nf_tables.h +4 -0
@@ -1085,6 +1085,10 @@ struct nft_chain { };int nft_chain_validate (const struct nft_ctx *ctx,const struct nft_chain *chain); +int nft_setelem_validate (const struct nft_ctx *ctx,struct nft_set *set, +const struct nft_set_iter *iter, +struct nft_set_elem *elem); +int nft_set_catchall_validate (const struct nft_ctx *ctx,struct nft_set *set);enum nft_chain_types {NFT_CHAIN_T_DEFAULT =0 ,
net/netfilter/nf_tables_api.c +58 -6
76 lines not on this page · raw message
net/netfilter/nft_lookup.c +4 -32
@@ -199,37 +199,6 @@ static int nft_lookup_dump(struct sk_buff *skb,return -1 ; } -static int nft_lookup_validate_setelem (const struct nft_ctx *ctx, -struct nft_set *set, -const struct nft_set_iter *iter, -struct nft_set_elem *elem) -{ -const struct nft_set_ext *ext =nft_set_elem_ext (set, elem->priv); -struct nft_ctx *pctx = (struct nft_ctx *)ctx; -const struct nft_data *data; -int err; - -if (nft_set_ext_exists (ext,NFT_SET_EXT_FLAGS ) && - *nft_set_ext_flags (ext) &NFT_SET_ELEM_INTERVAL_END ) -return 0 ; - - data =nft_set_ext_data (ext); -switch (data->verdict.code) { -case NFT_JUMP : -case NFT_GOTO : - pctx->level++; - err =nft_chain_validate (ctx, data->verdict.chain); -if (err <0 ) -return err; - pctx->level--; -break ; -default : -break ; - } - -return 0 ; -} -static int nft_lookup_validate (const struct nft_ctx *ctx,const struct nft_expr *expr,const struct nft_data **d)
@@ -245,9 +214,12 @@ static int nft_lookup_validate(const struct nft_ctx *ctx, iter.skip =0 ; iter.count =0 ; iter.err =0 ; - iter.fn = nft_lookup_validate_setelem; + iter.fn = nft_setelem_validate; priv->set->ops->walk (ctx, priv->set, &iter); +if (!iter.err) + iter.err =nft_set_catchall_validate (ctx, priv->set); +if (iter.err <0 )return iter.err;
Signature · 1 line
2.30.2