linux/arch/loongarch/kernel
Jérémy Jean 72ce4b2467 LoongArch: Avoid preempt count underflow without probe
LoongArch uses break 11 for the breakpoint placed after an instruction
that Kprobes executes out of line. Since userspace can issue the same
break instruction, do_bp() can reach kprobe_singlestep_handler() when
there is no current probe.

The handler actually returns false in this case, but it first calls
preempt_enable_no_resched(). The corresponding preempt_disable() is done
by kprobe_breakpoint_handler() on a real Kprobe hit, so it has not run
here. As a result, an ordinary userspace breakpoint (code 11) underflows
the current task's preempt count.

This also makes in_interrupt() return true until the task schedules. One
visible consequence is the socket cgroup attribution: cgroup_sk_alloc()
treats the allocation as interrupt context and assigns the socket to the
root cgroup. A socket opened from the SIGTRAP handler can then avoid a
BPF_CGROUP_INET_SOCK_CREATE policy attached to the task's own cgroup.

Return as soon as kprobe_running() reports no active probe.

The same check has appeared in [PATCH v10 2/4] of the original LoongArch
Kprobes series, but was dropped before the feature reached mainline.

Cc: stable@vger.kernel.org
Fixes: 6d4cc40fb5 ("LoongArch: Add kprobes support")
Link: https://lore.kernel.org/loongarch/1670575981-14389-3-git-send-email-yangtiezhu@loongson.cn/
Assisted-by: Codex:gpt-5
Signed-off-by: Jérémy Jean <Jeremy.Jean@oss.cyber.gouv.fr>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2026-09-04 21:44:43 +08:00
..
.gitignore
access-helper.h LoongArch: Add exception/interrupt handling 2022-06-03 20:09:28 +08:00
acpi.c LoongArch: Fix acpi_package_ids[] array overflow 2026-08-17 22:07:05 +08:00
alternative.c LoongArch: Fix build warnings about export.h 2025-06-26 20:07:18 +08:00
asm-offsets.c LoongArch: Add THREAD_INFO_IN_TASK implementation 2026-06-25 13:03:47 +08:00
cacheinfo.c LoongArch: Correct the cacheinfo sharing information 2025-01-25 18:51:33 +08:00
cpu-probe.c LoongArch: Define instruction formats for AM{SWAP/ADD}.{B/H} and DBAR 2026-04-22 15:45:13 +08:00
crash_dump.c LoongArch: Add kdump support 2022-10-12 16:36:19 +08:00
dma.c dma-mapping: Add helpers for dma_range_map bounds 2024-04-26 12:07:24 +02:00
efi-header.S LoongArch: Adjust boot & setup for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
efi.c efi: Support EDID information 2025-12-16 14:40:51 +01:00
elf.c LoongArch: Fix build warnings about export.h 2025-06-26 20:07:18 +08:00
entry.S LoongArch: Add THREAD_INFO_IN_TASK implementation 2026-06-25 13:03:47 +08:00
env.c LoongArch: Fix missing NULL checks for kstrdup() 2026-03-26 14:29:08 +08:00
fpu.S LoongArch: Align FPU register state to 32 bytes 2026-04-22 15:45:11 +08:00
ftrace_dyn.c LoongArch: ftrace: Use RCU in all users of __module_text_address(). 2025-03-10 11:54:45 +01:00
ftrace.c LoongArch/ftrace: Add basic support 2022-12-14 08:41:53 +08:00
genex.S LoongArch: Move __arch_cpu_idle() to .cpuidle.text section 2025-05-14 22:17:52 +08:00
head.S LoongArch: Add THREAD_INFO_IN_TASK implementation 2026-06-25 13:03:47 +08:00
hw_breakpoint.c LoongArch: Change 8 to 14 for LOONGARCH_MAX_{BRP,WRP} 2025-01-26 21:49:59 +08:00
idle.c LoongArch: Fix idle VS timer enqueue 2025-02-13 12:02:35 +08:00
image-vars.h sysfb: Replace screen_info with sysfb_primary_display 2025-12-16 14:12:44 +01:00
inst.c LoongArch: Batch the icache maintenance for jump_label 2026-04-22 15:45:13 +08:00
irq.c LoongArch: Override arch_dynirq_lower_bound to reserve LPC IRQs 2026-03-26 16:15:03 +01:00
jump_label.c LoongArch: Batch the icache maintenance for jump_label 2026-04-22 15:45:13 +08:00
kdebugfs.c LoongArch: Add debugfs entries to switch SFB/TSO state 2025-01-26 21:49:59 +08:00
kexec_efi.c LoongArch: kexec: Initialize the kexec_buf structure 2025-11-10 08:37:07 +08:00
kexec_elf.c LoongArch: kexec: Initialize the kexec_buf structure 2025-11-10 08:37:07 +08:00
kfpu.c LoongArch: Fix build warnings about export.h 2025-06-26 20:07:18 +08:00
kgdb.c LoongArch: Fix oops during single-step debugging 2026-07-23 22:27:30 +08:00
kprobes.c LoongArch: Avoid preempt count underflow without probe 2026-09-04 21:44:43 +08:00
lbt.S LoongArch: Handle fp, lsx, lasx and lbt assembly symbols 2025-04-26 09:58:12 +08:00
machine_kexec_file.c LoongArch: kexec_file: Use crash_prepare_headers() helper to simplify code 2026-06-30 18:49:06 +03:00
machine_kexec.c LoongArch: Fix address space mismatch in kexec command line lookup 2026-07-23 22:27:30 +08:00
Makefile LoongArch: Add ELF binary support for kexec_file 2025-10-02 22:39:08 +08:00
Makefile.syscalls LoongArch: Wire up memfd_secret system call 2026-02-10 19:31:12 +08:00
mcount_dyn.S LoongArch: Refactor register restoration in ftrace_common_return 2025-12-31 15:19:20 +08:00
mcount.S fgraph: Replace fgraph_ret_regs with ftrace_regs 2024-12-26 10:50:02 -05:00
mem.c LoongArch: Consolidate max_pfn & max_low_pfn calculation 2025-11-10 08:37:06 +08:00
module-sections.c LoongArch: Use generic cmp_int() instead of custom cmp_3way() 2026-08-17 22:07:14 +08:00
module.c LoongArch: Adjust module loader for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
numa.c LoongArch: remove redundant numa_nodes_parsed node_set() 2026-07-03 11:16:27 +03:00
paravirt.c LoongArch: KVM: Make vcpu_is_preempted() as a macro rather than function 2026-04-09 18:56:36 +08:00
perf_event.c LoongArch: Fix PMU counter allocation for mixed-type event groups 2026-01-17 10:56:43 +08:00
perf_regs.c LoongArch: Add perf events support 2022-10-12 16:36:14 +08:00
proc.c LoongArch: Define instruction formats for AM{SWAP/ADD}.{B/H} and DBAR 2026-04-22 15:45:13 +08:00
process.c LoongArch: Add THREAD_INFO_IN_TASK implementation 2026-06-25 13:03:47 +08:00
ptrace.c LoongArch: Adjust process management for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
relocate_kernel.S LoongArch: Make relocate_new_kernel_size be a .quad value 2025-08-03 22:49:47 +08:00
relocate.c LoongArch: Add THREAD_INFO_IN_TASK implementation 2026-06-25 13:03:47 +08:00
reset.c LoongArch: Fix idle VS timer enqueue 2025-02-13 12:02:35 +08:00
rethook_trampoline.S LoongArch: Do not save/restore percpu base register in rethook trampoline 2026-09-04 21:44:43 +08:00
rethook.c LoongArch: Replace kretprobe with rethook 2023-06-29 20:58:44 +08:00
rethook.h LoongArch: Replace kretprobe with rethook 2023-06-29 20:58:44 +08:00
setup.c LoongArch: Move jump_label_init() before parse_early_param() 2026-07-23 22:27:29 +08:00
signal.c LoongArch: vDSO: Emit GNU_EH_FRAME correctly 2026-03-26 14:29:09 +08:00
smp.c LoongArch: Remove unused setup_profiling_timer() function 2026-09-04 21:44:43 +08:00
stacktrace.c LoongArch: Fix unreliable stack for live patching 2025-09-18 19:44:08 +08:00
switch.S LoongArch: Add THREAD_INFO_IN_TASK implementation 2026-06-25 13:03:47 +08:00
syscall.c entry, treewide: Make syscall_enter_from_user_mode[_work]() indicate syscall execution 2026-07-20 20:38:40 +02:00
sysrq.c tty: sysrq: switch sysrq handlers from int to u8 2023-07-25 19:21:03 +02:00
time.c LoongArch: Remove CONFIG_GENERIC_GETTIMEOFDAY ifdeffery 2026-08-10 16:25:22 +02:00
topology.c LoongArch: convert to use arch_cpu_is_hotpluggable() 2023-12-06 12:41:50 +09:00
traps.c LoongArch: Add THREAD_INFO_IN_TASK implementation 2026-06-25 13:03:47 +08:00
unaligned.c LoongArch: Adjust misc routines for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
unwind_guess.c LoongArch: Fix build warnings about export.h 2025-06-26 20:07:18 +08:00
unwind_orc.c LoongArch: Remove some extern variables in source files 2026-02-10 19:31:14 +08:00
unwind_prologue.c LoongArch: Remove some extern variables in source files 2026-02-10 19:31:14 +08:00
unwind.c LoongArch: Set unwind stack type to unknown rather than set error flag 2023-12-09 15:49:15 +08:00
uprobes.c LoongArch: uprobes: Remove redundant code about resume_era 2025-05-14 22:18:10 +08:00
vdso.c LoongArch: vDSO: Explicitly include asm/vdso/vdso.h 2026-03-11 15:12:41 +01:00
vmlinux.lds.S LoongArch: Fix typo "avaliable" in comment of vmlinux.lds.S 2026-09-04 21:44:24 +08:00