All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [nft] mnl: catch bogus expressions before crashing
Date: Thu, 12 Jun 2025 00:50:12 +0200	[thread overview]
Message-ID: <aEoIJIGoTF4abPtd@calendula> (raw)
In-Reply-To: <20250605222039.31719-1-fw@strlen.de>

On Fri, Jun 06, 2025 at 12:20:28AM +0200, Florian Westphal wrote:
> We can't recover from errors here, but we can abort with a more
> precise reason than 'segmentation fault', or stack corruptions
> that get caught way later, or not at all.
> 
> expr->value is going to be read, we can't cope with other expression
> types here.
> 
> We will copy to stack buffer of IFNAMSIZ size, abort if we would
> overflow.
> 
> Check there is a NUL byte present too.
> This is a preemptive patch, I've seen one crash in this area but
> no reproducer yet.

I don't see how this can happen yet, but I like this sanity checks.

> Signed-off-by: Florian Westphal <fw@strlen.de>

Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>

> ---
>  src/mnl.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/src/mnl.c b/src/mnl.c
> index 64b1aaedb84c..6565341fa6e3 100644
> --- a/src/mnl.c
> +++ b/src/mnl.c
> @@ -732,9 +732,20 @@ static void nft_dev_add(struct nft_dev *dev_array, const struct expr *expr, int
>  	unsigned int ifname_len;
>  	char ifname[IFNAMSIZ];
>  
> +	if (expr->etype != EXPR_VALUE)
> +		BUG("Must be a value, not %s\n", expr_name(expr));
> +
>  	ifname_len = div_round_up(expr->len, BITS_PER_BYTE);
>  	memset(ifname, 0, sizeof(ifname));
> +
> +	if (ifname_len > sizeof(ifname))
> +		BUG("Interface length %u exceeds limit\n", ifname_len);
> +
>  	mpz_export_data(ifname, expr->value, BYTEORDER_HOST_ENDIAN, ifname_len);
> +
> +	if (strnlen(ifname, IFNAMSIZ) >= IFNAMSIZ)
> +		BUG("Interface length %zu exceeds limit, no NUL byte\n", strnlen(ifname, IFNAMSIZ));
> +
>  	dev_array[i].ifname = xstrdup(ifname);
>  	dev_array[i].location = &expr->location;
>  }
> -- 
> 2.49.0
> 
> 

      reply	other threads:[~2025-06-11 22:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-05 22:20 [nft] mnl: catch bogus expressions before crashing Florian Westphal
2025-06-11 22:50 ` Pablo Neira Ayuso [this message]

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=aEoIJIGoTF4abPtd@calendula \
    --to=pablo@netfilter.org \
    --cc=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.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.