ARM: Don't oops when userspace executes kgdb break instructions.
PATCH 1/1 ARM: Don't oops when userspace executes kgdb break instructions.
Don't break into kgdb when userspace executes the kernel break instructions (KGDB_BREAKINST and KGDB_COMPILED_BREAK). The kernel will oops in kgdb_handle_exception.
Signed-off-by Omar Sandoval <[email protected]>
---
The following program will immediately cause a kernel oops:
.globl _start_start:
udf #65006 @ KGDB_BREAKINST
arch/arm/kernel/kgdb.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm/kernel/kgdb.c +4 -0
@@ -160,12 +160,16 @@ static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int instr)static struct undef_hook kgdb_brkpt_hook = { .instr_mask =0xffffffff , .instr_val =KGDB_BREAKINST , + .cpsr_mask =MODE_MASK , + .cpsr_val =SVC_MODE , .fn = kgdb_brk_fn };static struct undef_hook kgdb_compiled_brkpt_hook = { .instr_mask =0xffffffff , .instr_val =KGDB_COMPILED_BREAK , + .cpsr_mask =MODE_MASK , + .cpsr_val =SVC_MODE , .fn = kgdb_compiled_brk_fn };
Signature · 1 line
2.0.1
Quoted 37 lines · Omar Sandoval
Don't break into kgdb when userspace executes the kernel break instructions (
KGDB_BREAKINSTandKGDB_COMPILED_BREAK). The kernel will oops inkgdb_handle_exception.Signed-off-by Omar Sandoval <[email protected]>---
The following program will immediately cause a kernel oops:
.globl_start_start:udf #65006 @ KGDB_BREAKINSTarch/arm/kernel/kgdb.c | 4 ++++ 1 file changed, 4 insertions(+)arch/arm/kernel/kgdb.c +4
-0@@ -160,12 +160,16 @@ static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int instr)static struct undef_hook kgdb_brkpt_hook = { .instr_mask =0xffffffff , .instr_val =KGDB_BREAKINST , + .cpsr_mask =MODE_MASK , + .cpsr_val =SVC_MODE , .fn = kgdb_brk_fn };static struct undef_hook kgdb_compiled_brkpt_hook = { .instr_mask =0xffffffff , .instr_val =KGDB_COMPILED_BREAK , + .cpsr_mask =MODE_MASK , + .cpsr_val =SVC_MODE , .fn = kgdb_compiled_brk_fn };Signature · 1 line
2.0.1
Signature · 14 lines
Following up/clarifying this. This only happens when the kernel is compiled with CONFIG_KGDB. When a userspace program executes KGDB_BREAKINST or KGDB_COMPILED_BREAK, the undef_hook for kgdb catches it. The reason in kdb_stub defaults to KDB_REASON_OOPS, so the bug manifests itself as an oops caused by userspace (a better description for the patch would be "Don't enter KGDB when userspace executes kgdb break instructions"). This means that a buggy/malicious program can take down the system just by executing an instruction. ARM64 might have the same issue, but I don't have a board to test that on. I verified that breaking normally (e.g., with kgdbwait or through /proc/sysrq-trigger) still works. ? Omar