aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Zabrocki <[email protected]>2022-04-22 18:40:27 +0200
committerDaniel Borkmann <[email protected]>2022-04-26 16:09:36 +0200
commit1d661ed54d8613c97bcff2c7d6181c61e482a1da (patch)
treef126c3bcc98255dfed064c1ac7a95fc58e771613
parentb02d196c44ead1a5949729be9ff08fe781c3e48a (diff)
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 <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Masami Hiramatsu <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Naveen N. Rao <[email protected]> Cc: Anil S. Keshavamurthy <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
-rw-r--r--kernel/kprobes.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index dbe57df2e199..dd58c0be9ce2 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);