Skip to content

Commit 8261ef2

Browse files
committed
tracing: Add BUILD_BUG() to make sure stacktrace fits in strings
The max string length for a histogram variable is 256 bytes. The max depth of a stacktrace is 16. With 8byte words, that's 16 * 8 = 128. Which can easily fit in the string variable. The histogram stacktrace is being stored in the string value (with the given max length), with the assumption it will fit. To make sure that this is always the case (in the case that the stack trace depth increases), add a BUILD_BUG_ON() to test this. Link: https://lore.kernel.org/linux-trace-kernel/[email protected]/ Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent fc1a9dc commit 8261ef2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

kernel/trace/trace_events_hist.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,6 +3119,9 @@ static inline void __update_field_vars(struct tracing_map_elt *elt,
31193119
unsigned int i, j, var_idx;
31203120
u64 var_val;
31213121

3122+
/* Make sure stacktrace can fit in the string variable length */
3123+
BUILD_BUG_ON((HIST_STACKTRACE_DEPTH + 1) * sizeof(long) >= STR_VAR_LEN_MAX);
3124+
31223125
for (i = 0, j = field_var_str_start; i < n_field_vars; i++) {
31233126
struct field_var *field_var = field_vars[i];
31243127
struct hist_field *var = field_var->var;

0 commit comments

Comments
 (0)