mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
To: musl@lists.openwall.com
Cc: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
Subject: [musl] [PATCH v2] dns: check length field in tcp response message
Date: Wed, 22 Mar 2023 17:48:40 +0300	[thread overview]
Message-ID: <20230322144840.138539-1-aleksei.kodanev@bell-sw.com> (raw)

The received length field in the message may be greater than the
size of the 'answer' buffer in which the message resides. Currently,
ABUF_SIZE is 768. And if we get a larger 'alens[i]', it will result
in an out-of-bounds reading in __dns_parse().

To fix this, limit the length to the size of the received buffer.
---
v2: move the check to name_from_dns()

 src/network/lookup_name.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/network/lookup_name.c b/src/network/lookup_name.c
index 5f6867cb..e324f39d 100644
--- a/src/network/lookup_name.c
+++ b/src/network/lookup_name.c
@@ -179,6 +179,7 @@ static int name_from_dns(struct address buf[static MAXADDRS], char canon[static
 
 	for (i=nq-1; i>=0; i--) {
 		ctx.rrtype = qtypes[i];
+		if (alens[i] > sizeof(abuf[i])) alens[i] = sizeof(abuf[i]);
 		__dns_parse(abuf[i], alens[i], dns_parse_callback, &ctx);
 	}
 
-- 
2.25.1


                 reply	other threads:[~2023-03-22 14:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230322144840.138539-1-aleksei.kodanev@bell-sw.com \
    --to=aleksei.kodanev@bell-sw.com \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).