tracing: probe-events: Log error for exceeding the number of arguments
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Thu, 27 Mar 2025 12:19:54 +0000 (21:19 +0900)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Thu, 27 Mar 2025 12:19:54 +0000 (21:19 +0900)
Add error message when the number of arguments exceeds the limitation.

Link: https://lore.kernel.org/all/174055075075.4079315.10916648136898316476.stgit@mhiramat.tok.corp.google.com/
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/trace_eprobe.c
kernel/trace/trace_fprobe.c
kernel/trace/trace_kprobe.c
kernel/trace/trace_probe.h
kernel/trace/trace_uprobe.c

index 82fd637cfc19eae447e8a7cb056f717d4407d5eb..af9fa0632b57405be17314959748aac97511cdee 100644 (file)
@@ -913,6 +913,8 @@ static int __trace_eprobe_create(int argc, const char *argv[])
        }
 
        if (argc - 2 > MAX_TRACE_ARGS) {
+               trace_probe_log_set_index(2);
+               trace_probe_log_err(0, TOO_MANY_ARGS);
                ret = -E2BIG;
                goto error;
        }
index 985ff98272da8fbd5b0e3010c825cdebe9b12b3d..5d7ca80173ea2b852bd17e4c7d70abf3b381c4db 100644 (file)
@@ -1199,8 +1199,11 @@ static int trace_fprobe_create_internal(int argc, const char *argv[],
                argc = new_argc;
                argv = new_argv;
        }
-       if (argc > MAX_TRACE_ARGS)
+       if (argc > MAX_TRACE_ARGS) {
+               trace_probe_log_set_index(2);
+               trace_probe_log_err(0, TOO_MANY_ARGS);
                return -E2BIG;
+       }
 
        ret = traceprobe_expand_dentry_args(argc, argv, &dbuf);
        if (ret)
index d8d5f18a141adc780d4a6448591af6780283105d..8287b175667f334663748f0abbdac036c68b422a 100644 (file)
@@ -1007,8 +1007,11 @@ static int trace_kprobe_create_internal(int argc, const char *argv[],
                argc = new_argc;
                argv = new_argv;
        }
-       if (argc > MAX_TRACE_ARGS)
+       if (argc > MAX_TRACE_ARGS) {
+               trace_probe_log_set_index(2);
+               trace_probe_log_err(0, TOO_MANY_ARGS);
                return -E2BIG;
+       }
 
        ret = traceprobe_expand_dentry_args(argc, argv, &dbuf);
        if (ret)
index 96792bc4b09244ea66881d938edd30ffdac18f07..854e5668f5ee5ab4e489ca6c88f4260516dc1cbe 100644 (file)
@@ -545,6 +545,7 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,
        C(BAD_BTF_TID,          "Failed to get BTF type info."),\
        C(BAD_TYPE4STR,         "This type does not fit for string."),\
        C(NEED_STRING_TYPE,     "$comm and immediate-string only accepts string type"),\
+       C(TOO_MANY_ARGS,        "Too many arguments are specified"),    \
        C(TOO_MANY_EARGS,       "Too many entry arguments specified"),
 
 #undef C
index ccc762fbb69cd195c1cd8a14ad6a8d5e125c3820..3386439ec9f674392aeaaca632b0e13ba15248ef 100644 (file)
@@ -562,8 +562,14 @@ static int __trace_uprobe_create(int argc, const char **argv)
 
        if (argc < 2)
                return -ECANCELED;
-       if (argc - 2 > MAX_TRACE_ARGS)
+
+       trace_probe_log_init("trace_uprobe", argc, argv);
+
+       if (argc - 2 > MAX_TRACE_ARGS) {
+               trace_probe_log_set_index(2);
+               trace_probe_log_err(0, TOO_MANY_ARGS);
                return -E2BIG;
+       }
 
        if (argv[0][1] == ':')
                event = &argv[0][2];
@@ -582,7 +588,6 @@ static int __trace_uprobe_create(int argc, const char **argv)
                return -ECANCELED;
        }
 
-       trace_probe_log_init("trace_uprobe", argc, argv);
        trace_probe_log_set_index(1);   /* filename is the 2nd argument */
 
        *arg++ = '\0';