All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: David Dull <monderasdor@gmail.com>
Cc: netfilter-devel@vger.kernel.org, fw@strlen.de
Subject: Re: [PATCH v2] netfilter: guard option walkers against 1-byte tail reads
Date: Sun, 8 Mar 2026 12:11:53 +0100	[thread overview]
Message-ID: <aa1ZeSRNg3HMo7JR@chamomile> (raw)
In-Reply-To: <20260307184553.1779-1-monderasdor@gmail.com>

On Sat, Mar 07, 2026 at 08:45:52PM +0200, David Dull wrote:
> When the last byte of options is a non-single-byte option kind, walkers
> that advance with i += op[i + 1] ? : 1 can read op[i + 1] past the end
> of the option area.
> 
> Add an explicit i == optlen - 1 check before dereferencing op[i + 1]
> in xt_tcpudp and xt_dccp option walkers.
> 
> Fixes: 2e4e6a17af35 ("[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables")
> Cc: fw@strlen.de
> Cc: stable@vger.kernel.org
> Signed-off-by: David Dull <monderasdor@gmail.com>
> ---
>  net/netfilter/xt_dccp.c   | 4 ++--
>  net/netfilter/xt_tcpudp.c | 6 ++++--
>  2 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/net/netfilter/xt_dccp.c b/net/netfilter/xt_dccp.c
> index e5a13ecbe6..037ab93e25 100644
> --- a/net/netfilter/xt_dccp.c
> +++ b/net/netfilter/xt_dccp.c
> @@ -62,10 +62,10 @@ dccp_find_option(u_int8_t option,
>  			return true;
>  		}
>  
> -		if (op[i] < 2)
> +		if (op[i] < 2 || i == optlen - 1)
>  			i++;
>  		else
> -			i += op[i+1]?:1;
> +			i += op[i + 1] ? : 1;
>  	}

To improve this area, I'd suggest:

		if (op[i] < 2) {
 			i++;
                        continue;
                }

                if (i + 1 >= optlen)
                        break;

		i += op[i + 1] ? : 1;
 	}

  reply	other threads:[~2026-03-08 11:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-07 18:26 [PATCH] netfilter: guard option walkers against 1-byte tail reads David Dull
2026-03-07 18:34 ` Florian Westphal
2026-03-07 18:45 ` [PATCH v2] " David Dull
2026-03-08 11:11   ` Pablo Neira Ayuso [this message]
2026-03-08 15:52   ` [PATCH v3] " David Dull
2026-03-08 17:05     ` 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=aa1ZeSRNg3HMo7JR@chamomile \
    --to=pablo@netfilter.org \
    --cc=fw@strlen.de \
    --cc=monderasdor@gmail.com \
    --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.