Skip to content

Commit 8c427cc

Browse files
committed
tracing/probes: Fix to show a parse error for bad type for $comm
Fix to show a parse error for bad type (non-string) for $comm/$COMM and immediate-string. With this fix, error_log file shows appropriate error message as below. /sys/kernel/tracing # echo 'p vfs_read $comm:u32' >> kprobe_events sh: write error: Invalid argument /sys/kernel/tracing # echo 'p vfs_read \"hoge":u32' >> kprobe_events sh: write error: Invalid argument /sys/kernel/tracing # cat error_log [ 30.144183] trace_kprobe: error: $comm and immediate-string only accepts string type Command: p vfs_read $comm:u32 ^ [ 62.618500] trace_kprobe: error: $comm and immediate-string only accepts string type Command: p vfs_read \"hoge":u32 ^ Link: https://lore.kernel.org/all/170602215411.215583.2238016352271091852.stgit@devnote2/ Fixes: 3dd1f7f ("tracing: probeevent: Fix to make the type of $comm string") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
1 parent 54be6c6 commit 8c427cc

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

kernel/trace/trace_probe.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,9 +1159,12 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
11591159
if (!(ctx->flags & TPARG_FL_TEVENT) &&
11601160
(strcmp(arg, "$comm") == 0 || strcmp(arg, "$COMM") == 0 ||
11611161
strncmp(arg, "\\\"", 2) == 0)) {
1162-
/* The type of $comm must be "string", and not an array. */
1163-
if (parg->count || (t && strcmp(t, "string")))
1162+
/* The type of $comm must be "string", and not an array type. */
1163+
if (parg->count || (t && strcmp(t, "string"))) {
1164+
trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0),
1165+
NEED_STRING_TYPE);
11641166
goto out;
1167+
}
11651168
parg->type = find_fetch_type("string", ctx->flags);
11661169
} else
11671170
parg->type = find_fetch_type(t, ctx->flags);

kernel/trace/trace_probe.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,
515515
C(BAD_HYPHEN, "Failed to parse single hyphen. Forgot '>'?"), \
516516
C(NO_BTF_FIELD, "This field is not found."), \
517517
C(BAD_BTF_TID, "Failed to get BTF type info."),\
518-
C(BAD_TYPE4STR, "This type does not fit for string."),
518+
C(BAD_TYPE4STR, "This type does not fit for string."),\
519+
C(NEED_STRING_TYPE, "$comm and immediate-string only accepts string type"),
519520

520521
#undef C
521522
#define C(a, b) TP_ERR_##a

0 commit comments

Comments
 (0)