Skip to content

Commit

Permalink
netfilter: nf_tables: validate NFTA_SET_ELEM_OBJREF based on NFT_SET_…
Browse files Browse the repository at this point in the history
…OBJECT flag

commit 5a2f3dc upstream.

If the NFTA_SET_ELEM_OBJREF netlink attribute is present and
NFT_SET_OBJECT flag is set on, report EINVAL.

Move existing sanity check earlier to validate that NFT_SET_OBJECT
requires NFTA_SET_ELEM_OBJREF.

Fixes: 8aeff92 ("netfilter: nf_tables: add stateful object reference to set elements")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
ummakynes authored and gregkh committed Aug 25, 2022
1 parent f4fbfbc commit 3ccd3c8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions net/netfilter/nf_tables_api.c
Expand Up @@ -5848,6 +5848,15 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
return -EINVAL;
}

if (set->flags & NFT_SET_OBJECT) {
if (!nla[NFTA_SET_ELEM_OBJREF] &&
!(flags & NFT_SET_ELEM_INTERVAL_END))
return -EINVAL;
} else {
if (nla[NFTA_SET_ELEM_OBJREF])
return -EINVAL;
}

if ((flags & NFT_SET_ELEM_INTERVAL_END) &&
(nla[NFTA_SET_ELEM_DATA] ||
nla[NFTA_SET_ELEM_OBJREF] ||
Expand Down Expand Up @@ -5986,10 +5995,6 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
}

if (nla[NFTA_SET_ELEM_OBJREF] != NULL) {
if (!(set->flags & NFT_SET_OBJECT)) {
err = -EINVAL;
goto err_parse_key_end;
}
obj = nft_obj_lookup(ctx->net, ctx->table,
nla[NFTA_SET_ELEM_OBJREF],
set->objtype, genmask);
Expand Down

0 comments on commit 3ccd3c8

Please sign in to comment.