<div dir="ltr"><div><div><div><div>Dear sirs,<br></div>             I discovered one potential vulnerability in dnsmasq. <br>More specifically, in tcp_request(), setup_reply() gets called and the returned value<br></div><div>is used as a size argument in a write function.<br><br></div>m = setup_reply(header, (unsigned int)size, addrp, flags, daemon->local_ttl);<br>read_write(confd, packet, m + sizeof(u16), 0))<br><br></div>Although, setup_reply can't return a size variable greater than <br>packet[65535+ MAXDNAME + RRFIXEDSZ + sizeof(u16))], <br>an ignored error value(NULL) of  skip_questions() might lead to a negative pointer<br></div><div>value(-header)<br><br>size_t setup_reply(struct dns_header *header, size_t qlen,<br>struct all_addr *addrp, unsigned int flags, unsigned long ttl)<br>{ <br>   unsigned char *p = skip_questions(header, qlen)<br>   return p - (unsigned char *)header<br>}<br><br></div><div>read_write checks if the size argument is positive. In case of a 32 bit system<br></div><div>size_t m would be 4 bytes and read_write will automatically exit. In case of 64 bit<br></div>system size_t m is 8 bytes and may turn to positive if the sign bit of the <br>32 bit value is 0. <br><br>If m is less than 0xffffffff80000000, dnsmasq will be exploited <br>by a potential attacker who will remotely read dnsmasq heap until it crashes.<br>If the above condition is not met, dnsmasq  exits properly.</div>