Skip to content

Commit cb05143

Browse files
Peter ZijlstraKAGA-KOKO
authored andcommitted
x86/debug: Fix DR_STEP vs ptrace_get_debugreg(6)
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 <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Kyle Huey <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a195f3d commit cb05143

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

arch/x86/kernel/traps.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,10 +937,13 @@ static __always_inline void exc_debug_user(struct pt_regs *regs,
937937
instrumentation_begin();
938938

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

945948
/*
946949
* The SDM says "The processor clears the BTF flag when it

0 commit comments

Comments
 (0)