From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Cc: "Claude Opus 4.6 \(1M context\)" <noreply@anthropic.com>
Subject: [PATCH 4/4] fs: tftp: use bounded format for TFTP error message debug print
Date: Thu, 02 Apr 2026 09:21:22 +0200 [thread overview]
Message-ID: <20260402-net-tftp-buffer-overflows-v1-4-0a18aa8ea19e@pengutronix.de> (raw)
In-Reply-To: <20260402-net-tftp-buffer-overflows-v1-0-0a18aa8ea19e@pengutronix.de>
The pr_debug for TFTP_ERROR uses %s to print the server's error
message, but the message may not be null-terminated. This causes
pr_debug to read past the packet data into uninitialized buffer
memory.
Use %.*s with the remaining packet length to bound the read. This
is only relevant in debug builds but is still worth fixing for
correctness.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---
fs/tftp.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/tftp.c b/fs/tftp.c
index 6dd4829184..8f01754fc0 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -631,7 +631,9 @@ static void tftp_recv(struct file_priv *priv,
break;
case TFTP_ERROR:
- pr_debug("error: '%s' (%d)\n", pkt + 2, ntohs(*(uint16_t *)pkt));
+ pr_debug("error: '%.*s' (%d)\n",
+ len > 2 ? len - 2 : 0, pkt + 2,
+ ntohs(*(uint16_t *)pkt));
switch (ntohs(*(uint16_t *)pkt)) {
case 1:
priv->err = -ENOENT;
--
2.47.3
prev parent reply other threads:[~2026-04-02 7:21 UTC|newest]
Thread overview: 5+ 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-02 7:21 ` [PATCH 2/4] fs: tftp: fix OACK option parsing bounds check Sascha Hauer
2026-04-02 7:21 ` [PATCH 3/4] fs: tftp: reject OACK with blocksize of zero Sascha Hauer
2026-04-02 7:21 ` Sascha Hauer [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=20260402-net-tftp-buffer-overflows-v1-4-0a18aa8ea19e@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=noreply@anthropic.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox