Xen exploitation part 1: XSA-105, from nobody to root
The Xen emulator for HLT, LGDT, LIDT, and LMSW instructions failed to perform supervisor mode permission checks, allowing unprivileged guest user-mode code to load its own GDT or IDT. An attacker could exploit this to execute arbitrary code with kernel privileges and escalate to root on the guest.
blog.quarkslab.com
Published on blog.quarkslab.com
Posted Wed 25 May 2016 Author Jérémie Boutoille Category Exploitation Tags Xen, PoC, exploitation, Linux, 2016
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
The Xen emulator for HLT, LGDT, LIDT, and LMSW instructions did not check the current privilege level (CPL) before executing them, allowing ring 3 code to modify privileged registers.
Impact
A malicious guest user could escalate privileges to root on the guest, but the exploit requires SMEP to be disabled and kptr_restrict to be off, and only works on HVM guests with more than one CPU.
What the attacker needed
HVM guest with more than one CPU; SMEP disabled in the guest; kptr_restrict disabled
How it was found
- Craft a custom GDT containing a flat segmentation model and a call gate with DPL = 3.
- Save the current GDTR.
- Create two threads waiting for each other for synchronisation.
- The first thread executes an ud2 instruction while the second patches it with a lgdt [rbx] instruction.
- If not too slow, the emulation of lgdt [rbx] occurs.
- Perform a far call to the call gate, which executes kernel code to escalate privileges.
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.
In a virtualised environment, the hypervisor (Xen) emulates certain CPU instructions for guests. Normally, instructions that change critical tables like the GDT (which defines memory segments) are restricted to kernel mode. Here, Xen forgot to check the privilege level, so a normal user program could run them. By loading a crafted GDT with a call gate, the attacker can jump into kernel code and gain root.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.