Skip to content

Commit 4e51653

Browse files
mhiramatIngo Molnar
authored andcommitted
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: cc66bb9 ("x86/ibt,kprobes: Cure sym+0 equals fentry woes") Reported-by: Qiang Zhang <[email protected]> Tested-by: Jinghao Jia <[email protected]> Signed-off-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/171042945004.154897.2221804961882915806.stgit@devnote2
1 parent e3f269e commit 4e51653

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

arch/x86/kernel/kprobes/core.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,16 @@ static bool can_probe(unsigned long paddr)
373373
kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offset,
374374
bool *on_func_entry)
375375
{
376-
if (is_endbr(*(u32 *)addr)) {
376+
u32 insn;
377+
378+
/*
379+
* Since 'addr' is not guaranteed to be safe to access, use
380+
* copy_from_kernel_nofault() to read the instruction:
381+
*/
382+
if (copy_from_kernel_nofault(&insn, (void *)addr, sizeof(u32)))
383+
return NULL;
384+
385+
if (is_endbr(insn)) {
377386
*on_func_entry = !offset || offset == 4;
378387
if (*on_func_entry)
379388
offset = 4;

0 commit comments

Comments
 (0)