All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Chen Yufeng <chenyufeng@iie.ac.cn>
Cc: pablo@netfilter.org, kadlec@netfilter.org,
	netfilter-devel@vger.kernel.org
Subject: Re: [PATCH] netfilter: Set expressions out of range in nft_add_set_elem()
Date: Mon, 8 Sep 2025 16:31:09 +0200	[thread overview]
Message-ID: <aL7orb8efT7px8NB@strlen.de> (raw)
In-Reply-To: <20250908140844.1197-1-chenyufeng@iie.ac.cn>

Chen Yufeng <chenyufeng@iie.ac.cn> wrote:
> The number of `expr` expressions provided by userspace may exceed the 
> declared set expressions, potentially leading to errors or undefined behavior. 
> This patch addresses the issue by validating whether i exceeds 
> set->num_exprs.

Its already tested?
Please explain why this isn't enough and/or provide splat/backtrace.


                nla_for_each_nested(tmp, nla[NFTA_SET_ELEM_EXPRESSIONS], left) {
                        if (i == NFT_SET_EXPR_MAX ||
                            (set->num_exprs && set->num_exprs == i)) {
                                err = -E2BIG;
                                goto err_set_elem_expr;
                        }
                        if (nla_type(tmp) != NFTA_LIST_ELEM) {
                                err = -EINVAL;

> diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> index 58c5425d61c2..958a7c8b0b4c 100644
> --- a/net/netfilter/nf_tables_api.c
> +++ b/net/netfilter/nf_tables_api.c
> @@ -7338,9 +7338,15 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
>  			expr_array[i] = expr;
>  			num_exprs++;
>  
> -			if (set->num_exprs && expr->ops != set->exprs[i]->ops) {
> -				err = -EOPNOTSUPP;
> -				goto err_set_elem_expr;
> +			if (set->num_exprs) {
> +				if (i >= set->num_exprs) {
> +					err = -EINVAL;
> +					goto err_set_elem_expr;
> +				}

I don't see how we can hit the if (set->num_exprs && conditional with
i == set->num_exprs.

  reply	other threads:[~2025-09-08 14:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-08 14:08 [PATCH] netfilter: Set expressions out of range in nft_add_set_elem() Chen Yufeng
2025-09-08 14:31 ` Florian Westphal [this message]
2025-09-08 15:54 ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aL7orb8efT7px8NB@strlen.de \
    --to=fw@strlen.de \
    --cc=chenyufeng@iie.ac.cn \
    --cc=kadlec@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.