From 9785e2ec41b9b4e9bac40608565f5a18d4035a17 Mon Sep 17 00:00:00 2001 From: Georgi Steffenhagen Date: Mon, 23 Nov 2026 20:27:17 +0100 Subject: [PATCH] Fix use-after-free in relay_upstream6(). CVE-2026-133730 relay_upstream6() takes a pointer to the Relay-forward header at the start of the output packet, then adds the client link-layer address and relay message options, and then writes the link-address into the header through that pointer, once for each relay. Adding the options makes expand_buf() move the packet buffer whenever the relayed message doesn't fit the buffer as it is, and the buffer starts out at 548 bytes. The link-address is then written into memory which has been freed, and the packet goes out with an empty link-address. One DHCPv6 message of about 500 bytes or more arriving on an interface with --dhcp-relay configured is enough for that. With a normal build it takes a few messages of growing size to crash dnsmasq: the write lands on the heap's own bookkeeping in the freed block. Up to 2.86 the link-address was written before the options were added. Commit 7fbf1cc ("Improve the performance of DHCP relay.") moved it into the loop over the relays, so 2.87 is the first release with the problem. Find the header again once the packet is complete. Credit to Akin Yilmaz (DecompilerAI) and, independently, Georgi Steffenhagen for finding this. --- CHANGELOG | 5 ++++- src/rfc3315.c | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index f160ca4..485d4a3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,7 +13,10 @@ version 2.94 for spotting and reporting this. A crafted reply can crash dnsmasq. CNVD-C-2026-590208 applies. - + Fix heap OOB write in relay_upstream6() Thanks to + Akin Yilma (DecompilerAI) and Georgi Steffenhagen for spotting this. + CVE-2026-133730 appiles. + version 2.93 Fix a corner-case in DNSSEC validation with wildcards. If we have a wildcard record *.example.com and receive a query for diff --git a/src/rfc3315.c b/src/rfc3315.c index 79d420f..690e2f6 100644 --- a/src/rfc3315.c +++ b/src/rfc3315.c @@ -2218,6 +2218,10 @@ int relay_upstream6(int iface_index, ssize_t sz, put_opt6(inbuff, sz); end_opt6(o); + /* Adding the options above may have moved the packet buffer, + so find the header again before writing to it below. */ + header = daemon->outpacket.iov_base; + for (; relay; relay = relay->next) if (relay->iface_index != 0 && relay->iface_index == iface_index) {