Skip to content

Commit 0312735

Browse files
rostedtgregkh
authored andcommitted
tracing: Verify event formats that have "%*p.."
[ Upstream commit ea8d764 ] The trace event verifier checks the formats of trace events to make sure that they do not point at memory that is not in the trace event itself or in data that will never be freed. If an event references data that was allocated when the event triggered and that same data is freed before the event is read, then the kernel can crash by reading freed memory. The verifier runs at boot up (or module load) and scans the print formats of the events and checks their arguments to make sure that dereferenced pointers are safe. If the format uses "%*p.." the verifier will ignore it, and that could be dangerous. Cover this case as well. Also add to the sample code a use case of "%*pbl". Link: https://lore.kernel.org/all/[email protected]/ Cc: [email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Fixes: 5013f45 ("tracing: Add check of trace event print fmts for dereferencing pointers") Link: https://lore.kernel.org/[email protected] Reported-by: Libo Chen <[email protected]> Reviewed-by: Libo Chen <[email protected]> Tested-by: Libo Chen <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 0b603e7 commit 0312735

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

kernel/trace/trace_events.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ static void test_event_printk(struct trace_event_call *call)
470470
case '%':
471471
continue;
472472
case 'p':
473+
do_pointer:
473474
/* Find dereferencing fields */
474475
switch (fmt[i + 1]) {
475476
case 'B': case 'R': case 'r':
@@ -498,6 +499,12 @@ static void test_event_printk(struct trace_event_call *call)
498499
continue;
499500
if (fmt[i + j] == '*') {
500501
star = true;
502+
/* Handle %*pbl case */
503+
if (!j && fmt[i + 1] == 'p') {
504+
arg++;
505+
i++;
506+
goto do_pointer;
507+
}
501508
continue;
502509
}
503510
if ((fmt[i + j] == 's')) {

samples/trace_events/trace-events-sample.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ TRACE_EVENT(foo_bar,
319319
__assign_cpumask(cpum, cpumask_bits(mask));
320320
),
321321

322-
TP_printk("foo %s %d %s %s %s %s %s %s (%s) (%s) %s", __entry->foo, __entry->bar,
322+
TP_printk("foo %s %d %s %s %s %s %s %s (%s) (%s) %s [%d] %*pbl",
323+
__entry->foo, __entry->bar,
323324

324325
/*
325326
* Notice here the use of some helper functions. This includes:
@@ -370,7 +371,10 @@ TRACE_EVENT(foo_bar,
370371

371372
__get_str(str), __get_str(lstr),
372373
__get_bitmask(cpus), __get_cpumask(cpum),
373-
__get_str(vstr))
374+
__get_str(vstr),
375+
__get_dynamic_array_len(cpus),
376+
__get_dynamic_array_len(cpus),
377+
__get_dynamic_array(cpus))
374378
);
375379

376380
/*

0 commit comments

Comments
 (0)