x86: Refine checks in #DB handler for faulting conditions
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 19 Jun 2018 14:11:52 +0000 (15:11 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 22 Jun 2018 15:38:39 +0000 (16:38 +0100)
commite5fe66a03b72284cab31cdf9ede029330f72663a
tree58a324b20f7fc61d4644810048c2c15c2435ad40
parentc4dd2dc622b253fc78d8ba8550d86d4891b071dc
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>
Gbp-Pq: Name x86-refine-checks-in-db-handler-for-faul.patch
xen/arch/x86/traps.c