x86/HVM: guard against emulator driving ioreq state in weird ways
authorJan Beulich <jbeulich@suse.com>
Tue, 8 May 2018 17:12:56 +0000 (18:12 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 8 May 2018 17:13:13 +0000 (18:13 +0100)
commit92938e5d149669033aecdfb3d1396948d49d1887
tree2ec30eee6932726d4bdbdac5429c53fb7a83b842
parent14c3f68a57361f20be33ec3848f83d8636a0d34e
x86/HVM: guard against emulator driving ioreq state in weird ways

In the case where hvm_wait_for_io() calls wait_on_xen_event_channel(),
p->state ends up being read twice in succession: once to determine that
state != p->state, and then again at the top of the loop.  This gives a
compromised emulator a chance to change the state back between the two
reads, potentially keeping Xen in a loop indefinitely.

Instead:
* Read p->state once in each of the wait_on_xen_event_channel() tests,
* re-use that value the next time around,
* and insist that the states continue to transition "forward" (with the
  exception of the transition to STATE_IOREQ_NONE).

This is XSA-262.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
xen/arch/x86/hvm/ioreq.c