tracing: Add length protection to histogram string copies
Steven Rostedt
maintainerLinus,
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.
Please pull the latest trace-v5.16-5 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
trace-v5.16-5
Tag SHA1: db2ed9a1d3f9d93cb36d38110e6567c1bd8d1e9a Head SHA1: 938aa33f14657c9ed9deea348b7d6f14b6d69cb7
Steven Rostedt (VMware) (1):
tracing: Add length protection to histogram string copies
----
include/linux/trace_events.h | 2 +- kernel/trace/trace_events_hist.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) --------------------------- commit 938aa33f14657c9ed9deea348b7d6f14b6d69cb7 Author: Steven Rostedt (VMware) <[email protected]> Date: Sun Nov 14 13:28:34 2021 -0500
tracing: Add length protection to histogram string copies
The string copies to the histogram storage has a max size of 256 bytes (defined by MAX_FILTER_STR_VAL). Only the string size of the event field needs to be copied to the event storage, but no more than what is in the event storage. Although nothing should be bigger than 256 bytes, there's no protection against overwriting of the storage if one day there is.
Copy no more than the destination size, and enforce it.
Also had to turn MAX_FILTER_STR_VAL into an unsigned int, to keep the min() comparison of the string sizes of comparable types.
include/linux/trace_events.h +1 -1
@@ -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 ),
kernel/trace/trace_events_hist.c +7 -2
@@ -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);
@@ -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;
@@ -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; }
The pull request you sent on Sun, 14 Nov 2021 21:33:17 -0500:
The pull request you sent on Sun, 14 Nov 2021 21:33:17 -0500:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.gittrace-v5.16-5
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/8ab774587903771821b59471cc723bba6d893942
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html