Skip to contentSkip to conversation

SVM IOIO intercept does not check all bits

PATCH In review Bernhard Kauer 2 participants 5 messages Dec 6, 2007 – Dec 8, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 SVM IOIO intercept does not check all bits

The SVM IOIO intercept does not check all bits in the IO permission map for in/outs with word or long operand size. The attached patch fix this.

Bernhard Kauer

Index: target-i386/helper.c

helper.c +2 -2
@@ -4250,8 +4331,8 @@
             uint64_t addr = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, control.iopm_base_pa));
             uint16_t port = (uint16_t) (param >> 16);
 
-            if(ldub_phys(addr + port / 8) & (1 << (port % 8)))
-                vmexit(type, param);
+	    if(ldub_phys(addr + port / 8) & (((1 << ((param >> 4) & 0x7)) - 1) << (port % 8)))
+	      vmexit(type, param);
         }
         break;
 
#1 lore raw

Hi,

Quoted 6 lines · Bernhard Kauer

The SVM IOIO intercept does not check all bits in the IO permission map for in/outs with word or long operand size. The attached patch fix this.

Bernhard Kauer
<qemu_ioio.diff>

Could you please make this more readable? Apart from that the patch is fine if the highest bit in the IOIO vector is to be set. I could not find that in the documentation.

Cheers,

Alex

#2 lore raw
Quoted 1 line · Alexander Graf

Could you please make this more readable?

Not easy by a one liner. I splitted the mask calculation in a separate line. Is it better now?

Quoted 2 lines

Apart from that the patch is fine if the highest bit in the IOIO vector is to be set. I could not find that in the documentation.

I did not understand your comment. Perhaps you mean the following sentence from the AMD vol. 2:

Quoted 3 lines
Quoted 3 lines

For IN/OUT instructions that access more than a single byte, the permission bits for all bytes are checked; if any bit is set to 1, the I/O operation is intercepted.

Greetings,

Bernhard

Index: target-i386/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/helper.c,v retrieving revision 1.95

helper.c +2 -1
diff -u -r1.95 helper.c
@@ -4250,7 +4331,8 @@
             uint64_t addr = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, control.iopm_base_pa));
             uint16_t port = (uint16_t) (param >> 16);
 
-            if(ldub_phys(addr + port / 8) & (1 << (port % 8)))
+	    uint8_t mask = (1 << ((param >> 4) & 0x7)) - 1;
+	    if(ldub_phys(addr + port / 8) & (mask << (port % 8)))
                 vmexit(type, param);
         }
         break;
#3 lore raw
Quoted 5 lines · Bernhard Kauer
Quoted 1 line · Alexander Graf

Could you please make this more readable?

Not easy by a one liner. I splitted the mask calculation in a separate line. Is it better now?

Much better, yes.

Quoted 8 lines
Quoted 4 lines

Apart from that the patch is fine if the highest bit in the IOIO vector is to be set. I could not find that in the documentation.

I did not understand your comment. Perhaps you mean the following sentence from the AMD vol. 2:

I actually misread your patch, nevermind.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

For IN/OUT instructions that access more than a single byte, the permission bits for all bytes are checked; if any bit is set to 1, the I/O operation is intercepted.

That was the one. Thank you.

Quoted 6 lines

Greetings,

Bernhard
<qemu_ioio.diff>

Looks good now (apart from whitespaces).

Cheers,

Alex

#4 lore raw
Quoted 6 lines · Alexander Graf
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

For IN/OUT instructions that access more than a single byte, the permission bits for all bytes are checked; if any bit is set to 1, the I/O operation is intercepted.

That was the one. Thank you.

Unfortunately there is another bug in this line. As there is only a single byte read from the permission bitmap, an unaligned 4-byte access to port 0x7 would be possible even when the access to port 0x8-0xa is not allowed. The updated patch fixes also this case.

Bernhard Kauer

Index: target-i386/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/helper.c,v retrieving revision 1.95

helper.c +2 -1
diff -u -r1.95 helper.c
@@ -4250,7 +4332,8 @@
             uint64_t addr = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, control.iopm_base_pa));
             uint16_t port = (uint16_t) (param >> 16);
 
-            if(ldub_phys(addr + port / 8) & (1 << (port % 8)))
+            uint16_t mask = (1 << ((param >> 4) & 7)) - 1;
+            if(lduw_phys(addr + port / 8) & (mask << (port & 7)))
                 vmexit(type, param);
         }
         break;