Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <mhiramat@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tomas Glozar <tglozar@redhat.com>
Cc: Juri Lelli <jlelli@redhat.com>
Cc: Clark Williams <williams@redhat.com>
Cc: John Kacur <jkacur@redhat.com>
Link: https://lore.kernel.org/20250728135022.255578-4-gmonaco@redhat.com
Fixes: 792575348ff7 ("rv/include: Add deterministic automata monitor definition via C macros")
Reviewed-by: Nam Cao <namcao@linutronix.de>
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Gabriele Monaco and committed by
Steven Rostedt (Google)
7f904ff6 7b70ac4c

+38 -38
+38 -38
kernel/trace/rv/rv_trace.h
··· 16 16 TP_ARGS(state, event, next_state, final_state), 17 17 18 18 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 ) 23 23 ), 24 24 25 25 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; 30 30 ), 31 31 32 32 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), 36 36 __entry->final_state ? " (final)" : "") 37 37 ); 38 38 ··· 43 43 TP_ARGS(state, event), 44 44 45 45 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 ) 48 48 ), 49 49 50 50 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); 53 53 ), 54 54 55 55 TP_printk("event %s not expected in the state %s", 56 - __entry->event, 57 - __entry->state) 56 + __get_str(event), 57 + __get_str(state)) 58 58 ); 59 59 60 60 #include <monitors/wip/wip_trace.h> ··· 75 75 TP_ARGS(id, state, event, next_state, final_state), 76 76 77 77 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 ) 83 83 ), 84 84 85 85 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; 91 91 ), 92 92 93 93 TP_printk("%d: %s x %s -> %s%s", 94 94 __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), 98 98 __entry->final_state ? " (final)" : "") 99 99 ); 100 100 ··· 105 105 TP_ARGS(id, state, event), 106 106 107 107 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 ) 111 111 ), 112 112 113 113 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; 117 117 ), 118 118 119 119 TP_printk("%d: event %s not expected in the state %s", 120 120 __entry->id, 121 - __entry->event, 122 - __entry->state) 121 + __get_str(event), 122 + __get_str(state)) 123 123 ); 124 124 125 125 #include <monitors/wwnr/wwnr_trace.h>