Skip to content

Commit 28f6c37

Browse files
Chen ZhongjinIngo Molnar
authored andcommitted
kprobes: Forbid probing on trampoline and BPF code areas
kernel_text_address() treats ftrace_trampoline, kprobe_insn_slot and bpf_text_address as valid kprobe addresses - which is not ideal. These text areas are removable and changeable without any notification to kprobes, and probing on them can trigger unexpected behavior: https://lkml.org/lkml/2022/7/26/1148 Considering that jump_label and static_call text are already forbiden to probe, kernel_text_address() should be replaced with core_kernel_text() and is_module_text_address() to check other text areas which are unsafe to kprobe. [ mingo: Rewrote the changelog. ] Fixes: 5b48562 ("kprobes, extable: Identify kprobes trampolines as kernel text area") Fixes: 74451e6 ("bpf: make jited programs visible in traces") Signed-off-by: Chen Zhongjin <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9de1f9c commit 28f6c37

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/kprobes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,8 @@ static int check_kprobe_address_safe(struct kprobe *p,
15601560
preempt_disable();
15611561

15621562
/* Ensure it is not in reserved area nor out of text */
1563-
if (!kernel_text_address((unsigned long) p->addr) ||
1563+
if (!(core_kernel_text((unsigned long) p->addr) ||
1564+
is_module_text_address((unsigned long) p->addr)) ||
15641565
within_kprobe_blacklist((unsigned long) p->addr) ||
15651566
jump_label_text_reserved(p->addr, p->addr) ||
15661567
static_call_text_reserved(p->addr, p->addr) ||

0 commit comments

Comments
 (0)