From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
To: Linux Trace Kernel <linux-trace-kernel@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Steven Rostedt <rostedt@goodmis.org>
Cc: Qiang Zhang <zzqq0103.hey@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H . Peter Anvin" <hpa@zytor.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Jinghao Jia <jinghao7@illinois.edu>,
Peter Zijlstra <peterz@infradead.org>,
x86@kernel.org
Subject: [PATCH v2] kprobes/x86: Use copy_from_kernel_nofault() to read from unsafe address
Date: Fri, 15 Mar 2024 00:17:30 +0900 [thread overview]
Message-ID: <171042945004.154897.2221804961882915806.stgit@devnote2> (raw)
In-Reply-To: <20240315000753.a448251fce0291e041f76c13@kernel.org>
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
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.
Reported-by: Qiang Zhang <zzqq0103.hey@gmail.com>
Closes: https://lore.kernel.org/all/CAKHoSAs2rof6vQVBw_Lg_j3QNku0CANZR2qmy4eT7R5Lo8MFbg@mail.gmail.com/
Fixes: cc66bb914578 ("x86/ibt,kprobes: Cure sym+0 equals fentry woes")
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
Changes in v2:
- Fix to return NULL if failed to access the address.
---
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 a0ce46c0a2d8..95e4ebe5d514 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -335,7 +335,16 @@ static int can_probe(unsigned long paddr)
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 safely accessed yet, use
+ * copy_from_kernel_nofault() to get 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;
next prev parent reply other threads:[~2024-03-14 15:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240315000753.a448251fce0291e041f76c13@kernel.org>
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 ` Masami Hiramatsu (Google) [this message]
2024-03-14 23:56 ` [PATCH v2] " Jinghao Jia
2024-03-16 13:46 ` Masami Hiramatsu
2024-03-17 15:53 ` Jinghao Jia
2024-03-20 8:12 ` Masami Hiramatsu
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=171042945004.154897.2221804961882915806.stgit@devnote2 \
--to=mhiramat@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jinghao7@illinois.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--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;
as well as URLs for NNTP newsgroup(s).