]> xenbits.xensource.com Git - qemu-xen-traditional.git/commitdiff
qemu: ioport_read, ioport_write: be defensive about 32-bit addresses
authorIan Jackson <ian.jackson@eu.citrix.com>
Mon, 14 Nov 2016 17:19:46 +0000 (17:19 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Wed, 7 Dec 2016 16:54:29 +0000 (16:54 +0000)
On x86, ioport addresses are 16-bit.  That these functions take 32-bit
arguments is a mistake.  Changing the argument type to 16-bit will
discard the top bits of any erroneous values from elsewhere in qemu.

Also, check just before use that the value is in range.  (This turns
an ill-advised change to MAX_IOPORTS into a possible guest crash
rather than a privilege escalation vulnerability.)

And, in the Xen ioreq processor, clamp incoming ioport addresses to
16-bit values.  Xen will never write >16-bit values but the guest may
have access to the ioreq ring.  We want to defend the rest of the qemu
code from wrong values.

This is XSA-199.

Reported-by: yanghongke <yanghongke@huawei.com>
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
(cherry picked from commit b669e922b37b8957248798a5eb7aa96a666cd3fe)
(cherry picked from commit 095261a9ad5c31b9ed431f8382e8aa223089c85b)
(cherry picked from commit 18858e28bb6bae83ddcf413995b2e68c4c7ae03d)
(cherry picked from commit a7fd3717d99944530b04130f050e83402e64afed)

i386-dm/helper2.c
vl.c

index 8926e0a13d0b9d3b06ce9747fde193ffc1756e0b..e078f1114158f9d437bba51555ccf3da3b819a29 100644 (file)
@@ -378,6 +378,7 @@ static void cpu_ioreq_pio(CPUState *env, ioreq_t *req)
         fprintf(stderr, "PIO: bad size (%u)\n", req->size);
         exit(-1);
     }
+    req->addr &= 0x0ffffU;
 
     if (req->dir == IOREQ_READ) {
         if (!req->data_is_ptr) {
diff --git a/vl.c b/vl.c
index 5f6db2ff1e7a300fe4cce0286dfd92fef80347e0..883ce4f7ac4dbdfef4fa2aa8907efbd5081875b9 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -52,6 +52,7 @@
 
 #include <xen/hvm/hvm_info_table.h>
 
+#include <assert.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <signal.h>
@@ -290,26 +291,30 @@ PicState2 *isa_pic;
 static IOPortReadFunc default_ioport_readb, default_ioport_readw, default_ioport_readl;
 static IOPortWriteFunc default_ioport_writeb, default_ioport_writew, default_ioport_writel;
 
-static uint32_t ioport_read(int index, uint32_t address)
+static uint32_t ioport_read(int index, uint16_t address)
 {
     static IOPortReadFunc *default_func[3] = {
         default_ioport_readb,
         default_ioport_readw,
         default_ioport_readl
     };
+    if (address >= MAX_IOPORTS)
+        abort();
     IOPortReadFunc *func = ioport_read_table[index][address];
     if (!func)
         func = default_func[index];
     return func(ioport_opaque[address], address);
 }
 
-static void ioport_write(int index, uint32_t address, uint32_t data)
+static void ioport_write(int index, uint16_t address, uint32_t data)
 {
     static IOPortWriteFunc *default_func[3] = {
         default_ioport_writeb,
         default_ioport_writew,
         default_ioport_writel
     };
+    if (address >= MAX_IOPORTS)
+        abort();
     IOPortWriteFunc *func = ioport_write_table[index][address];
     if (!func)
         func = default_func[index];