GHSL-2021-049: Type confusion vulnerability in the varlink interface of systemd-resolved
The varlink interface of systemd-resolved stored two different object types in the same userdata field of a reused Varlink struct. A local attacker sending two requests in quick succession could trigger a type confusion, crashing the service and potentially corrupting memory.
Originally disclosed on GitHub Security Lab
There is a potential type confusion vulnerability in the varlink interface of systemd-resolved. This is due to the userdata field of the Varlink struct being used to store two unrelated datatypes: Manager and DnsQuery.
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 report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The Varlink struct's userdata field was reused to hold either a Manager or a DnsQuery pointer, on the assumption that the object only lives for one request, but the object is reused across back-to-back requests.
Impact
In testing the service always crashed on a NULL pointer assertion, but the authors believe a different event ordering could cause a type confusion leading to memory corruption and possibly code execution as the systemd-resolve user.
What the attacker needed
Local access to the system; systemd-resolved with varlink interface running
The fix
The issue was already fixed upstream, though it was not declared a security issue.
How it was found
- Build the proof-of-concept program with gcc.
- Start systemd-resolved if it is not already running.
- Run the PoC in hostname mode against a hostname.
- Run the PoC in address mode against an address.
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.
A program can store a pointer to some data in a shared slot. Here the same slot was used for two different kinds of object, and the code assumed the slot would be reset between requests. When two requests arrive close together, the slot still holds the wrong kind of object, so the program misreads it and can crash or corrupt memory.
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.