Keyrings Archive mirror
 help / color / mirror / Atom feed
From: Shaomin Chen <eeesssooo020@gmail.com>
To: keyrings@vger.kernel.org
Cc: David Howells <dhowells@redhat.com>,
	Jarkko Sakkinen <jarkko@kernel.org>,
	Shaomin Chen <eeesssooo020@gmail.com>
Subject: [PATCH keyutils] dns: Limit AFSDB/SRV records to MAX_VLS
Date: Tue, 19 May 2026 00:44:35 +0800	[thread overview]
Message-ID: <20260518164435.3875488-1-eeesssooo020@gmail.com> (raw)

afsdb_hosts_to_addrs() and srv_hosts_to_addrs() store server names in
vllist[MAX_VLS], but iterate over all DNS answers without checking whether
vlsnum has reached MAX_VLS. A response with more than MAX_VLS usable records
can therefore write past the end of the array.

Ignore additional records once MAX_VLS entries have been collected.

Signed-off-by: Shaomin Chen <eeesssooo020@gmail.com>
---
 dns.afsdb.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/dns.afsdb.c b/dns.afsdb.c
index 986c0f3..983e7cd 100644
--- a/dns.afsdb.c
+++ b/dns.afsdb.c
@@ -61,6 +61,11 @@ static void afsdb_hosts_to_addrs(ns_msg handle, ns_sect section)
 
 		/* We're only interested in AFSDB records */
 		if (ns_rr_type(rr) == ns_t_afsdb) {
+			if (vlsnum >= MAX_VLS) {
+				debug("Too many AFSDB records, ignoring extra record");
+				continue;
+			}
+
 			vllist[vlsnum] = malloc(MAXDNAME);
 			if (!vllist[vlsnum])
 				error("Out of memory");
@@ -141,6 +146,11 @@ static void srv_hosts_to_addrs(ns_msg handle, ns_sect section)
 		}
 
 		if (ns_rr_type(rr) == ns_t_srv) {
+			if (vlsnum >= MAX_VLS) {
+				debug("Too many SRV records, ignoring extra record");
+				continue;
+			}
+
 			vllist[vlsnum] = malloc(MAXDNAME);
 			if (!vllist[vlsnum])
 				error("Out of memory");
-- 
2.47.3


                 reply	other threads:[~2026-05-18 16:44 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=20260518164435.3875488-1-eeesssooo020@gmail.com \
    --to=eeesssooo020@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=jarkko@kernel.org \
    --cc=keyrings@vger.kernel.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).