diff options
author | Chen Zhongjin <chenzhongjin@huawei.com> | 2022-08-01 11:37:19 +0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-08-17 14:24:13 +0200 |
commit | a1edb85e60fdab1e14db63ae8af8db3f0d798fb6 (patch) | |
tree | ccd288f033e7467cbd216e569aee80d2508ed1ed /kernel | |
parent | 533a06858b01e0142e891807efa8ce7d3a01f126 (diff) | |
download | linux-stable-a1edb85e60fdab1e14db63ae8af8db3f0d798fb6.tar.gz linux-stable-a1edb85e60fdab1e14db63ae8af8db3f0d798fb6.tar.bz2 linux-stable-a1edb85e60fdab1e14db63ae8af8db3f0d798fb6.zip |
kprobes: Forbid probing on trampoline and BPF code areas
[ Upstream commit 28f6c37a2910f565b4f5960df52b2eccae28c891 ]
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: 5b485629ba0d ("kprobes, extable: Identify kprobes trampolines as kernel text area")
Fixes: 74451e66d516 ("bpf: make jited programs visible in traces")
Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Link: https://lore.kernel.org/r/20220801033719.228248-1-chenzhongjin@huawei.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/kprobes.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 2ef90d15699f..3a3c0166bd1f 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1559,7 +1559,8 @@ static int check_kprobe_address_safe(struct kprobe *p, preempt_disable(); /* Ensure it is not in reserved area nor out of text */ - if (!kernel_text_address((unsigned long) p->addr) || + if (!(core_kernel_text((unsigned long) p->addr) || + is_module_text_address((unsigned long) p->addr)) || within_kprobe_blacklist((unsigned long) p->addr) || jump_label_text_reserved(p->addr, p->addr) || static_call_text_reserved(p->addr, p->addr) || |