KVM: emulator: Fix permission checking in io permission bitmap
authorGleb Natapov <gleb@redhat.com>
Mon, 7 Mar 2011 12:55:07 +0000 (14:55 +0200)
committerMarcelo Tosatti <mtosatti@redhat.com>
Thu, 17 Mar 2011 16:08:33 +0000 (13:08 -0300)
Currently if io port + len crosses 8bit boundary in io permission bitmap the
check may allow IO that otherwise should not be allowed. The patch fixes that.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/kvm/emulate.c

index d6088b8686fbd0423b8f771d449d4719f697f3fe..0ad47b819a8b2eb1743810e9b9dd19c9d5b59a3d 100644 (file)
@@ -1769,8 +1769,7 @@ static bool emulator_io_port_access_allowed(struct x86_emulate_ctxt *ctxt,
        struct desc_struct tr_seg;
        u32 base3;
        int r;
-       u16 io_bitmap_ptr;
-       u8 perm, bit_idx = port & 0x7;
+       u16 io_bitmap_ptr, perm, bit_idx = port & 0x7;
        unsigned mask = (1 << len) - 1;
        unsigned long base;
 
@@ -1788,7 +1787,7 @@ static bool emulator_io_port_access_allowed(struct x86_emulate_ctxt *ctxt,
                return false;
        if (io_bitmap_ptr + port/8 > desc_limit_scaled(&tr_seg))
                return false;
-       r = ops->read_std(base + io_bitmap_ptr + port/8, &perm, 1, ctxt->vcpu,
+       r = ops->read_std(base + io_bitmap_ptr + port/8, &perm, 2, ctxt->vcpu,
                          NULL);
        if (r != X86EMUL_CONTINUE)
                return false;