64fe61f
x86/HVM: avoid reading ioreq state more than once
64fe61f
64fe61f
Otherwise, especially when the compiler chooses to translate the
64fe61f
switch() to a jump table, unpredictable behavior (and in the jump table
64fe61f
case arbitrary code execution) can result.
64fe61f
64fe61f
This is XSA-166.
64fe61f
64fe61f
Signed-off-by: Jan Beulich <jbeulich@suse.com>
64fe61f
Acked-by: Ian Campbell <ian.campbell@citrix.com>
64fe61f
64fe61f
--- a/xen/arch/x86/hvm/hvm.c
64fe61f
+++ b/xen/arch/x86/hvm/hvm.c
64fe61f
@@ -460,7 +460,10 @@ static bool_t hvm_wait_for_io(struct hvm
64fe61f
 {
64fe61f
     while ( sv->pending )
64fe61f
     {
64fe61f
-        switch ( p->state )
64fe61f
+        unsigned int state = p->state;
64fe61f
+
64fe61f
+        rmb();
64fe61f
+        switch ( state )
64fe61f
         {
64fe61f
         case STATE_IOREQ_NONE:
64fe61f
             /*
64fe61f
@@ -471,18 +474,15 @@ static bool_t hvm_wait_for_io(struct hvm
64fe61f
             hvm_io_assist(sv, ~0ul);
64fe61f
             break;
64fe61f
         case STATE_IORESP_READY: /* IORESP_READY -> NONE */
64fe61f
-            rmb(); /* see IORESP_READY /then/ read contents of ioreq */
64fe61f
             p->state = STATE_IOREQ_NONE;
64fe61f
             hvm_io_assist(sv, p->data);
64fe61f
             break;
64fe61f
         case STATE_IOREQ_READY:  /* IOREQ_{READY,INPROCESS} -> IORESP_READY */
64fe61f
         case STATE_IOREQ_INPROCESS:
64fe61f
-            wait_on_xen_event_channel(sv->ioreq_evtchn,
64fe61f
-                                      (p->state != STATE_IOREQ_READY) &&
64fe61f
-                                      (p->state != STATE_IOREQ_INPROCESS));
64fe61f
+            wait_on_xen_event_channel(sv->ioreq_evtchn, p->state != state);
64fe61f
             break;
64fe61f
         default:
64fe61f
-            gdprintk(XENLOG_ERR, "Weird HVM iorequest state %d.\n", p->state);
64fe61f
+            gdprintk(XENLOG_ERR, "Weird HVM iorequest state %u\n", state);
64fe61f
             sv->pending = 0;
64fe61f
             domain_crash(sv->vcpu->domain);
64fe61f
             return 0; /* bail */