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 2/2] net: dns: fix OOB read in dns_recv query type check
Date: Thu, 02 Apr 2026 10:25:10 +0200 [thread overview]
Message-ID: <20260402-net-dns-buffer-overflows-v1-2-30621fe8c6b7@pengutronix.de> (raw)
In-Reply-To: <20260402-net-dns-buffer-overflows-v1-0-30621fe8c6b7@pengutronix.de>
After skipping the query name in a DNS response, dns_recv() reads
p[1] and p[2] to check the query type BEFORE validating that these
offsets are within the packet bounds. The bounds check '&p[5] > e'
follows the reads, but by then the OOB access has already occurred.
If the query name's null terminator is at or near the end of the
packet, p[1] and p[2] read 1-2 bytes past the packet data.
Fix by moving the bounds check before the reads.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---
net/dns.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/net/dns.c b/net/dns.c
index fde1439469..5a3ee30720 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -166,8 +166,13 @@ static void dns_recv(struct header *header, unsigned len)
continue;
/* We sent query class 1, query type 1 */
+ if (&p[5] > e) {
+ pr_debug("DNS response too short\n");
+ return;
+ }
+
tmp = p[1] | (p[2] << 8);
- if (&p[5] > e || ntohs(tmp) != DNS_A_RECORD) {
+ if (ntohs(tmp) != DNS_A_RECORD) {
pr_debug("DNS response was not A record\n");
return;
}
--
2.47.3
prev parent reply other threads:[~2026-04-02 8:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 8:25 [PATCH 0/2] dns: Protect against too long hostnames and malicious packets Sascha Hauer
2026-04-02 8:25 ` [PATCH 1/2] net: dns: fix packet buffer overflow from long hostnames Sascha Hauer
2026-04-02 8:25 ` 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-dns-buffer-overflows-v1-2-30621fe8c6b7@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