This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[RFC PATCH tip/master 3/3] kprobes: Limit kretprobe maximum instances
- From: Masami Hiramatsu <mhiramat at kernel dot org>
- To: Steven Rostedt <rostedt at goodmis dot org>, Ingo Molnar <mingo at redhat dot com>
- Cc: Alban Crequy <alban dot crequy at gmail dot com>, Alban Crequy <alban at kinvolk dot io>, Alexei Starovoitov <ast at kernel dot org>, Jonathan Corbet <corbet at lwn dot net>, Arnaldo Carvalho de Melo <acme at redhat dot com>, Omar Sandoval <osandov at fb dot com>, linux-doc at vger dot kernel dot org, netdev at vger dot kernel dot org, linux-kernel at vger dot kernel dot org, iago at kinvolk dot io, michael at kinvolk dot io, Dorau Lukasz <lukasz dot dorau at intel dot com>, systemtap at sourceware dot org
- Date: Wed, 29 Mar 2017 14:24:23 +0900
- Subject: [RFC PATCH tip/master 3/3] kprobes: Limit kretprobe maximum instances
- Authentication-results: sourceware.org; auth=none
- References: <149076484118.24574.7083269903420611708.stgit@devbox>
Limit kretprobe maximum instance up to MAXACTIVE_ALLOC.
Without this limit, kretprobe user can specify huge number
(e.g. forget to zero-fill struct kretprobe) to maxactive
and may cause out-of-memory.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
kernel/kprobes.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 75c5390..f1bebcf 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1942,6 +1942,9 @@ int register_kretprobe(struct kretprobe *rp)
rp->kp.break_handler = NULL;
/* Pre-allocate memory for max kretprobe instances */
+ if (rp->maxactive > KRETPROBE_MAXACTIVE_ALLOC)
+ return -E2BIG;
+
if (rp->maxactive <= 0) {
#ifdef CONFIG_PREEMPT
rp->maxactive = max_t(unsigned int, 10, 2*num_possible_cpus());