Resource leak when using a normal site as DOH server
When curl uses a DNS-over-HTTPS (DOH) server that is actually a normal web server, the DNS response is not valid DNS, so curl correctly treats resolution as failed but fails to free allocated memory. An attacker could cause a memory leak that, if repeated, might eventually lead to denial of service through resource depletion.
- Disclosed after 17 months
Summary:
If a DOH server is used, which is not really a DOH server but just a normal web server, the DNS request is sent but the reply will not be the expected DNS payload. In that case, curl correctly thinks DNS resolution failed, but it does not clean up allocated memory properly.
Steps To Reproduce:
See the attached demonstration program. It can use either no DOH, a valid DOH, a garbage DOH address, or a valid web server not serving DOH. Valgrind sees that it leaks memory only in the last case, the others are cleaned up properly.
Leaking case
This will use https://example.com/ both as the URL to reach and as a DOH.
valgrind ./a.out notadoh
(snip)
==3096== HEAP SUMMARY:
==3096== in use at exit: 98,252 bytes in 1,043 blocks
==3096== total heap usage: 101,296 allocs, 100,253 frees, 9,473,596 bytes allocated
==3096==
==3096== LEAK SUMMARY:
==3096== definitely lost: 8,564 bytes in 3 blocks
==3096== indirectly lost: 88,144 bytes in 995 blocks
==3096== possibly lost: 0 bytes in 0 blocks
==3096== still reachable: 1,544 bytes in 45 blocks
==3096== suppressed: 0 bytes in 0 blocks
==3096== Rerun with --leak-check=full to see details of leaked memory
Normal case - no DOH
This will use https://example.com/ without DOH.
valgrind ./a.out none
(snip)
==3217== HEAP SUMMARY:
==3217== in use at exit: 1,544 bytes in 45 blocks
==3217== total heap usage: 37,396 allocs, 37,351 frees, 3,332,013 bytes allocated
==3217==
==3217== LEAK SUMMARY:
==3217== definitely lost: 0 bytes in 0 blocks
==3217== indirectly lost: 0 bytes in 0 blocks
==3217== possibly lost: 0 bytes in 0 blocks
==3217== still reachable: 1,544 bytes in 45 blocks
==3217== suppressed: 0 bytes in 0 blocks
Normal case - working DOH
This will use https://example.com/ with cloudflare DOH.
valgrind ./a.out cloudflare
(snip)
==3376== HEAP SUMMARY:
==3376== in use at exit: 1,656 bytes in 49 blocks
==3376== total heap usage: 101,564 allocs, 101,515 frees, 9,062,588 bytes allocated
==3376==
==3376== LEAK SUMMARY:
==3376== definitely lost: 0 bytes in 0 blocks
==3376== indirectly lost: 0 bytes in 0 blocks
==3376== possibly lost: 0 bytes in 0 blocks
==3376== still reachable: 1,656 bytes in 49 blocks
==3376== suppressed: 0 bytes in 0 blocks
Supporting Material/References:
See the attached program.
Impact
The failed DOH is invisible to the end user, it seems to fallback to normal DNS. So if the user has the wrong DOH adress (perhaps confused, or the DOH url changed slightly and now points to some generic hello page), I guess the memory leaks will add up, eventually leading to denial of service because of resource depletion.
It does not feel like a serious issue but I wanted to go through hackerone instead of filing a public report right away.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
The failed DOH is invisible to the user and seems to fall back to normal DNS, so repeated use with a wrong DOH address could accumulate leaks and eventually cause denial of service through resource depletion.
What the attacker needed
Curl built with DOH support; DOH server address points to a normal web server
How it was found
- Run the demonstration program with a normal web server (not a DOH server) as the DOH address.
- Observe that curl fails DNS resolution as expected.
- Run the program under Valgrind and see that memory is reported as definitely lost.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
DNS-over-HTTPS (DOH) is a way to look up domain names using a web request instead of the usual DNS system. If the web server you point curl at is not a real DOH server, it sends back a normal web page instead of a DNS answer. curl notices the answer is wrong and stops, but it forgets to free some memory it used, so that memory is lost until the program ends.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.