Skip to contentSkip to conversation

x86/hvm/vioapic: 8-Bit IOREGSEL write does not work

BUG Christian Prochaska 4 participants 4 messages Sep 5, 2017 – Sep 6, 2017

lore
Share & tools
lore
#0 lore raw

I've seen this problem with Xen 4.6.5 from the Xubuntu 16.04 distribution and from a quick look over the current vioapic code it seems to be still present.

From the IOAPIC datasheet [1]: "To reference an IOAPIC register, a byte memory write that the PIIX3 decodes for the IOAPIC loads the IOREGSEL Register with an 8-bit value that specifies the IOAPIC register (address offset in Table 3.2) to be accessed."

But the 'vioapic_write()' function does not consider the 'length' argument and always copies 4 Bytes from the unsigned long 'val' argument into the virtual 32-Bit IOREGSEL register. In the error case I've seen, 'length' was 1 and 'val' was 0xffff8300bb0cf801 and the IOAPIC version register with address offset 0x01 was not read correctly.

Regards,
Christian

[1] https://pdos.csail.mit.edu/6.828/2016/readings/ia32/ioapic.pdf

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#1 lore raw
Quoted 8 lines · Christian Prochaska

I've seen this problem with Xen 4.6.5 from the Xubuntu 16.04 distribution and from a quick look over the current vioapic code it seems to be still present.

From the IOAPIC datasheet [1]: "To reference an IOAPIC register, a byte memory write that the PIIX3 decodes for the IOAPIC loads the IOREGSEL Register with an 8-bit value that specifies the IOAPIC register (address offset in Table 3.2) to be accessed."

IOREGSEL is a 32bit field, with bits 31:8 marked as reserved.

Quoted 5 lines

But the 'vioapic_write()' function does not consider the 'length' argument and always copies 4 Bytes from the unsigned long 'val' argument into the virtual 32-Bit IOREGSEL register. In the error case I've seen, 'length' was 1 and 'val' was 0xffff8300bb0cf801 and the IOAPIC version register with address offset 0x01 was not read correctly.

OK, so it means that the guest is writing garbage to the reserved bits, which is against the spec.

The following patch should solve this, but keep in mind that your guest is not well-behaved, it's writing this garbage to IOREGSEL, and that's why it breaks.

Roger.
---8<---

xen/arch/x86/hvm/vioapic.c +1 -1
index 72cae935ac..4d8b5a4dbe 100644
@@ -324,7 +324,7 @@ static int vioapic_write(
     switch ( addr & 0xff )
     {
     case VIOAPIC_REG_SELECT:
-        vioapic->ioregsel = val;
+        vioapic->ioregsel = val & 0xff;
         break;
 
     case VIOAPIC_REG_WINDOW:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
In reply to Christian Prochaska
Quoted 9 lines · Christian Prochaska

I've seen this problem with Xen 4.6.5 from the Xubuntu 16.04 distribution and from a quick look over the current vioapic code it seems to be still present.

From the IOAPIC datasheet [1]: "To reference an IOAPIC register, a byte memory write that the PIIX3 decodes for the IOAPIC loads the IOREGSEL Register with an 8-bit value that specifies the IOAPIC register (address offset in Table 3.2) to be accessed."

Quoted 5 lines

But the 'vioapic_write()' function does not consider the 'length' argument and always copies 4 Bytes from the unsigned long 'val' argument into the virtual 32-Bit IOREGSEL register. In the error case I've seen, 'length' was 1 and 'val' was 0xffff8300bb0cf801 and the IOAPIC version register with address offset 0x01 was not read correctly.

That looks suspiciously like a Xen pointer, not a plausible val.

Irrespective, it is an error for the guest to issue anything other than a 4 byte write into the IOREGSEL field, so we ought to be rejecting length-1 accesses.

What instruction is the guest using to cause this behaviour to occur?

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 06.09.17 at 11:58, <[email protected]> wrote:
Quoted 9 lines · Christian Prochaska

I've seen this problem with Xen 4.6.5 from the Xubuntu 16.04 distribution and from a quick look over the current vioapic code it seems to be still present.

From the IOAPIC datasheet [1]: "To reference an IOAPIC register, a byte memory write that the PIIX3 decodes for the IOAPIC loads the IOREGSEL Register with an 8-bit value that specifies the IOAPIC register (address offset in Table 3.2) to be accessed."

Quoted 7 lines
Quoted 5 lines

But the 'vioapic_write()' function does not consider the 'length' argument and always copies 4 Bytes from the unsigned long 'val' argument into the virtual 32-Bit IOREGSEL register. In the error case I've seen, 'length' was 1 and 'val' was 0xffff8300bb0cf801 and the IOAPIC version register with address offset 0x01 was not read correctly.

That looks suspiciously like a Xen pointer, not a plausible val.

Considering length is 1, I'd assume this is a Xen pointer with the low 8 bits overwritten with the actual value to be written out.

Quoted 3 lines

Irrespective, it is an error for the guest to issue anything other than a 4 byte write into the IOREGSEL field, so we ought to be rejecting length-1 accesses.

With what the referred to data sheet text says in mind I'm not sure we shouldn't rather support 1-byte writes here. It specifically also says "The IOWIN Register must be accessed as a Dword quantity", so the same relaxation should not be done there.

Even checking much newer data sheets (ICH10, C600) they still describe the register as an 8-bit one.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel