Commit
a244c241593b5b38a08f0df2cb43c26574efbdcb
tracing/histograms: Reject non-stacktrace fields for synthetic stacktrace fields
In check_synth_field(), when a synthetic event field is a stacktrace
(field->is_stack) and the histogram field is not a "long[" stacktrace
array, validation falls through to the generic size and signedness
comparison.
Because parse_synth_field() sets a stacktrace field's type to
"__data_loc unsigned long[]", its size is sizeof(u64) and
synth_field_signed() marks it as signed. Consequently, any 8-byte
signed scalar histogram field passes the fallback check, and its scalar
value is subsequently dereferenced as a kernel stacktrace pointer in
get_field_size() and trace_stack().
Furthermore, checking strstr(hist_field->type, "long[") is insufficient
because tracepoint fields defined with __bitmask() or __rel_bitmask()
also have type "__data_loc unsigned long[]" or "__rel_loc unsigned
long[]", whilst create_hist_field() treats them as 4-byte scalar values
without HIST_FIELD_FL_STACKTRACE.
Propagate HIST_FIELD_FL_STACKTRACE to variable references and field
variables (whilst excluding variable aliases from per-element
stacktrace capture), and reject any mismatch between
HIST_FIELD_FL_STACKTRACE and field->is_stack in check_synth_field().
Cc: stable@vger.kernel.org
Fixes: 00cf3d672a9d ("tracing: Allow synthetic events to pass around stacktraces")
Link: https://patch.msgid.link/20261013112449.1006088-1-lee@kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Lee Jones <lee@kernel.org> · 2026-10-13 11:24 UTC · committed by Steven Rostedt
1 file changed,
+11
−4
modified kernel/trace/trace_events_hist.c
| @@ -2121,7 +2121,8 @@ static int init_var_ref(struct hist_field *ref_field, | |||
| 2121 | 2121 | ref_field->size = var_field->size; | |
| 2122 | 2122 | ref_field->is_signed = var_field->is_signed; | |
| 2123 | 2123 | ref_field->flags |= var_field->flags & | |
| 2124 | - | (HIST_FIELD_FL_TIMESTAMP | HIST_FIELD_FL_TIMESTAMP_USECS); | |
| 2124 | + | (HIST_FIELD_FL_TIMESTAMP | HIST_FIELD_FL_TIMESTAMP_USECS | | |
| 2125 | + | HIST_FIELD_FL_STACKTRACE); | |
| 2125 | 2126 | ||
| 2126 | 2127 | if (system) { | |
| 2127 | 2128 | ref_field->system = kstrdup(system, GFP_KERNEL); | |
| @@ -3318,6 +3319,7 @@ static struct field_var *create_field_var(struct hist_trigger_data *hist_data, | |||
| 3318 | 3319 | ret = PTR_ERR(var); | |
| 3319 | 3320 | goto err; | |
| 3320 | 3321 | } | |
| 3322 | + | var->flags |= val->flags & HIST_FIELD_FL_STACKTRACE; | |
| 3321 | 3323 | ||
| 3322 | 3324 | field_var = kzalloc_obj(struct field_var); | |
| 3323 | 3325 | if (!field_var) { | |
| @@ -3946,7 +3948,10 @@ static int check_synth_field(struct synth_event *event, | |||
| 3946 | 3948 | && field->is_dynamic) | |
| 3947 | 3949 | return 0; | |
| 3948 | 3950 | ||
| 3949 | - | if (strstr(hist_field->type, "long[") && field->is_stack) | |
| 3951 | + | if (!!(hist_field->flags & HIST_FIELD_FL_STACKTRACE) != field->is_stack) | |
| 3952 | + | return -EINVAL; | |
| 3953 | + | ||
| 3954 | + | if (field->is_stack) | |
| 3950 | 3955 | return 0; | |
| 3951 | 3956 | ||
| 3952 | 3957 | if (strcmp(field->type, hist_field->type) != 0) { | |
| @@ -4487,7 +4492,8 @@ static int create_var_field(struct hist_trigger_data *hist_data, | |||
| 4487 | 4492 | if (!ret && hist_data->fields[val_idx]->flags & HIST_FIELD_FL_EXECNAME) | |
| 4488 | 4493 | update_var_execname(hist_data->fields[val_idx]); | |
| 4489 | 4494 | ||
| 4490 | - | if (!ret && hist_data->fields[val_idx]->flags & | |
| 4495 | + | if (!ret && !(hist_data->fields[val_idx]->flags & HIST_FIELD_FL_ALIAS) && | |
| 4496 | + | hist_data->fields[val_idx]->flags & | |
| 4491 | 4497 | (HIST_FIELD_FL_STRING | HIST_FIELD_FL_STACKTRACE)) | |
| 4492 | 4498 | hist_data->fields[val_idx]->var_str_idx = hist_data->n_var_str++; | |
| 4493 | 4499 | ||
| @@ -5228,7 +5234,8 @@ static void hist_trigger_elt_update(struct hist_trigger_data *hist_data, | |||
| 5228 | 5234 | if (hist_field->flags & HIST_FIELD_FL_VAR) { | |
| 5229 | 5235 | var_idx = hist_field->var.idx; | |
| 5230 | 5236 | ||
| 5231 | - | if (hist_field->flags & | |
| 5237 | + | if (!(hist_field->flags & HIST_FIELD_FL_ALIAS) && | |
| 5238 | + | hist_field->flags & | |
| 5232 | 5239 | (HIST_FIELD_FL_STRING | HIST_FIELD_FL_STACKTRACE)) { | |
| 5233 | 5240 | unsigned int str_start, var_str_idx, idx; | |
| 5234 | 5241 | char *str, *val_str; | |