nginx: 1-byte memory overwrite vulnerability in DNS resolver (CVE-2021-23017)
An off-by-one error in nginx's DNS resolver allows a network attacker to write a dot character out of bounds in a heap buffer when processing a crafted DNS response. This can lead to denial of service and likely remote code execution.
x41-dsec.de
Published on x41-dsec.de
An off-by-one error in ngxresolvercopy() while processing DNS responses allows a network attacker to write a dot character (‘.’, 0x2E) out of bounds in a heap allocated buffer. The vulnerability can be triggered by a DNS response in reply to a DNS request from nginx when the resolver primitive is configured.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
A mismatch between the size calculation and the decompression step in `ngx_resolver_copy()` causes an off-by-one write when a compressed name ends with a pointer to a NUL byte.
Impact
A network attacker could cause a denial of service and likely achieve remote code execution, though exploitability depends on heap layout and operating system.
What the attacker needed
Nginx configured with resolver; attacker can send DNS responses
The fix
The issue was fixed by allocating an extra byte for the spurious dot character.
How it was found
- Configure nginx with the resolver primitive pointing to a DNS server.
- Send a DNS request from nginx to that server.
- Have the attacker-controlled DNS server respond with a crafted DNS response containing a poisoned name.
- The vulnerable function processes the response and writes a dot out of bounds.
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 write-up has not been written yet. The Original tab links to the source.
When nginx looks up a domain name, it receives DNS responses and parses them. A bug in that parsing lets an attacker send a specially crafted response that writes one byte past the end of a memory buffer. This can crash nginx or, in some cases, let the attacker run their own code.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.