netfilter: nf_tables: validate .maxattr at expression registration
authorPablo Neira Ayuso <pablo@netfilter.org>
Sat, 6 Jan 2024 22:52:02 +0000 (23:52 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 17 Jan 2024 11:02:46 +0000 (12:02 +0100)
struct nft_expr_info allows to store up to NFT_EXPR_MAXATTR (16)
attributes when parsing netlink attributes.

Rise a warning in case there is ever a nft expression whose .maxattr
goes beyond this number of expressions, in such case, struct nft_expr_info
needs to be updated.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nf_tables_api.c

index a90a364f5be5a8ae2f8a92bfa62fa6fff12e09bb..2548d7d56408cbfa77506a0d8d025171c1084c02 100644 (file)
@@ -2977,6 +2977,9 @@ static int nf_tables_delchain(struct sk_buff *skb, const struct nfnl_info *info,
  */
 int nft_register_expr(struct nft_expr_type *type)
 {
+       if (WARN_ON_ONCE(type->maxattr > NFT_EXPR_MAXATTR))
+               return -ENOMEM;
+
        nfnl_lock(NFNL_SUBSYS_NFTABLES);
        if (type->family == NFPROTO_UNSPEC)
                list_add_tail_rcu(&type->list, &nf_tables_expressions);