qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/1] x86: enforce DPL checking on task gate switches


From: Alex Zuepke
Subject: [Qemu-devel] [PATCH 1/1] x86: enforce DPL checking on task gate switches
Date: Tue, 13 May 2014 23:12:53 +0200

x86 software emulation (non-KVM mode) does not check privilege levels on task 
gate switches.
An "int $8" in user mode panics any OS kernel by a forbidden direct call into 
the double fault handler.

This testcase crashes a Linux kernel with a double fault panic:

$ cat test.c
  int main(void)
  {
    __asm__ volatile ("int $8");
  }
$ gcc test.c
$ ./a.out
panic ...

Signed-off-by: Alex Zuepke <address@hidden>
---
 target-i386/seg_helper.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/target-i386/seg_helper.c b/target-i386/seg_helper.c
index 8c3f92c..d7f3d49 100644
--- a/target-i386/seg_helper.c
+++ b/target-i386/seg_helper.c
@@ -582,12 +582,18 @@ static void do_interrupt_protected(CPUX86State *env, int 
intno, int is_int,
     e2 = cpu_ldl_kernel(env, ptr + 4);
     /* check gate type */
     type = (e2 >> DESC_TYPE_SHIFT) & 0x1f;
+    dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+    cpl = env->hflags & HF_CPL_MASK;
     switch (type) {
     case 5: /* task gate */
         /* must do that check here to return the correct error code */
         if (!(e2 & DESC_P_MASK)) {
             raise_exception_err(env, EXCP0B_NOSEG, intno * 8 + 2);
         }
+        /* check privilege if software int */
+        if (is_int && (dpl < cpl)) {
+            raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2);
+        }
         switch_tss(env, intno * 8, e1, e2, SWITCH_TSS_CALL, old_eip);
         if (has_error_code) {
             int type;
@@ -620,8 +626,6 @@ static void do_interrupt_protected(CPUX86State *env, int 
intno, int is_int,
         raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2);
         break;
     }
-    dpl = (e2 >> DESC_DPL_SHIFT) & 3;
-    cpl = env->hflags & HF_CPL_MASK;
     /* check privilege if software int */
     if (is_int && dpl < cpl) {
         raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2);
-- 
1.7.9.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]