Skip to content

Commit 0e7e5e7

Browse files
seehearfeelopsiff
authored andcommitted
LoongArch: kprobes: Fix handling of fatal unrecoverable recursions
[ Upstream commit 1c856e158fd34ef2c4475a81c1dc386329989938 ] KPROBE_HIT_SS and KPROBE_REENTER are two types of fatal recursions that can not be safely recovered in kprobes. KPROBE_HIT_SS means that a kprobe is hit during single-stepping. At this point, the architecture-specific single-step context is already active. Nested single-stepping would corrupt the state, as the kprobe control block (kcb) and hardware registers cannot safely store multiple levels of stepping state. KPROBE_REENTER means that a third-level recursion occurs when a probe is hit while the system is already handling a nested probe (second- level). The kcb only provides a single slot (prev_kprobe) to backup the state. When a third probe is hit, there is no more space to save the state without corrupting the first-level backup. Kprobes work by replacing instructions with breakpoints. In order to execute the original instruction and continue, it must be moved to a temporary "single-step" slot. Since there is no backup space left to set up this slot safely, the CPU would be forced to return to the same original breakpoint address, triggering an endless loop. Currently, the code only prints a warning and returns. This leads to an infinite re-entry loop as the CPU repeatedly hits the same trap and a "stuck" CPU core because preemption was disabled at the start of the handler and never re-enabled in this early return path. Fix the logic by: 1. Merging KPROBE_HIT_SS and KPROBE_REENTER cases, as both represent fatal recursions that cannot be safely recovered. 2. Replacing WARN_ON_ONCE() with BUG() to terminate the system. This aligns LoongArch with other architectures (x86, arm64, riscv) and prevents stack overflow while providing diagnostic information. Fixes: 6d4cc40 ("LoongArch: Add kprobes support") Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit 105c6a594b3f5cdbf5632ae8819c414e0f78f890) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 6715e8b commit 0e7e5e7

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

arch/loongarch/kernel/kprobes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,16 @@ static bool reenter_kprobe(struct kprobe *p, struct pt_regs *regs,
184184
struct kprobe_ctlblk *kcb)
185185
{
186186
switch (kcb->kprobe_status) {
187-
case KPROBE_HIT_SS:
188187
case KPROBE_HIT_SSDONE:
189188
case KPROBE_HIT_ACTIVE:
190189
kprobes_inc_nmissed_count(p);
191190
setup_singlestep(p, regs, kcb, 1);
192191
break;
192+
case KPROBE_HIT_SS:
193193
case KPROBE_REENTER:
194194
pr_warn("Failed to recover from reentered kprobes.\n");
195195
dump_kprobe(p);
196-
WARN_ON_ONCE(1);
196+
BUG();
197197
break;
198198
default:
199199
WARN_ON(1);

0 commit comments

Comments
 (0)