From: "tip-bot2 for Masami Hiramatsu (Google)" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Qiang Zhang <zzqq0103.hey@gmail.com>,
Jinghao Jia <jinghao7@illinois.edu>,
"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
Ingo Molnar <mingo@kernel.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: x86/urgent] kprobes/x86: Use copy_from_kernel_nofault() to read from unsafe address
Date: Fri, 22 Mar 2024 10:59:19 -0000 [thread overview]
Message-ID: <171110515913.10875.11206445395083365696.tip-bot2@tip-bot2> (raw)
In-Reply-To: <171042945004.154897.2221804961882915806.stgit@devnote2>
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 4e51653d5d871f40f1bd5cf95cc7f2d8b33d063b
Gitweb: https://git.kernel.org/tip/4e51653d5d871f40f1bd5cf95cc7f2d8b33d063b
Author: Masami Hiramatsu (Google) <mhiramat@kernel.org>
AuthorDate: Fri, 15 Mar 2024 00:17:30 +09:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Fri, 22 Mar 2024 11:40:56 +01:00
kprobes/x86: Use copy_from_kernel_nofault() to read from unsafe address
Read from an unsafe address with copy_from_kernel_nofault() in
arch_adjust_kprobe_addr() because this function is used before checking
the address is in text or not. Syzcaller bot found a bug and reported
the case if user specifies inaccessible data area,
arch_adjust_kprobe_addr() will cause a kernel panic.
[ mingo: Clarified the comment. ]
Fixes: cc66bb914578 ("x86/ibt,kprobes: Cure sym+0 equals fentry woes")
Reported-by: Qiang Zhang <zzqq0103.hey@gmail.com>
Tested-by: Jinghao Jia <jinghao7@illinois.edu>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/171042945004.154897.2221804961882915806.stgit@devnote2
---
arch/x86/kernel/kprobes/core.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 091b3ab..d0e49bd 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -373,7 +373,16 @@ out:
kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offset,
bool *on_func_entry)
{
- if (is_endbr(*(u32 *)addr)) {
+ u32 insn;
+
+ /*
+ * Since 'addr' is not guaranteed to be safe to access, use
+ * copy_from_kernel_nofault() to read the instruction:
+ */
+ if (copy_from_kernel_nofault(&insn, (void *)addr, sizeof(u32)))
+ return NULL;
+
+ if (is_endbr(insn)) {
*on_func_entry = !offset || offset == 4;
if (*on_func_entry)
offset = 4;
prev parent reply other threads:[~2024-03-22 10:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAKHoSAs2rof6vQVBw_Lg_j3QNku0CANZR2qmy4eT7R5Lo8MFbg@mail.gmail.com>
2024-03-14 15:07 ` BUG: unable to handle kernel paging request in arch_adjust_kprobe_addr Masami Hiramatsu
2024-03-14 15:12 ` [PATCH] kprobes/x86: Use copy_from_kernel_nofault() to read from unsafe address Masami Hiramatsu (Google)
2024-03-14 15:15 ` Masami Hiramatsu
2024-03-14 15:17 ` [PATCH v2] " Masami Hiramatsu (Google)
2024-03-14 23:56 ` Jinghao Jia
2024-03-16 13:46 ` Masami Hiramatsu
2024-03-17 15:53 ` Jinghao Jia
2024-03-20 8:12 ` Masami Hiramatsu
2024-03-22 10:59 ` tip-bot2 for Masami Hiramatsu (Google) [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=171110515913.10875.11206445395083365696.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=jinghao7@illinois.edu \
--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 \
--cc=zzqq0103.hey@gmail.com \
/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®