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

tracing: Avoid -Warray-bounds warning for __rel_loc macro

Since -Warray-bounds checks the destination size from the type of given
pointer, __assign_rel_str() macro gets warned because it passes the
pointer to the 'u32' field instead of 'trace_event_raw_*' data structure.
Pass the data address calculated from the 'trace_event_raw_*' instead of
'u32' __rel_loc field.

Link: https://lkml.kernel.org/r/20220125233154.dac280ed36944c0c2fe6f3ac@kernel.org

Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
[ This did not fix the warning, but is still a nice clean up ]
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Masami Hiramatsu and committed by
Steven Rostedt (Google)
58c5724e e629e7b5

+4 -3
+4 -3
include/trace/trace_events.h
··· 318 318 #define __get_str(field) ((char *)__get_dynamic_array(field)) 319 319 320 320 #undef __get_rel_dynamic_array 321 - #define __get_rel_dynamic_array(field) \ 322 - ((void *)(&__entry->__rel_loc_##field) + \ 323 - sizeof(__entry->__rel_loc_##field) + \ 321 + #define __get_rel_dynamic_array(field) \ 322 + ((void *)__entry + \ 323 + offsetof(typeof(*__entry), __rel_loc_##field) + \ 324 + sizeof(__entry->__rel_loc_##field) + \ 324 325 (__entry->__rel_loc_##field & 0xffff)) 325 326 326 327 #undef __get_rel_dynamic_array_len