nday exploit: libinput format string bug, canary leak exploit (cve-2022-1215)
A format string vulnerability in libinput allowed a malicious USB device to inject printf-style placeholders through its descriptor string fields, which were then used as a format string in logging. The author used this to leak the stack canary from the Xorg log file, but could not achieve code execution because FORTIFY_SOURCE=2 blocks %n.
This is an issue that I had independently discovered in Xorg (or so I thought) a while back while messing around with the GreatFET One, a cool little device for USB hacking. While trying out some random payloads I found that connecting a USB keyboard device with format strings in certain device descriptor fields…
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
Likely the device-supplied name string was concatenated into a format string and then passed as the format argument to sprintf, so attacker-controlled format specifiers were interpreted.
Impact
An attacker with a malicious USB device could leak the stack canary into a world-readable log, but code execution was not achieved because FORTIFY_SOURCE=2 blocks %n; the leak was only confirmed on an unpatched Xubuntu 20.04 install.
What the attacker needed
Physical or emulated USB device; unpatched libinput/Xorg build; access to the Xorg log file
The fix
The issue was fixed upstream in libinput in April 2022, and the author notes patches have been pushed.
How it was found
- Connect an emulated USB keyboard whose descriptor string fields contain format specifiers.
- The vulnerable logging path prepends the device name to a format string and passes it to sprintf.
- Use direct parameter access in the specifiers to avoid crashing on the extra %s specifiers.
- Read the resulting values from the world-readable Xorg log file.
- Search the log for a value matching the pattern of a stack canary.
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 a program builds a message by pasting in text from outside, and that text contains special formatting codes, the program can be tricked into reading or writing memory it should not. Here a fake USB keyboard could put such codes in its name, and the system logged them in a way that revealed a secret value used to protect against memory attacks. The author could read that secret but not take over the machine.
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.