Skip to content

Commit cf4f493

Browse files
committed
Merge tag 'trace-v5.4-3' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing fixes from Steven Rostedt: "A few more tracing fixes: - Fix a buffer overflow by checking nr_args correctly in probes - Fix a warning that is reported by clang - Fix a possible memory leak in error path of filter processing - Fix the selftest that checks for failures, but wasn't failing - Minor clean up on call site output of a memory trace event" * tag 'trace-v5.4-3' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: selftests/ftrace: Fix same probe error test mm, tracing: Print symbol name for call_site in trace events tracing: Have error path in predicate_parse() free its allocated memory tracing: Fix clang -Wint-in-bool-context warnings in IF_ASSIGN macro tracing/probe: Fix to check the difference of nr_args before adding probe
2 parents c710364 + 8ed4889 commit cf4f493

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

include/trace/events/kmem.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ DECLARE_EVENT_CLASS(kmem_alloc,
3535
__entry->gfp_flags = gfp_flags;
3636
),
3737

38-
TP_printk("call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",
39-
__entry->call_site,
38+
TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",
39+
(void *)__entry->call_site,
4040
__entry->ptr,
4141
__entry->bytes_req,
4242
__entry->bytes_alloc,
@@ -131,7 +131,8 @@ DECLARE_EVENT_CLASS(kmem_free,
131131
__entry->ptr = ptr;
132132
),
133133

134-
TP_printk("call_site=%lx ptr=%p", __entry->call_site, __entry->ptr)
134+
TP_printk("call_site=%pS ptr=%p",
135+
(void *)__entry->call_site, __entry->ptr)
135136
);
136137

137138
DEFINE_EVENT(kmem_free, kfree,

kernel/trace/trace.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,11 @@ static inline struct trace_array *top_trace_array(void)
365365
__builtin_types_compatible_p(typeof(var), type *)
366366

367367
#undef IF_ASSIGN
368-
#define IF_ASSIGN(var, entry, etype, id) \
369-
if (FTRACE_CMP_TYPE(var, etype)) { \
370-
var = (typeof(var))(entry); \
371-
WARN_ON(id && (entry)->type != id); \
372-
break; \
368+
#define IF_ASSIGN(var, entry, etype, id) \
369+
if (FTRACE_CMP_TYPE(var, etype)) { \
370+
var = (typeof(var))(entry); \
371+
WARN_ON(id != 0 && (entry)->type != id); \
372+
break; \
373373
}
374374

375375
/* Will cause compile errors if type is not found. */

kernel/trace/trace_events_filter.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,10 @@ predicate_parse(const char *str, int nr_parens, int nr_preds,
452452

453453
switch (*next) {
454454
case '(': /* #2 */
455-
if (top - op_stack > nr_parens)
456-
return ERR_PTR(-EINVAL);
455+
if (top - op_stack > nr_parens) {
456+
ret = -EINVAL;
457+
goto out_free;
458+
}
457459
*(++top) = invert;
458460
continue;
459461
case '!': /* #3 */

kernel/trace/trace_probe.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ void __trace_probe_log_err(int offset, int err_type)
178178
if (!command)
179179
return;
180180

181+
if (trace_probe_log.index >= trace_probe_log.argc) {
182+
/**
183+
* Set the error position is next to the last arg + space.
184+
* Note that len includes the terminal null and the cursor
185+
* appaers at pos + 1.
186+
*/
187+
pos = len;
188+
offset = 0;
189+
}
190+
181191
/* And make a command string from argv array */
182192
p = command;
183193
for (i = 0; i < trace_probe_log.argc; i++) {
@@ -1084,6 +1094,12 @@ int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b)
10841094
{
10851095
int i;
10861096

1097+
/* In case of more arguments */
1098+
if (a->nr_args < b->nr_args)
1099+
return a->nr_args + 1;
1100+
if (a->nr_args > b->nr_args)
1101+
return b->nr_args + 1;
1102+
10871103
for (i = 0; i < a->nr_args; i++) {
10881104
if ((b->nr_args <= i) ||
10891105
((a->args[i].type != b->args[i].type) ||

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ echo 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
9595
check_error 'p:kprobes/testevent _do_fork ^bcd=\1' # DIFF_ARG_TYPE
9696
check_error 'p:kprobes/testevent _do_fork ^abcd=\1:u8' # DIFF_ARG_TYPE
9797
check_error 'p:kprobes/testevent _do_fork ^abcd=\"foo"' # DIFF_ARG_TYPE
98-
check_error '^p:kprobes/testevent _do_fork' # SAME_PROBE
98+
check_error '^p:kprobes/testevent _do_fork abcd=\1' # SAME_PROBE
9999
fi
100100

101101
exit 0

0 commit comments

Comments
 (0)