[PATCH 1/2] tracing/histograms: Reject non-string fields for synthetic string fields
From: Lee Jones
Date: Tue Dec 01 2026 - 09:29:54 EST
In check_synth_field(), when a synthetic event field is a string
(field->is_string) and the histogram field does not match the "char["
dynamic string shortcut, validation falls through to the generic size
comparison (which also skips signedness checks for string fields).
Because a dynamic string synthetic field ("__data_loc char[]") has a
size of sizeof(u64), any 8-byte scalar histogram field, constant, or
pointer field (including FILTER_PTR_STRING fields that
create_hist_field() intentionally excludes from HIST_FIELD_FL_STRING)
passes the fallback check. Its scalar value is then dereferenced as a
string pointer in get_field_size() and trace_string(). Likewise, an
8-byte scalar can match a char[8] static string synthetic field, or a
char[8] static string field can match an 8-byte scalar synthetic field
and leak a kernel pointer address.
Propagate HIST_FIELD_FL_STRING to variable references and field
variables (matching HIST_FIELD_FL_STACKTRACE, with variable aliases
already excluded from per-element string capture), and reject any
mismatch between HIST_FIELD_FL_STRING and field->is_string in
check_synth_field().
Fixes: b05e89ae7cf3 ("tracing: Accept different type for synthetic event fields")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
kernel/trace/trace_events_hist.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index d4702ad4e003..7f5ec9ff19e5 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -2138,7 +2138,7 @@ static int init_var_ref(struct hist_field *ref_field,
ref_field->is_signed = var_field->is_signed;
ref_field->flags |= var_field->flags &
(HIST_FIELD_FL_TIMESTAMP | HIST_FIELD_FL_TIMESTAMP_USECS |
- HIST_FIELD_FL_STACKTRACE);
+ HIST_FIELD_FL_STRING | HIST_FIELD_FL_STACKTRACE);
if (system) {
ref_field->system = kstrdup(system, GFP_KERNEL);
@@ -3331,7 +3331,8 @@ static struct field_var *create_field_var(struct hist_trigger_data *hist_data,
ret = PTR_ERR(var);
goto err;
}
- var->flags |= val->flags & HIST_FIELD_FL_STACKTRACE;
+ var->flags |= val->flags &
+ (HIST_FIELD_FL_STRING | HIST_FIELD_FL_STACKTRACE);
field_var = kzalloc_obj(struct field_var);
if (!field_var) {
@@ -3951,13 +3952,15 @@ static int check_synth_field(struct synth_event *event,
field = event->fields[field_pos];
+ if (!!(hist_field->flags & HIST_FIELD_FL_STRING) != field->is_string)
+ return -EINVAL;
+
/*
* A dynamic string synth field can accept static or
* dynamic. A static string synth field can only accept a
* same-sized static string, which is checked for later.
*/
- if (strstr(hist_field->type, "char[") && field->is_string
- && field->is_dynamic)
+ if (field->is_string && field->is_dynamic)
return 0;
if (!!(hist_field->flags & HIST_FIELD_FL_STACKTRACE) != field->is_stack)
--
2.56.1.839.g22a8290db9-goog