]> Git Repo - linux.git/commitdiff
x86/debug: Fix DR_STEP vs ptrace_get_debugreg(6)
authorPeter Zijlstra <[email protected]>
Tue, 27 Oct 2020 18:33:30 +0000 (19:33 +0100)
committerThomas Gleixner <[email protected]>
Tue, 27 Oct 2020 22:15:24 +0000 (23:15 +0100)
Commit d53d9bc0cf78 ("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: d53d9bc0cf78 ("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]
arch/x86/kernel/traps.c

index 32b2d39272e0375980c7e02857584ec6331a8364..e19df6cde35d1d5d7c6a1ffb09e2d26cc39d1b95 100644 (file)
@@ -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
This page took 0.05942 seconds and 4 git commands to generate.