x86: Refine checks in #DB handler for faulting conditions
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 28 Jun 2018 07:04:20 +0000 (09:04 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 28 Jun 2018 07:04:20 +0000 (09:04 +0200)
commit17bf51297220dcd74da29de99320b6b1c72d1fa5
treef3e115c3b6498af2f1f78bc735f4348e60b8e759
parent17608703c65bf080b0a9f024f9b370872b9f2c05
x86: Refine checks in #DB handler for faulting conditions

One of the fix for XSA-260 (c/s 75d6828bc2 "x86/traps: Fix handling of #DB
exceptions in hypervisor context") added some safety checks to help avoid
livelocks of #DB faults.

While a General Detect #DB exception does have fault semantics, hardware
clears %dr7.gd on entry to the handler, meaning that it is actually safe to
return to.  Furthermore, %dr6.gd is guest controlled and sticky (never cleared
by hardware).  A malicious PV guest can therefore trigger the fatal_trap() and
crash Xen.

Instruction breakpoints are more tricky.  The breakpoint match bits in %dr6
are not sticky, but the Intel manual warns that they may be set for
non-enabled breakpoints, so add a breakpoint enabled check.

Beyond that, because of the restriction on the linear addresses PV guests can
set, and the fault (rather than trap) nature of instruction breakpoints
(i.e. can't be deferred by a MovSS shadow), there should be no way to
encounter an instruction breakpoint in Xen context.  However, for extra
robustness, deal with this situation by clearing the breakpoint configuration,
rather than crashing.

This is XSA-265

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/traps.c