Skip to content

Commit

Permalink
x86/debug: Fix DR_STEP vs ptrace_get_debugreg(6)
Browse files Browse the repository at this point in the history
Commit d53d9bc ("x86/debug: Change thread.debugreg6 to
thread.virtual_dr6") changed the semantics of the variable from random
collection of bits, to exactly only those bits that ptrace() needs.

Unfortunately this lost DR_STEP for PTRACE_{BLOCK,SINGLE}STEP.

Furthermore, it turns out that userspace expects DR_STEP to be
unconditionally available, even for manual TF usage outside of
PTRACE_{BLOCK,SINGLE}_STEP.

Fixes: d53d9bc ("x86/debug: Change thread.debugreg6 to thread.virtual_dr6")
Reported-by: Kyle Huey <me@kylehuey.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Kyle Huey <me@kylehuey.com> 
Link: https://lore.kernel.org/r/20201027183330.GM2628@hirez.programming.kicks-ass.net
  • Loading branch information
Peter Zijlstra authored and Thomas Gleixner committed Oct 27, 2020
1 parent a195f3d commit cb05143
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions arch/x86/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,10 +937,13 @@ static __always_inline void exc_debug_user(struct pt_regs *regs,
instrumentation_begin();

/*
* Clear the virtual DR6 value, ptrace() routines will set bits here
* for things it wants signals for.
* Start the virtual/ptrace DR6 value with just the DR_STEP mask
* of the real DR6. ptrace_triggered() will set the DR_TRAPn bits.
*
* Userspace expects DR_STEP to be visible in ptrace_get_debugreg(6)
* even if it is not the result of PTRACE_SINGLESTEP.
*/
current->thread.virtual_dr6 = 0;
current->thread.virtual_dr6 = (dr6 & DR_STEP);

/*
* The SDM says "The processor clears the BTF flag when it
Expand Down

0 comments on commit cb05143

Please sign in to comment.