From: Sriram Sriram <sriramsriram@linux.microsoft.com>
To: u-boot@lists.u-boot-project.org
Cc: Tom Rini <trini@konsulko.com>,
Jerome Forissier <jerome.forissier@arm.com>,
Simon Glass <sjg@chromium.org>,
Drew Kluemke <ankluemk@microsoft.com>,
Daniel Munic <v-dmunic@microsoft.com>,
Sriram Sriram <sriramsriram@linux.microsoft.com>
Subject: [PATCH 3/4] net: tftp: use bounded string compare for OACK option parsing
Date: Wed, 9 Sep 2026 12:20:15 -0700 [thread overview]
Message-ID: <20260909192016.217183-4-sriramsriram@linux.microsoft.com> (raw)
In-Reply-To: <20260909192016.217183-1-sriramsriram@linux.microsoft.com>
From: Drew Kluemke <ankluemk@microsoft.com>
The TFTP OACK handler matches option names in the received packet with
strcasecmp(), which scans until a NUL byte. A malformed or truncated
OACK packet may not contain a NUL within the received length, causing
an out-of-bounds read past the packet buffer.
Replace each strcasecmp() with a strncasecmp() bounded to the option
name length plus an explicit check that the name is NUL-terminated at
the expected position. For the "windowsize" option, whose name and
value extend beyond the loop's "i + 8 < len" guard, add an explicit
"i + 11 < len" bound before the comparison.
Signed-off-by: Drew Kluemke <ankluemk@microsoft.com>
Signed-off-by: Sriram Sriram <sriramsriram@linux.microsoft.com>
---
net/tftp.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/net/tftp.c b/net/tftp.c
index beb9d08f5a2..35693e2a93e 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -544,7 +544,8 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
* something like "len-8" may give a *huge* number
*/
for (i = 0; i+8 < len; i++) {
- if (strcasecmp((char *)pkt + i, "blksize") == 0) {
+ if (!strncasecmp((char *)pkt + i, "blksize", 7) &&
+ pkt[i + 7] == '\0') {
tftp_block_size = (unsigned short)
dectoul((char *)pkt + i + 8, NULL);
debug("Blocksize oack: %s, %d\n",
@@ -555,7 +556,8 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
tftp_state = STATE_INVALID_OPTION;
}
}
- if (strcasecmp((char *)pkt + i, "timeout") == 0) {
+ if (!strncasecmp((char *)pkt + i, "timeout", 7) &&
+ pkt[i + 7] == '\0') {
timeout_val_rcvd = (unsigned short)
dectoul((char *)pkt + i + 8, NULL);
debug("Timeout oack: %s, %d\n",
@@ -567,14 +569,17 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
}
}
#ifdef CONFIG_TFTP_TSIZE
- if (strcasecmp((char *)pkt + i, "tsize") == 0) {
+ if (!strncasecmp((char *)pkt + i, "tsize", 5) &&
+ pkt[i + 5] == '\0') {
tftp_tsize = dectoul((char *)pkt + i + 6,
NULL);
debug("size = %s, %u\n",
(char *)pkt + i + 6, tftp_tsize);
}
#endif
- if (strcasecmp((char *)pkt + i, "windowsize") == 0) {
+ if (i + 11 < len &&
+ !strncasecmp((char *)pkt + i, "windowsize", 10) &&
+ pkt[i + 10] == '\0') {
tftp_windowsize =
dectoul((char *)pkt + i + 11, NULL);
debug("windowsize = %s, %d\n",
--
2.49.0
next prev parent reply other threads:[~2026-09-09 20:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 19:20 [PATCH 0/4] Bounds/overflow hardening in NFS, FIT, TFTP and ext4 Sriram Sriram
2026-09-09 19:20 ` [PATCH 1/4] net: nfs: add bounds checks on memcpy into stack-allocated rpc_pkt Sriram Sriram
2026-09-09 19:20 ` [PATCH 2/4] boot: image-fit: add overflow guard for FIT decompression buffer Sriram Sriram
2026-09-10 19:09 ` Tom Rini
2026-09-09 19:20 ` Sriram Sriram [this message]
2026-09-10 19:25 ` [PATCH 3/4] net: tftp: use bounded string compare for OACK option parsing Tom Rini
2026-09-09 19:20 ` [PATCH 4/4] fs: ext4: widen ext4fs_update() block-group loop counter Sriram Sriram
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=20260909192016.217183-4-sriramsriram@linux.microsoft.com \
--to=sriramsriram@linux.microsoft.com \
--cc=ankluemk@microsoft.com \
--cc=jerome.forissier@arm.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
--cc=v-dmunic@microsoft.com \
/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.