1 From 9478f1927e6ef9ef5e1ad761af1c98aa8e40b7f5 Mon Sep 17 00:00:00 2001
2 From: Mark Rutland <mark.rutland@arm.com>
3 Date: Tue, 3 Apr 2018 11:22:51 +0100
4 Subject: arm64: only advance singlestep for user instruction traps
6 From: Mark Rutland <mark.rutland@arm.com>
8 commit 9478f1927e6ef9ef5e1ad761af1c98aa8e40b7f5 upstream.
10 Our arm64_skip_faulting_instruction() helper advances the userspace
11 singlestep state machine, but this is also called by the kernel BRK
12 handler, as used for WARN*().
14 Thus, if we happen to hit a WARN*() while the user singlestep state
15 machine is in the active-no-pending state, we'll advance to the
16 active-pending state without having executed a user instruction, and
17 will take a step exception earlier than expected when we return to
20 Let's fix this by only advancing the state machine when skipping a user
23 Signed-off-by: Mark Rutland <mark.rutland@arm.com>
24 Cc: Andrey Konovalov <andreyknvl@google.com>
25 Cc: Catalin Marinas <catalin.marinas@arm.com>
26 Cc: Will Deacon <will.deacon@arm.com>
27 Signed-off-by: Will Deacon <will.deacon@arm.com>
28 Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
29 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
32 arch/arm64/kernel/traps.c | 3 ++-
33 1 file changed, 2 insertions(+), 1 deletion(-)
35 --- a/arch/arm64/kernel/traps.c
36 +++ b/arch/arm64/kernel/traps.c
37 @@ -304,7 +304,8 @@ void arm64_skip_faulting_instruction(str
38 * If we were single stepping, we want to get the step exception after
39 * we return from the trap.
41 - user_fastforward_single_step(current);
42 + if (user_mode(regs))
43 + user_fastforward_single_step(current);
46 static LIST_HEAD(undef_hook);