Skip to contentSkip to conversation

target/i386: Add missing CPL==0 check when returning to VM86

PATCH In review Hrvoje Misetic 1 participant 2 messages May 28 – Aug 18

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/i386: Add missing CPL==0 check when returning to VM86

helper_ret_protected only checks if the VM flag is set in the new eflags, while the Intel manual says:
IF tempEFLAGS(VM) = 1 and CPL = 0

        THEN GOTO RETURN-TO-VIRTUAL-8086-MODE;

As CPL==0 check is missing in QEMU TCG, a 32-bit binary inside the guest can elevate privileges by executing an iret and returning to VM86 while setting IOPL to 3.

Fixes 90a9fdae1f1a ("more ring 0 operations")
---
 target/i386/tcg/seg_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/tcg/seg_helper.c +1 -1
index 58aac72011..57cf668131 100644
@@ -2068,7 +2068,7 @@ static inline void helper_ret_protected(CPUX86State *env, int shift,
             new_cs = popl(&sa) & 0xffff;
             if (is_iret) {
                 new_eflags = popl(&sa);
-                if (new_eflags & VM_MASK) {
+                if (new_eflags & VM_MASK && cpl == 0) {
                     goto return_to_vm86;
                 }
             }
Signature · 1 line
2.48.1
#1 lore raw

Bumping this:
https://lore.kernel.org/qemu-devel/[email protected]/T/#u

Any comments or suggestions on the patch?

Thanks,
Hrvoje

Quoted 33 lines · Hrvoje Misetic

helper_ret_protected only checks if the VM flag is set in the new eflags, while the Intel manual says:
IF tempEFLAGS(VM) = 1 and CPL = 0

        THEN GOTO RETURN-TO-VIRTUAL-8086-MODE;

As CPL==0 check is missing in QEMU TCG, a 32-bit binary inside the guest can elevate privileges by executing an iret and returning to VM86 while setting IOPL to 3.

Fixes 90a9fdae1f1a ("more ring 0 operations")
---
 target/i386/tcg/seg_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/tcg/seg_helper.c +1 -1
index 58aac72011..57cf668131 100644
@@ -2068,7 +2068,7 @@ static inline void helper_ret_protected(CPUX86State
 *env, int shift,
             new_cs = popl(&sa) & 0xffff;
             if (is_iret) {
                 new_eflags = popl(&sa);
-                if (new_eflags & VM_MASK) {
+                if (new_eflags & VM_MASK && cpl == 0) {
                     goto return_to_vm86;
                 }
             }

--
2.48.1