]> xenbits.xensource.com Git - xen.git/commitdiff
x86/HVM: avoid reading ioreq state more than once
authorJan Beulich <jbeulich@suse.com>
Thu, 17 Dec 2015 13:31:28 +0000 (14:31 +0100)
committerJan Beulich <jbeulich@suse.com>
Thu, 17 Dec 2015 13:31:28 +0000 (14:31 +0100)
Otherwise, especially when the compiler chooses to translate the
switch() to a jump table, unpredictable behavior (and in the jump table
case arbitrary code execution) can result.

This is XSA-166.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
master commit: b452430a4cdfc801fa4bc391aed7522365e1deb6
master date: 2015-12-17 14:22:46 +0100

xen/arch/x86/hvm/hvm.c

index 321f8bf544f3c10175324b713630e4d65c482d6f..f3f6c61ae202840ae33324395aa61986710f2e40 100644 (file)
@@ -348,6 +348,7 @@ void hvm_migrate_pirqs(struct vcpu *v)
 void hvm_do_resume(struct vcpu *v)
 {
     ioreq_t *p;
+    unsigned int state;
 
     check_wakeup_from_wait();
 
@@ -358,9 +359,10 @@ void hvm_do_resume(struct vcpu *v)
     if ( !(p = get_ioreq(v)) )
         goto check_inject_trap;
 
-    while ( p->state != STATE_IOREQ_NONE )
+    while ( (state = p->state) != STATE_IOREQ_NONE )
     {
-        switch ( p->state )
+        rmb();
+        switch ( state )
         {
         case STATE_IORESP_READY: /* IORESP_READY -> NONE */
             hvm_io_assist(p);
@@ -368,11 +370,10 @@ void hvm_do_resume(struct vcpu *v)
         case STATE_IOREQ_READY:  /* IOREQ_{READY,INPROCESS} -> IORESP_READY */
         case STATE_IOREQ_INPROCESS:
             wait_on_xen_event_channel(v->arch.hvm_vcpu.xen_port,
-                                      (p->state != STATE_IOREQ_READY) &&
-                                      (p->state != STATE_IOREQ_INPROCESS));
+                                      p->state != state);
             break;
         default:
-            gdprintk(XENLOG_ERR, "Weird HVM iorequest state %d.\n", p->state);
+            gdprintk(XENLOG_ERR, "Weird HVM iorequest state %u\n", state);
             domain_crash(v->domain);
             return; /* bail */
         }