Skip to content

Commit 7f904ff

Browse files
glemcorostedt
authored andcommitted
rv: Use strings in da monitors tracepoints
Using DA monitors tracepoints with KASAN enabled triggers the following warning: BUG: KASAN: global-out-of-bounds in do_trace_event_raw_event_event_da_monitor+0xd6/0x1a0 Read of size 32 at addr ffffffffaada8980 by task ... Call Trace: <TASK> [...] do_trace_event_raw_event_event_da_monitor+0xd6/0x1a0 ? __pfx_do_trace_event_raw_event_event_da_monitor+0x10/0x10 ? trace_event_sncid+0x83/0x200 trace_event_sncid+0x163/0x200 [...] The buggy address belongs to the variable: automaton_snep+0x4e0/0x5e0 This is caused by the tracepoints reading 32 bytes __array instead of __string from the automata definition. Such strings are literals and reading 32 bytes ends up in out of bound memory accesses (e.g. the next automaton's data in this case). The error is harmless as, while printing the string, we stop at the null terminator, but it should still be fixed. Use the __string facilities while defining the tracepoints to avoid reading out of bound memory. Cc: Masami Hiramatsu <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Tomas Glozar <[email protected]> Cc: Juri Lelli <[email protected]> Cc: Clark Williams <[email protected]> Cc: John Kacur <[email protected]> Link: https://lore.kernel.org/[email protected] Fixes: 7925753 ("rv/include: Add deterministic automata monitor definition via C macros") Reviewed-by: Nam Cao <[email protected]> Signed-off-by: Gabriele Monaco <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 7b70ac4 commit 7f904ff

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

kernel/trace/rv/rv_trace.h

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ DECLARE_EVENT_CLASS(event_da_monitor,
1616
TP_ARGS(state, event, next_state, final_state),
1717

1818
TP_STRUCT__entry(
19-
__array( char, state, MAX_DA_NAME_LEN )
20-
__array( char, event, MAX_DA_NAME_LEN )
21-
__array( char, next_state, MAX_DA_NAME_LEN )
22-
__field( bool, final_state )
19+
__string( state, state )
20+
__string( event, event )
21+
__string( next_state, next_state )
22+
__field( bool, final_state )
2323
),
2424

2525
TP_fast_assign(
26-
memcpy(__entry->state, state, MAX_DA_NAME_LEN);
27-
memcpy(__entry->event, event, MAX_DA_NAME_LEN);
28-
memcpy(__entry->next_state, next_state, MAX_DA_NAME_LEN);
29-
__entry->final_state = final_state;
26+
__assign_str(state);
27+
__assign_str(event);
28+
__assign_str(next_state);
29+
__entry->final_state = final_state;
3030
),
3131

3232
TP_printk("%s x %s -> %s%s",
33-
__entry->state,
34-
__entry->event,
35-
__entry->next_state,
33+
__get_str(state),
34+
__get_str(event),
35+
__get_str(next_state),
3636
__entry->final_state ? " (final)" : "")
3737
);
3838

@@ -43,18 +43,18 @@ DECLARE_EVENT_CLASS(error_da_monitor,
4343
TP_ARGS(state, event),
4444

4545
TP_STRUCT__entry(
46-
__array( char, state, MAX_DA_NAME_LEN )
47-
__array( char, event, MAX_DA_NAME_LEN )
46+
__string( state, state )
47+
__string( event, event )
4848
),
4949

5050
TP_fast_assign(
51-
memcpy(__entry->state, state, MAX_DA_NAME_LEN);
52-
memcpy(__entry->event, event, MAX_DA_NAME_LEN);
51+
__assign_str(state);
52+
__assign_str(event);
5353
),
5454

5555
TP_printk("event %s not expected in the state %s",
56-
__entry->event,
57-
__entry->state)
56+
__get_str(event),
57+
__get_str(state))
5858
);
5959

6060
#include <monitors/wip/wip_trace.h>
@@ -75,26 +75,26 @@ DECLARE_EVENT_CLASS(event_da_monitor_id,
7575
TP_ARGS(id, state, event, next_state, final_state),
7676

7777
TP_STRUCT__entry(
78-
__field( int, id )
79-
__array( char, state, MAX_DA_NAME_LEN )
80-
__array( char, event, MAX_DA_NAME_LEN )
81-
__array( char, next_state, MAX_DA_NAME_LEN )
82-
__field( bool, final_state )
78+
__field( int, id )
79+
__string( state, state )
80+
__string( event, event )
81+
__string( next_state, next_state )
82+
__field( bool, final_state )
8383
),
8484

8585
TP_fast_assign(
86-
memcpy(__entry->state, state, MAX_DA_NAME_LEN);
87-
memcpy(__entry->event, event, MAX_DA_NAME_LEN);
88-
memcpy(__entry->next_state, next_state, MAX_DA_NAME_LEN);
89-
__entry->id = id;
90-
__entry->final_state = final_state;
86+
__assign_str(state);
87+
__assign_str(event);
88+
__assign_str(next_state);
89+
__entry->id = id;
90+
__entry->final_state = final_state;
9191
),
9292

9393
TP_printk("%d: %s x %s -> %s%s",
9494
__entry->id,
95-
__entry->state,
96-
__entry->event,
97-
__entry->next_state,
95+
__get_str(state),
96+
__get_str(event),
97+
__get_str(next_state),
9898
__entry->final_state ? " (final)" : "")
9999
);
100100

@@ -105,21 +105,21 @@ DECLARE_EVENT_CLASS(error_da_monitor_id,
105105
TP_ARGS(id, state, event),
106106

107107
TP_STRUCT__entry(
108-
__field( int, id )
109-
__array( char, state, MAX_DA_NAME_LEN )
110-
__array( char, event, MAX_DA_NAME_LEN )
108+
__field( int, id )
109+
__string( state, state )
110+
__string( event, event )
111111
),
112112

113113
TP_fast_assign(
114-
memcpy(__entry->state, state, MAX_DA_NAME_LEN);
115-
memcpy(__entry->event, event, MAX_DA_NAME_LEN);
116-
__entry->id = id;
114+
__assign_str(state);
115+
__assign_str(event);
116+
__entry->id = id;
117117
),
118118

119119
TP_printk("%d: event %s not expected in the state %s",
120120
__entry->id,
121-
__entry->event,
122-
__entry->state)
121+
__get_str(event),
122+
__get_str(state))
123123
);
124124

125125
#include <monitors/wwnr/wwnr_trace.h>

0 commit comments

Comments
 (0)