Skip to content

Commit

Permalink
Merge tag 'trace-v5.16-5' of git://git.kernel.org/pub/scm/linux/kerne…
Browse files Browse the repository at this point in the history
…l/git/rostedt/linux-trace

Pull tracing fix from Steven Rostedt:
 "Update to tracing histogram variable string copy

  A fix to only copy the size of the field to the histogram string did
  not take into account that the size can be larger than the storage"

* tag 'trace-v5.16-5' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace:
  tracing: Add length protection to histogram string copies
  • Loading branch information
Linus Torvalds committed Nov 15, 2021
2 parents 158ea2d + 938aa33 commit 8ab7745
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/linux/trace_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ struct trace_event_file {

#define PERF_MAX_TRACE_SIZE 8192

#define MAX_FILTER_STR_VAL 256 /* Should handle KSYM_SYMBOL_LEN */
#define MAX_FILTER_STR_VAL 256U /* Should handle KSYM_SYMBOL_LEN */

enum event_trigger_type {
ETT_NONE = (0),
Expand Down
9 changes: 7 additions & 2 deletions kernel/trace/trace_events_hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -3026,8 +3026,10 @@ static inline void __update_field_vars(struct tracing_map_elt *elt,
if (val->flags & HIST_FIELD_FL_STRING) {
char *str = elt_data->field_var_str[j++];
char *val_str = (char *)(uintptr_t)var_val;
unsigned int size;

strscpy(str, val_str, val->size);
size = min(val->size, STR_VAR_LEN_MAX);
strscpy(str, val_str, size);
var_val = (u64)(uintptr_t)str;
}
tracing_map_set_var(elt, var_idx, var_val);
Expand Down Expand Up @@ -4914,6 +4916,7 @@ static void hist_trigger_elt_update(struct hist_trigger_data *hist_data,
if (hist_field->flags & HIST_FIELD_FL_STRING) {
unsigned int str_start, var_str_idx, idx;
char *str, *val_str;
unsigned int size;

str_start = hist_data->n_field_var_str +
hist_data->n_save_var_str;
Expand All @@ -4922,7 +4925,9 @@ static void hist_trigger_elt_update(struct hist_trigger_data *hist_data,

str = elt_data->field_var_str[idx];
val_str = (char *)(uintptr_t)hist_val;
strscpy(str, val_str, hist_field->size);

size = min(hist_field->size, STR_VAR_LEN_MAX);
strscpy(str, val_str, size);

hist_val = (u64)(uintptr_t)str;
}
Expand Down

0 comments on commit 8ab7745

Please sign in to comment.