<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Hello,</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">I found a heap-buffer-overflow (out-of-bounds read) in dnsmasq's configuration parser. A malformed server= line (also address= and local=) makes the daemon read past the 1024-byte line buffer while parsing the configuration at startup or during --test.</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Version</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">-------</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">dnsmasq 2.93 (release tarball). The same code is present at commit cf08eeee12b0f76a1259736c7795bfae82e08d2c (2.93-dev).</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Reproducer</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">----------</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Minimal configuration file, 21 bytes, one line terminated by a newline:</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> server=/a/ b/1.1.1.1</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">i.e. the bytes</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> 73 65 72 76 65 72 3d 2f 61 2f 20 62 2f 31 2e 31 2e 31 2e 31 0a</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Command:</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> ./dnsmasq --test --conf-file=min.conf</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Result, gcc 12 plus ASan, aarch64 Linux:</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> ==...==ERROR: AddressSanitizer: heap-buffer-overflow on address ...</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> READ of size 1004 at ... thread T0</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> #0 ... in __interceptor_strlen</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> #1 ... in check_name src/util.c:139</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> #2 ... in canonicalise src/util.c:251</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> #3 ... in add_update_server src/domain-match.c:677</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> #4 ... in one_opt src/option.c:3142</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> #5 ... in read_file src/option.c:5599</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> #6 ... in one_file src/option.c:5705</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> #7 ... in read_opts src/option.c:6090</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> #8 ... in main src/dnsmasq.c:115</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">The 1024-byte line buffer is allocated by get_line_alloc() (src/util.c:1054) via whine_realloc_real() (src/util.c:967); the over-read starts inside it and runs past the end of the allocation.</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">The original 71-byte test file from my fuzzing run also reproduces (READ of size 953), as do these variants:</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> server=/a/ x/1.2.3.4</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> server=/a/ b/1.2.3.4</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> address=/a/ b/1.1.1.1</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> local=/a/ b/</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> server=/a/<TAB>b/1.1.1.1</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">server=/a/ /1.2.3.4 is rejected as a syntax error and server=/a /1.2.3.4 (two spaces) parses fine. The trigger is an extra whitespace-separated token after the /domain/ group that is neither a server address nor a URL.</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Root cause</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">----------</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">For server=, address= and local=, one_opt() (src/option.c, around lines 3030 to 3150) parses the optional domain list:</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> domain = lastdomain = ++arg;</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> while ((last = split_chr(arg, '/'))) {</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> lastdomain = arg;</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> arg = last;</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"> }</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">split_chr() (src/option.c:698) replaces the found '/' with a space and then NUL-terminates backwards over spaces, so each domain segment is delimited in place. When the rest of the line contains an extra token that is not a URL or server specification, the final lastdomain pointer does not point at a NUL-terminated domain; add_update_server() -> canonicalise() -> check_name() then calls strlen() on it (src/util.c:139) and walks past the end of the line buffer.</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Suggested fix</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">-------------</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Reject or ignore tokens after a /domain/ group that are neither a server address, an interface, a source address, nor a URL, instead of passing the leftover token to add_update_server().</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Defensively bound the domain before canonicalise() and check_name(): the domain is already delimited by the '/' or whitespace in the line buffer, so terminate it explicitly rather than relying on the in-place NUL that split_chr() writes only for the segments it consumed.</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Impact</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">------</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Parsing a crafted configuration file causes an out-of-bounds heap read during startup or --test; the tested ASan build aborts, demonstrating a local denial-of-service condition. Configuration files may be generated by management planes or provisioning pipelines, so a malformed generated line can prevent the resolver from starting. The trigger demonstrated here is local configuration parsing, not a remote network attack, and no information disclosure was demonstrated.</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">I can provide my name and affiliation if the report is credited or a CVE is assigned.</span><br>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';"><br>
</span><br>
<p>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Regards,</span>
</p>
<p>
<span style="font-family:'SimSun, 宋体, STSong, CESI_SS_GB18030';">Mengda Chen</span>
</p>