Re: [RFC][PATCH 4/7] x86/debug: Move historical SYSENTER junk into exc_debug_kernel()
From: peterz
Date: Thu Aug 20 2020 - 14:20:40 EST
On Thu, Aug 20, 2020 at 09:43:15AM -0700, Andy Lutomirski wrote:
> I’ve lost track of how many bugs QEMU and KVM have in this space.
> Let’s keep it as a warning, but a bug. But let’s get rid of the
> totally bogus TIF_SINGLESTEP manipulation.
OK, I've shuffled the series around to fix that ordering problem in
patch 4 and added the below patch at the end.
Although I'm not entirely sure it actually leaks a #DB or just wrecks
the state.. *shrug*.
---
Subject: x86/debug: Remove the historical junk
From: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Date: Thu Aug 20 18:28:37 CEST 2020
Suggested-by: Brian Gerst <brgerst@xxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
---
arch/x86/kernel/traps.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -839,22 +839,18 @@ static __always_inline void exc_debug_ke
goto out;
/*
- * Reload dr6, the notifier might have changed it.
+ * The kernel doesn't use TF single-step outside of:
+ *
+ * - Kprobes, consumed through kprobe_debug_handler()
+ * - KGDB, consumed through notify_debug()
+ *
+ * So if we get here with DR_STEP set, something is wonky.
+ *
+ * A known way to trigger this is through QEMU's GDB stub,
+ * which leaks #DB into the guest and causes IST recursion.
*/
- dr6 = current->thread.debugreg6;
-
- if (WARN_ON_ONCE(dr6 & DR_STEP)) {
- /*
- * Historical junk that used to handle SYSENTER single-stepping.
- * This should be unreachable now. If we survive for a while
- * without anyone hitting this warning, we'll turn this into
- * an oops.
- */
- dr6 &= ~DR_STEP;
- set_thread_flag(TIF_SINGLESTEP);
+ if (WARN_ON_ONCE(current->thread.debugreg6 & DR_STEP))
regs->flags &= ~X86_EFLAGS_TF;
- }
-
out:
instrumentation_end();
idtentry_exit_nmi(regs, irq_state);