Invalid #PF Exception Code in VMware can result in Guest Privilege Escalation Oct 27 2009 07:15PM
Tavis Ormandy (taviso sdf lonestar org)
Invalid #PF Exception Code in VMware can result in Guest Privilege Escalation

In protected mode, cpl is usually equal to the two least significant bits of
the cs register. However, there is an exception: in Virtual-8086 mode, the
cpl is always 3 (least privileged), regardless of the value of the cs

When the processor raises a #PF (page fault) exception, an exception code is
pushed onto the stack containing flags used by the operating system to
determine the correct course of action. One of those flags is called U/S
(user/supervisor), which is set if the fault was caused while the processor
was in user mode.

In Virtual-8086 mode, when VMware emulates a far call or far jmp instruction,
it incorrectly pushes the return cs and ip on the stack using supervisory
access, causing an incorrect exception code to be delivered to the guest

As Virtual-8086 mode allows userland code to specify an arbitrary cs register,
including the two least significant bits, an attacker can use this supervisory
access to confuse the kernel, allowing escalation of privileges.

The Common Vulnerabilities and Exposures project (cve.mitre.org) has
assigned the name CVE-2009-2267 to this issue.

Affected Software

- VMware Workstation
- VMware Player
- VMware ACE
- VMware Server
- VMware ESX
- VMware Fusion
- Etc.


We have successfully exploited this issue on Linux guests. Other guest
operating systems may also be exploitable.

Here is what happens on an up-to-date Ubuntu Linux 8.04 guest when the kernel
handles the #PF exception with a spoofed supervisor bit in the exception code.

(gdb) x/i $pc
0x900: call 0xaabb:0xccdd
(gdb) si
0xc031d000 in page_fault ()
(gdb) x/x $esp
0xdde15f08: 0x00000002
(gdb) x/t $esp
0xdde15f08: 00000000000000000000000000000010

Examining the condition code (error_code in the snippet below), you can see it
was caused by a data write (i.e. not an instruction fetch, the cs/eip push) in
supervisor mode to a non-present page. This is incorrect.


461 /* User mode accesses just cause a SIGSEGV */
462 if (error_code & 4) {
508 /* Are we prepared to handle this kernel fault? */
509 if (fixup_exception(regs))
510 return;

With a spoofed cs register, this can lead to this path (see the
SEGMENT_IS_PNP_CODE macro from segment_32.h), causing the kernel to
reach the pnp_bios_is_utter_crap code, and attempting this recovery:


19 printk(KERN_CRIT "PNPBIOS fault.. attempting recovery.\n");
20 __asm__ volatile(
21 "movl %0, %%esp\n\t"
22 "jmp *%1\n\t"
23 : : "g" (pnp_bios_fault_esp), "g" (pnp_bios_fault_eip));
24 panic("do_trap: can't hit this");
25 }

pnp_bios_fault_eip and pnp_bios_fault_esp are both .bss objects, and
will be initialised to NULL. Thus, line 22 will transfer execution to
the first page.

Therefore, incorrectly reporting the supervisor bit can lead to a local
ring3->ring0 privilege escalation in guests.

/* ... */
// Setup registers
vm.regs.eflags = EFLAGS_TF_MASK;
vm.regs.esp = 0xDEADBEEF;
vm.regs.eip = 0x00000000;
vm.regs.cs = 0x0090;
vm.regs.ss = 0xFFFF;

CODE16("call 0xaabb:0xccdd", code, codesize);

vm86(Vm86Enter, &vm);
/* ... */

The attached non-weaponised proof of concept demonstrates this by
printing a message to the console from ring0.


Updated software is available from the vendor at http://www.vmware.com/



This bug was discovered by Tavis Ormandy and Julien Tinnes of the Google
Security Team.


Greetz to Lcamtuf, LiquidK, redpig, Neel, pipacs, spoonm, asiraP,
Jagger, and our other elite colleagues.

Additional greetz to everyone at $1$K2XTi4ZA$H5Y197fbrMk85ZWzNw/Nm0.

Enjoy some photography while at ring0 @ http://flickr.com/meder

taviso (at) sdf.lonestar (dot) org [email concealed] | finger me for my gpg key.
?íY{sÛ6÷¿å§Ø?ÛDòÉ2õ?ìÆN'?-ûtÕk$Ùis½á@$$¡æ« (ËÉå»ß$%??lw?ñÜÍÓFÄb?Å.°»?çÎáô¤~Ô!·tÂlº÷í??­^×Õïq½¶ö+[¹z¼W.W?Ëu½V=F¾
rµ®?÷@ß{??p?=Aæ,ðvó=6þÚ?m¿?y¼ 4Í´)qßjßq'K:?<üßô8ù¦%#+lÉÔ¾??&:Õ
b.?ᯝ|P?áh??+ªêÂ~ iâÞ§NÝЁ/`»ÁÔ·Ã å¢emû|FÍÛâr¤é
qºR7<4?38êK~H®-L>®ÇH?¤°£#8'¶ÚDP `£ip'Ëâ4`Â=Î?o[}ð ãKã
?vÞ ?Ì/@>?÷??|I8;?Zþ?t9ú
nN `Sw+`??u?ø[­, ?Ü?<ôÅVÔEU?PãÔÌÛ®\/?:?PÞ?ò?íÝmW°×oG°TÕ#Pë¨>gs¬Î
¦l:§vÚ­ÏW?¡.?"j Ám2XW±¬Çܽ¡C·*xÓY?TÈ?qNt¬Ï¢;é|
GWÔ¥\F£r}ÌD?d® LË¥ÅjÈ¡"ØdLí"±Ï´?_à7Ie3 5j`?ë2G?¢üÂÉNS\s£îKÑ?'??d?wðêÕ&ïÔ??]?|?&³?Ï?¤{l#¸wY?ëù°øÍÍ¥
ë-W?«*×âQ&É=.¥Zy???¨¶T¬^l´üôúòÊ??Ä8jýiD>rÃ;<LØ?¯p7S??; ?uwW+¹7Ú
?LiCtCÛ??ÚK#ææåáS?Ñ éÁvæ-ºiª?ãx?ÁºØ!¾/Ë&Ýëv[1° ä3 ñ-U¶ Õ®?äÑX§!?Öõ±(? á?~pTºXòs*BîB9¢|Õ%?H÷A`?·v??`à?ä?w§5I±%?¬@?S%91ÃEÑ5CAð\ëAúzNa?&¢
ú«ýÆUÓbá???ÞÈèöºøÙiôþ uÓ5á?ª×À_;½ëaÜ¿lýÒ¼(??ÿaZ~Ñ­vó"­?Ú>tjò¯²^
©ý{¹eBÇR&bïT{dÇpYI7.IÕ?UcA$+¶W<`Y¤6^ôD?IÉ?RË?ÀwgL?ê6oÙ/à~= LÎ
?`݁qÇ?  <?°??vu-=ÙeêìÌJäº~Ëuol­d׬|Ñõîà?©È?¹×ç??¬OZË?
òI7æ-aߐ}ä>ï_oNêY§S¬?(?|.QùÎ jýýñt)ð?C_\4?ÍËÌ(?F??|®?A<øcf ?.±¥Ây¹?Ï?Òkú?ñø­¾0MËÊírBÚo«?iÝv:PZ8¿z½?Ws'ã[uÝÝpî?zgU¾É?:«ýÖQy^V???^
äSç?2O)ÌéÖÒF?p ~6 ?§êØ@¯[x]Úvº^þ¤ùÒ^ÚK{i/í¥½´GÚï?Iò(

[ reply ]


Privacy Statement
Copyright 2010, SecurityFocus