Skip to content

Commit 8bb0dae

Browse files
VincentZWCpaul-walmsley-sifive
authored andcommitted
riscv: Correct the handling of unexpected ebreak in do_trap_break()
For the kernel space, all ebreak instructions are determined at compile time because the kernel space debugging module is currently unsupported. Hence, it should be treated as a bug if an ebreak instruction which does not belong to BUG_TRAP_TYPE_WARN or BUG_TRAP_TYPE_BUG is executed in kernel space. For the userspace, debugging module or user problem may intentionally insert an ebreak instruction to trigger a SIGTRAP signal. To approach the above two situations, the do_trap_break() will direct the BUG_TRAP_TYPE_NONE ebreak exception issued in kernel space to die() and will send a SIGTRAP to the trapped process only when the ebreak is in userspace. Signed-off-by: Vincent Chen <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> [[email protected]: fixed checkpatch issue] Signed-off-by: Paul Walmsley <[email protected]>
1 parent e0c0fc1 commit 8bb0dae

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

arch/riscv/kernel/traps.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ asmlinkage void do_trap_break(struct pt_regs *regs)
130130
type = report_bug(regs->sepc, regs);
131131
switch (type) {
132132
#ifdef CONFIG_GENERIC_BUG
133-
case BUG_TRAP_TYPE_NONE:
134-
break;
135133
case BUG_TRAP_TYPE_WARN:
136134
regs->sepc += get_break_insn_length(regs->sepc);
137135
return;
@@ -140,8 +138,10 @@ asmlinkage void do_trap_break(struct pt_regs *regs)
140138
default:
141139
die(regs, "Kernel BUG");
142140
}
141+
} else {
142+
force_sig_fault(SIGTRAP, TRAP_BRKPT,
143+
(void __user *)(regs->sepc));
143144
}
144-
force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)(regs->sepc));
145145
}
146146

147147
#ifdef CONFIG_GENERIC_BUG

0 commit comments

Comments
 (0)