From: "tip-bot2 for Chen Zhongjin" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Chen Zhongjin <chenzhongjin@huawei.com>,
Ingo Molnar <mingo@kernel.org>,
"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: perf/urgent] kprobes: Forbid probing on trampoline and BPF code areas
Date: Tue, 02 Aug 2022 09:55:35 -0000 [thread overview]
Message-ID: <165943413527.15455.6314879465363056432.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20220801033719.228248-1-chenzhongjin@huawei.com>
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: 28f6c37a2910f565b4f5960df52b2eccae28c891
Gitweb: https://git.kernel.org/tip/28f6c37a2910f565b4f5960df52b2eccae28c891
Author: Chen Zhongjin <chenzhongjin@huawei.com>
AuthorDate: Mon, 01 Aug 2022 11:37:19 +08:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 02 Aug 2022 11:47:29 +02:00
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: 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
---
kernel/kprobes.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index f214f8c..80697e5 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1560,7 +1560,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) ||
prev parent reply other threads:[~2022-08-02 9:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-01 3:37 [PATCH v3] kprobes: Forbid probing on trampoline and bpf prog Chen Zhongjin
2022-08-01 20:41 ` Jiri Olsa
2022-08-01 20:51 ` Steven Rostedt
2022-08-01 23:29 ` Masami Hiramatsu
2022-08-02 9:06 ` Jiri Olsa
2022-08-02 12:28 ` Chen Zhongjin
2022-08-01 23:28 ` Masami Hiramatsu
2022-08-02 9:55 ` tip-bot2 for Chen Zhongjin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=165943413527.15455.6314879465363056432.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=chenzhongjin@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®