Skip to content

Commit 5b2f2cb

Browse files
mhiramatgregkh
authored andcommitted
tracing/histogram: Do not copy the fixed-size char array field over the field size
[ Upstream commit 63f84ae ] Do not copy the fixed-size char array field of the events over the field size. The histogram treats char array as a string and there are 2 types of char array in the event, fixed-size and dynamic string. The dynamic string (__data_loc) field must be null terminated, but the fixed-size char array field may not be null terminated (not a string, but just a data). In that case, histogram can copy the data after the field. This uses the original field size for fixed-size char array field to restrict the histogram not to access over the original field size. Link: https://lkml.kernel.org/r/163673292822.195747.3696966210526410250.stgit@devnote2 Fixes: 02205a6 (tracing: Add support for 'field variables') Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1d61255 commit 5b2f2cb

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎kernel/trace/trace_events_hist.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,9 +1684,10 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data,
16841684
if (!hist_field->type)
16851685
goto free;
16861686

1687-
if (field->filter_type == FILTER_STATIC_STRING)
1687+
if (field->filter_type == FILTER_STATIC_STRING) {
16881688
hist_field->fn = hist_field_string;
1689-
else if (field->filter_type == FILTER_DYN_STRING)
1689+
hist_field->size = field->size;
1690+
} else if (field->filter_type == FILTER_DYN_STRING)
16901691
hist_field->fn = hist_field_dynstring;
16911692
else
16921693
hist_field->fn = hist_field_pstring;
@@ -2624,7 +2625,7 @@ static inline void __update_field_vars(struct tracing_map_elt *elt,
26242625
char *str = elt_data->field_var_str[j++];
26252626
char *val_str = (char *)(uintptr_t)var_val;
26262627

2627-
strscpy(str, val_str, STR_VAR_LEN_MAX);
2628+
strscpy(str, val_str, val->size);
26282629
var_val = (u64)(uintptr_t)str;
26292630
}
26302631
tracing_map_set_var(elt, var_idx, var_val);
@@ -4472,7 +4473,7 @@ static void hist_trigger_elt_update(struct hist_trigger_data *hist_data,
44724473

44734474
str = elt_data->field_var_str[idx];
44744475
val_str = (char *)(uintptr_t)hist_val;
4475-
strscpy(str, val_str, STR_VAR_LEN_MAX);
4476+
strscpy(str, val_str, hist_field->size);
44764477

44774478
hist_val = (u64)(uintptr_t)str;
44784479
}

0 commit comments

Comments
 (0)