]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tracing: eprobe-event: Allocate string buffers from heap
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Wed, 23 Jul 2025 01:31:26 +0000 (10:31 +0900)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Wed, 23 Jul 2025 15:21:51 +0000 (00:21 +0900)
Allocate temporary string buffers for parsing eprobe-events
from heap instead of stack.

Link: https://lore.kernel.org/all/175323428599.57270.988038042425748956.stgit@devnote2/
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/trace_eprobe.c

index 7ba3a18be4c5623be74c93ce52bc9d0dac933fd3..f16a0ab0b001564880ebb7ead1313a77c3dbfbe6 100644 (file)
@@ -9,6 +9,7 @@
  * Copyright (C) 2021, VMware Inc, Tzvetomir Stoyanov tz.stoyanov@gmail.com>
  *
  */
+#include <linux/cleanup.h>
 #include <linux/ftrace.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
@@ -871,10 +872,10 @@ static int __trace_eprobe_create(int argc, const char *argv[])
        const char *event = NULL, *group = EPROBE_EVENT_SYSTEM;
        const char *sys_event = NULL, *sys_name = NULL;
        struct trace_event_call *event_call;
+       char *buf1 __free(kfree) = NULL;
+       char *buf2 __free(kfree) = NULL;
+       char *gbuf __free(kfree) = NULL;
        struct trace_eprobe *ep = NULL;
-       char buf1[MAX_EVENT_NAME_LEN];
-       char buf2[MAX_EVENT_NAME_LEN];
-       char gbuf[MAX_EVENT_NAME_LEN];
        int ret = 0, filter_idx = 0;
        int i, filter_cnt;
 
@@ -885,6 +886,9 @@ static int __trace_eprobe_create(int argc, const char *argv[])
 
        event = strchr(&argv[0][1], ':');
        if (event) {
+               gbuf = kmalloc(MAX_EVENT_NAME_LEN, GFP_KERNEL);
+               if (!gbuf)
+                       goto mem_error;
                event++;
                ret = traceprobe_parse_event_name(&event, &group, gbuf,
                                                  event - argv[0]);
@@ -894,6 +898,11 @@ static int __trace_eprobe_create(int argc, const char *argv[])
 
        trace_probe_log_set_index(1);
        sys_event = argv[1];
+
+       buf2 = kmalloc(MAX_EVENT_NAME_LEN, GFP_KERNEL);
+       if (!buf2)
+               goto mem_error;
+
        ret = traceprobe_parse_event_name(&sys_event, &sys_name, buf2, 0);
        if (ret || !sys_event || !sys_name) {
                trace_probe_log_err(0, NO_EVENT_INFO);
@@ -901,7 +910,9 @@ static int __trace_eprobe_create(int argc, const char *argv[])
        }
 
        if (!event) {
-               strscpy(buf1, sys_event, MAX_EVENT_NAME_LEN);
+               buf1 = kstrdup(sys_event, GFP_KERNEL);
+               if (!buf1)
+                       goto mem_error;
                event = buf1;
        }
 
@@ -974,6 +985,9 @@ static int __trace_eprobe_create(int argc, const char *argv[])
        trace_probe_log_clear();
        return ret;
 
+mem_error:
+       ret = -ENOMEM;
+       goto error;
 parse_error:
        ret = -EINVAL;
 error: