ptrace/x86: ptrace_write_dr7() should create bp if !disabled
authorOleg Nesterov <[email protected]>
Mon, 8 Jul 2013 23:01:01 +0000 (16:01 -0700)
committerLinus Torvalds <[email protected]>
Tue, 9 Jul 2013 17:33:26 +0000 (10:33 -0700)
Commit 24f1e32c60c4 ("hw-breakpoints: Rewrite the hw-breakpoints layer
on top of perf events") introduced the minor regression.  Before this
commit

PTRACE_POKEUSER DR7, enableDR0
PTRACE_POKEUSER DR0, address

was perfectly valid, now PTRACE_POKEUSER(DR7) fails if DR0 was not
previously initialized by PTRACE_POKEUSER(DR0).

Change ptrace_write_dr7() to do ptrace_register_breakpoint(addr => 0) if
!bp && !disabled.

This fixes watchpoint-zeroaddr from ptrace-tests, see

    https://bugzilla.redhat.com/show_bug.cgi?id=660204.

Signed-off-by: Oleg Nesterov <[email protected]>
Reported-by: Jan Kratochvil <[email protected]>
Acked-by: Frederic Weisbecker <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Michael Neuling <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Paul Mundt <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Prasad <[email protected]>
Cc: Russell King <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
arch/x86/kernel/ptrace.c

index 052636801b41a67deef5633de2a41853fd7bf825..5c387b3dce3f9ebccf22ca1c4b01513e95e96f5a 100644 (file)
@@ -670,13 +670,16 @@ restore:
                if (!bp) {
                        if (disabled)
                                continue;
-                       /*
-                        * We should have at least an inactive breakpoint at
-                        * this slot. It means the user is writing dr7 without
-                        * having written the address register first.
-                        */
-                       rc = -EINVAL;
-                       break;
+
+                       bp = ptrace_register_breakpoint(tsk,
+                                       len, type, 0, disabled);
+                       if (IS_ERR(bp)) {
+                               rc = PTR_ERR(bp);
+                               break;
+                       }
+
+                       thread->ptrace_bps[i] = bp;
+                       continue;
                }
 
                rc = ptrace_modify_breakpoint(bp, len, type, disabled);