Skip to content

Commit 63f84ae

Browse files
mhiramatrostedt
authored andcommitted
tracing/histogram: Do not copy the fixed-size char array field over the field size
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 <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent d7458bc commit 63f84ae

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

kernel/trace/trace_events_hist.c

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

1956-
if (field->filter_type == FILTER_STATIC_STRING)
1956+
if (field->filter_type == FILTER_STATIC_STRING) {
19571957
hist_field->fn = hist_field_string;
1958-
else if (field->filter_type == FILTER_DYN_STRING)
1958+
hist_field->size = field->size;
1959+
} else if (field->filter_type == FILTER_DYN_STRING)
19591960
hist_field->fn = hist_field_dynstring;
19601961
else
19611962
hist_field->fn = hist_field_pstring;
@@ -3025,7 +3026,7 @@ static inline void __update_field_vars(struct tracing_map_elt *elt,
30253026
char *str = elt_data->field_var_str[j++];
30263027
char *val_str = (char *)(uintptr_t)var_val;
30273028

3028-
strscpy(str, val_str, STR_VAR_LEN_MAX);
3029+
strscpy(str, val_str, val->size);
30293030
var_val = (u64)(uintptr_t)str;
30303031
}
30313032
tracing_map_set_var(elt, var_idx, var_val);
@@ -4920,7 +4921,7 @@ static void hist_trigger_elt_update(struct hist_trigger_data *hist_data,
49204921

49214922
str = elt_data->field_var_str[idx];
49224923
val_str = (char *)(uintptr_t)hist_val;
4923-
strscpy(str, val_str, STR_VAR_LEN_MAX);
4924+
strscpy(str, val_str, hist_field->size);
49244925

49254926
hist_val = (u64)(uintptr_t)str;
49264927
}

0 commit comments

Comments
 (0)