All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gdhcp: fix stack buffer overflow in get_domains()
@ 2026-10-23  8:53 Andrei Miu
  2026-10-23 10:54 ` Greg KH
  2026-12-04  6:47 ` [PATCH] gdhcp: bound DHCPv6 domain-list parsing Ashishkumar Parmar X (asparmar - E INFOCHIPS PRIVATE LIMITED at Cisco)
  0 siblings, 2 replies; 4+ messages in thread
From: Andrei Miu @ 2026-10-23  8:53 UTC (permalink / raw)
  To: connman; +Cc: cve


[-- Attachment #1.1: Type: text/plain, Size: 3662 bytes --]

gdhcp: fix stack buffer overflow in get_domains()

get_domains() copied a fixed NS_MAXDNAME (1025) bytes from the
DOMAIN_LIST (option 24) value into the 1026-byte stack buffer
dns_name regardless of the actual option length, and then walked
DNS labels with an unbounded 'c += jump + 1' loop. A crafted
DHCPv6 REPLY with a DOMAIN_LIST option of >= 1025 non-zero bytes
makes the label walk leave the buffer and read/write '.' past its
end in attacker-chosen strides (stride = label byte + 1), i.e.
out-of-bounds accesses past the 1026-byte stack buffer in
connmand (running as root). On stack-zeroing kernels the walk
performs an out-of-bounds read instead and exits at the first
zero byte.

DHCPv6 REPLY messages are unauthenticated and the transaction id
and CLIENTID DUID are observable on the wire (INFORMATION-REQUEST
is multicast to ff02::1:2), so any on-link attacker can trigger
this.

Fix by bounding the copy to the remaining option length,
NUL-terminating the buffer, and
 stopping the label walk at the
end of the copied data.

Fixes: bb06c47101ca24 ("gdhcp: Domain search list DHCPv6 option is checked")

---

Hello,

I found a stack out-of-bounds read/write in get_domains()
(gdhcp/client.c), reached from an accepted DHCPv6 REPLY
DOMAIN_LIST option. Details:

- Trigger requires only on-link position: a forgeable RA (O=1)
  makes connmand start stateless DHCPv6, it multicasts an
  INFORMATION-REQUEST with DOMAIN_LIST in the ORO to ff02::1:2,
  and an attacker who lifts the xid and CLIENTID off the wire can
  unicast a forged REPLY (matching xid, equal CLIENTID, one
  SERVERID) carrying a long DOMAIN_LIST option. gdhcp's owner
  check accepts it and get_dhcpv6_request() reaches get_domains().

- The out-of-bounds access is confirmed with an AddressSanitizer
  harness built from the verbatim get_domains(): for a DOMAIN_LIST
  value of >= 1025 non-zero bytes the label walk leaves the
  1026-byte dns_name buffer, e.g. "stack-buffer-ove
rflow ...
  '[48, 1074) dns_name' ... access at offset 1104 overflows this
  variable", i.e. ~30 bytes past the buffer, in the
  'while (c && *c)' loop.

- The out-of-bounds writes ('.' at attacker-chosen strides) reach
  the stack canary / saved-register region. Whether the canary is
  actually clobbered depends on the fill pattern and stack layout:
  a small stride reliably corrupts it and aborts connmand (root)
  with "*** stack smashing detected ***" / SIGABRT, while a large
  stride can step over the canary and still perform OOB
  read/writes. Net effect: an unauthenticated on-link attacker can
  crash the root daemon.

- The patch below was tested against a 7505-case corpus (option
  sizes 0..1500 x fill patterns {0x41, 0x00, 0xff, random,
  random-with-NULs}) under ASAN + stack protector with zero
  findings and no abort.

- The copy and walk are unchanged since 2013 (bb06c471), and I
  did not find an existing CVE for get_domains() / option 24.
  CVE-2023-2
8488 is the L2 DHCPv4 length fix (99e2c16e), a
  different code path.

- Suggested CVSS 3.1: AV:A/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:H = 7.6
  (CWE-787 / CWE-125). Cc to cve@kernel.org in case a CVE is
  warranted. I do not claim RCE; it is not demonstrated.

Separately, a smaller thing I'd ask you to confirm (probably no
CVE): dhcpv6_send_packet() in gdhcp/common.c binds a fresh
wildcard ::546 socket per send and passes IPV6_PKTINFO as a cmsg
only, without setsockopt(IPV6_PKTINFO), so stateless DHCPv6
requests appear to egress the default-route interface rather than
the service's interface (seen on a 3-interface host: the INFO-REQ
for a veth-hosted service left via eth0 with eth0's source
address).

Regards,
Andrei Miu

[-- Attachment #1.2: 0001-gdhcp-fix-stack-buffer-overflow-in-get_domains.patch --]
[-- Type: text/plain, Size: 2188 bytes --]

From 9c2e3f0f85370ecee33e09bfce1b8aa8c1c554d4 Mon Sep 17 00:00:00 2001
From: Andrei Miu <andimiu@pm.me>
Date: Thu, 23 Oct 2026 10:00:00 +0200
Subject: [PATCH] gdhcp: fix stack buffer overflow in get_domains()

get_domains() copied a fixed NS_MAXDNAME (1025) bytes from the
DOMAIN_LIST (option 24) value into the 1026-byte stack buffer
dns_name regardless of the actual option length, and then walked
DNS labels with an unbounded 'c += jump + 1' loop. A crafted
DHCPv6 REPLY with a DOMAIN_LIST option of >= 1025 non-zero bytes
makes the label walk leave the buffer and read/write '.' past its
end in attacker-chosen strides (stride = label byte + 1), i.e.
out-of-bounds writes into the canary/saved registers territory of
connmand (running as root). On stack-zeroing kernels the walk
performs an out-of-bounds read instead and exits at the first
zero byte.

DHCPv6 REPLY messages are unauthenticated and the transaction id
and CLIENTID DUID are observable on the wire (INFORMATION-REQUEST
is multicast to ff02::1:2), so any on-link attacker can trigger
this.

Fix by bounding the copy to the remaining option length,
NUL-terminating the buffer, and stopping the label walk at the
end of the copied data.

Fixes: bb06c47101ca24 ("gdhcp: Domain search list DHCPv6 option is checked")
---
 gdhcp/client.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/gdhcp/client.c b/gdhcp/client.c
index 976773ac..b594e349 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -2217,13 +2217,25 @@ static GList *get_domains(int maxlen, unsigned char *value)
 		return NULL;
 
 	while (pos < maxlen) {
-		strncpy(dns_name, (char *)&value[pos], NS_MAXDNAME);
+		int name_len = maxlen - pos;
+		char *name_end;
 
+		if (name_len > NS_MAXDNAME)
+			name_len = NS_MAXDNAME;
+
+		memcpy(dns_name, &value[pos], name_len);
+		dns_name[name_len] = '\0';
+
+		name_end = dns_name + name_len;
 		c = (unsigned char *)dns_name;
 		while (c && *c) {
 			int jump;
+			char *label = (char *)c;
+
 			jump = *c;
-			*c = '.';
+			if (label + jump + 1 > name_end)
+				break;
+			*label = '.';
 			c += jump + 1;
 		}
 		list = g_list_prepend(list, g_strdup(&dns_name[1]));
-- 
2.55.0

[-- Attachment #1.3: publickey - andimiu@pm.me - 0x897A3D75.asc --]
[-- Type: application/pgp-keys, Size: 873 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 322 bytes --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-04 10:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23  8:53 [PATCH] gdhcp: fix stack buffer overflow in get_domains() Andrei Miu
2026-10-23 10:54 ` Greg KH
2026-12-04  6:47 ` [PATCH] gdhcp: bound DHCPv6 domain-list parsing Ashishkumar Parmar X (asparmar - E INFOCHIPS PRIVATE LIMITED at Cisco)
2026-12-04 10:09   ` Greg KH

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.