From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Cc: "Claude Opus 4.6 (1M context)" <noreply@anthropic.com>
Subject: Re: [PATCH 2/4] fs: tftp: fix OACK option parsing bounds check
Date: Fri, 17 Apr 2026 11:28:08 +0200 [thread overview]
Message-ID: <92b29190-41a5-4cbf-9ec8-2bdc1fe5ea81@pengutronix.de> (raw)
In-Reply-To: <20260402-net-tftp-buffer-overflows-v1-2-0a18aa8ea19e@pengutronix.de>
On 4/2/26 9:21 AM, Sascha Hauer wrote:
> The bounds check in tftp_parse_oack() uses 'val > s + len' to detect
> when the value pointer exceeds the packet. Since 's' advances through
> the buffer while 'len' stays constant, 's + len' always points past
> 'pkt + len', making the check always false — it is dead code.
>
> The forced null at pkt[len - 1] provides partial protection, but when
> the last option key ends exactly at pkt[len - 1], val equals pkt + len
> and the subsequent strlen(val) reads past the packet boundary into
> uninitialized packet buffer data.
>
> Fix by checking 'val >= pkt + len' instead, which correctly bounds val
> against the actual end of the packet data. Using >= because when val
> equals pkt + len there is no room for a value string.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> fs/tftp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/tftp.c b/fs/tftp.c
> index 1b15bc18e7..03e9d552aa 100644
> --- a/fs/tftp.c
> +++ b/fs/tftp.c
> @@ -370,7 +370,7 @@ static int tftp_parse_oack(struct file_priv *priv, unsigned char *pkt, int len)
> while (s < pkt + len) {
> opt = s;
> val = s + strlen(s) + 1;
> - if (val > s + len)
> + if (val >= pkt + len)
> break;
> if (!strcmp(opt, "tsize"))
> priv->filesize = simple_strtoull(val, NULL, 10);
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2026-04-17 9:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 7:21 [PATCH 0/4] tftp: fix buffer overflows Sascha Hauer
2026-04-02 7:21 ` [PATCH 1/4] fs: tftp: prevent packet buffer overflow from long filenames Sascha Hauer
2026-04-17 9:14 ` Ahmad Fatoum
2026-04-02 7:21 ` [PATCH 2/4] fs: tftp: fix OACK option parsing bounds check Sascha Hauer
2026-04-17 9:28 ` Ahmad Fatoum [this message]
2026-04-02 7:21 ` [PATCH 3/4] fs: tftp: reject OACK with blocksize of zero Sascha Hauer
2026-04-17 9:32 ` Ahmad Fatoum
2026-04-02 7:21 ` [PATCH 4/4] fs: tftp: use bounded format for TFTP error message debug print Sascha Hauer
2026-04-17 9:42 ` Ahmad Fatoum
2026-04-17 10:40 ` [PATCH 0/4] tftp: fix buffer overflows Sascha Hauer
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=92b29190-41a5-4cbf-9ec8-2bdc1fe5ea81@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=noreply@anthropic.com \
--cc=s.hauer@pengutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox