Skip to content

Commit 6dc512a

Browse files
committed
Merge tag 'probes-fixes-v6.8-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull probes fixes from Masami Hiramatsu: - remove unnecessary initial values of kprobes local variables - probe-events parser bug fixes: - calculate the argument size and format string after setting type information from BTF, because BTF can change the size and format string. - show $comm parse error correctly instead of failing silently. * tag 'probes-fixes-v6.8-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: kprobes: Remove unnecessary initial values of variables tracing/probes: Fix to set arg size and fmt after setting type from BTF tracing/probes: Fix to show a parse error for bad type for $comm
2 parents e6f39a9 + 9efd24e commit 6dc512a

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

kernel/kprobes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,7 @@ NOKPROBE_SYMBOL(__kretprobe_find_ret_addr);
19931993
unsigned long kretprobe_find_ret_addr(struct task_struct *tsk, void *fp,
19941994
struct llist_node **cur)
19951995
{
1996-
struct kretprobe_instance *ri = NULL;
1996+
struct kretprobe_instance *ri;
19971997
kprobe_opcode_t *ret;
19981998

19991999
if (WARN_ON_ONCE(!cur))
@@ -2802,7 +2802,7 @@ static int show_kprobe_addr(struct seq_file *pi, void *v)
28022802
{
28032803
struct hlist_head *head;
28042804
struct kprobe *p, *kp;
2805-
const char *sym = NULL;
2805+
const char *sym;
28062806
unsigned int i = *(loff_t *) v;
28072807
unsigned long offset = 0;
28082808
char *modname, namebuf[KSYM_NAME_LEN];

kernel/trace/trace_probe.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,28 +1159,19 @@ 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);
11681171
if (!parg->type) {
11691172
trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0), BAD_TYPE);
11701173
goto out;
11711174
}
1172-
parg->offset = *size;
1173-
*size += parg->type->size * (parg->count ?: 1);
1174-
1175-
ret = -ENOMEM;
1176-
if (parg->count) {
1177-
len = strlen(parg->type->fmttype) + 6;
1178-
parg->fmt = kmalloc(len, GFP_KERNEL);
1179-
if (!parg->fmt)
1180-
goto out;
1181-
snprintf(parg->fmt, len, "%s[%d]", parg->type->fmttype,
1182-
parg->count);
1183-
}
11841175

11851176
code = tmp = kcalloc(FETCH_INSN_MAX, sizeof(*code), GFP_KERNEL);
11861177
if (!code)
@@ -1204,6 +1195,19 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
12041195
goto fail;
12051196
}
12061197
}
1198+
parg->offset = *size;
1199+
*size += parg->type->size * (parg->count ?: 1);
1200+
1201+
if (parg->count) {
1202+
len = strlen(parg->type->fmttype) + 6;
1203+
parg->fmt = kmalloc(len, GFP_KERNEL);
1204+
if (!parg->fmt) {
1205+
ret = -ENOMEM;
1206+
goto out;
1207+
}
1208+
snprintf(parg->fmt, len, "%s[%d]", parg->type->fmttype,
1209+
parg->count);
1210+
}
12071211

12081212
ret = -EINVAL;
12091213
/* Store operation */

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)