Skip to content

Commit 20df600

Browse files
wildea01gregkh
authored andcommitted
arm64: debug: Ensure debug handlers check triggering exception level
commit 6bd2885 upstream. Debug exception handlers may be called for exceptions generated both by user and kernel code. In many cases, this is checked explicitly, but in other cases things either happen to work by happy accident or they go slightly wrong. For example, executing 'brk #4' from userspace will enter the kprobes code and be ignored, but the instruction will be retried forever in userspace instead of delivering a SIGTRAP. Fix this issue in the most stable-friendly fashion by simply adding explicit checks of the triggering exception level to all of our debug exception handlers. Cc: <stable@vger.kernel.org> Reviewed-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a930f8c commit 20df600

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

arch/arm64/kernel/kgdb.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,22 +215,31 @@ int kgdb_arch_handle_exception(int exception_vector, int signo,
215215

216216
static int kgdb_brk_fn(struct pt_regs *regs, unsigned int esr)
217217
{
218+
if (user_mode(regs))
219+
return DBG_HOOK_ERROR;
220+
218221
kgdb_handle_exception(1, SIGTRAP, 0, regs);
219-
return 0;
222+
return DBG_HOOK_HANDLED;
220223
}
221224

222225
static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr)
223226
{
227+
if (user_mode(regs))
228+
return DBG_HOOK_ERROR;
229+
224230
compiled_break = 1;
225231
kgdb_handle_exception(1, SIGTRAP, 0, regs);
226232

227-
return 0;
233+
return DBG_HOOK_HANDLED;
228234
}
229235

230236
static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr)
231237
{
238+
if (user_mode(regs))
239+
return DBG_HOOK_ERROR;
240+
232241
kgdb_handle_exception(1, SIGTRAP, 0, regs);
233-
return 0;
242+
return DBG_HOOK_HANDLED;
234243
}
235244

236245
static struct break_hook kgdb_brkpt_hook = {

0 commit comments

Comments
 (0)