From: Adam Zabrocki Date: Fri, 22 Apr 2022 16:40:27 +0000 (+0200) Subject: kprobes: Fix KRETPROBES when CONFIG_KRETPROBE_ON_RETHOOK is set X-Git-Tag: v6.1-rc5~1477^2~10^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1d661ed54d8613c97bcff2c7d6181c61e482a1da;p=platform%2Fkernel%2Flinux-starfive.git kprobes: Fix KRETPROBES when CONFIG_KRETPROBE_ON_RETHOOK is set The recent kernel change in 73f9b911faa7 ("kprobes: Use rethook for kretprobe if possible"), introduced a potential NULL pointer dereference bug in the KRETPROBE mechanism. The official Kprobes documentation defines that "Any or all handlers can be NULL". Unfortunately, there is a missing return handler verification to fulfill these requirements and can result in a NULL pointer dereference bug. This patch adds such verification in kretprobe_rethook_handler() function. Fixes: 73f9b911faa7 ("kprobes: Use rethook for kretprobe if possible") Signed-off-by: Adam Zabrocki Signed-off-by: Daniel Borkmann Acked-by: Masami Hiramatsu Cc: Steven Rostedt Cc: Naveen N. Rao Cc: Anil S. Keshavamurthy Link: https://lore.kernel.org/bpf/20220422164027.GA7862@pi3.com.pl --- diff --git a/kernel/kprobes.c b/kernel/kprobes.c index dbe57df..dd58c0b 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -2126,7 +2126,7 @@ static void kretprobe_rethook_handler(struct rethook_node *rh, void *data, struct kprobe_ctlblk *kcb; /* The data must NOT be null. This means rethook data structure is broken. */ - if (WARN_ON_ONCE(!data)) + if (WARN_ON_ONCE(!data) || !rp->handler) return; __this_cpu_write(current_kprobe, &rp->kp);