Re: [PATCH v3] tracing: compare named histogram expressions recursively
From: Steven Rostedt
Date: Fri Dec 04 2026 - 10:41:01 EST
On Fri, 4 Dec 2026 14:07:43 +0900
Kyuwon Cho <kyuwon.cho@xxxxxxxx> wrote:
> Named histogram matching checks only the outer hist_field properties.
> Different expressions with compatible wrapper fields can therefore share
> the first trigger expression tree, which can read beyond records of the
> second event.
>
> Compare the complete operand trees before sharing named histogram data.
>
> Fixes: 100719dcef44 ("tracing: Add simple expression support to hist triggers")
> Signed-off-by: Kyuwon Cho <kyuwon.cho@xxxxxxxx>
> ---
> Changes in v3:
> - Ignore the presentation-only field name when comparing constant fields,
> as identified by the Sashiko review. A folded constant is printed as a
> literal and reparsed without a name.
> - Rebase onto trace/for-next.
>
> v2: https://lore.kernel.org/all/179632407670.3855722.5777623149223641405@xxxxxxxx/
> v1: https://lore.kernel.org/all/179620737571.2194197.15463715908322121429@xxxxxxxx/
>
> The issue was found by an LLM-guided test generator that we are
> developing as a research prototype.
>
> A reproducer is available on request.
Yes please.
>
> kernel/trace/trace_events_hist.c | 66 +++++++++++++++++++++++---------
> 1 file changed, 48 insertions(+), 18 deletions(-)
>
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index d4702ad4e003..67cdf64f06c2 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -6474,6 +6474,52 @@ static bool compatible_field(struct ftrace_event_field *field,
> return true;
> }
>
> +static bool compatible_optional_string(const char *str, const char *test_str)
> +{
> + if (!str || !test_str)
> + return str == test_str;
> +
> + return strcmp(str, test_str) == 0;
> +}
> +
> +static bool compatible_hist_field(struct hist_field *field,
> + struct hist_field *test_field)
Kernel stack size is a fixed limit and recursive functions must have a
limiting field to make sure it can never exceed the expect call depth.
Add a level field:
static bool compatible_hist_field(struct hist_field *field,
struct hist_field *test_field, int level)
> +{
> + unsigned int i;
How deep do you expect this to go? 2?
if (level > 2)
return false;
> +
> + if (field->flags != test_field->flags ||
> + field->fn_num != test_field->fn_num ||
> + !compatible_field(field->field, test_field->field) ||
> + field->offset != test_field->offset ||
> + field->size != test_field->size ||
> + field->is_signed != test_field->is_signed ||
> + field->buckets != test_field->buckets ||
> + field->operator != test_field->operator ||
> + field->constant != test_field->constant ||
> + !compatible_optional_string(field->type, test_field->type) ||
> + (!(field->flags & HIST_FIELD_FL_CONST) &&
> + !compatible_optional_string(field->name, test_field->name)) ||
> + !compatible_optional_string(field->var.name,
> + test_field->var.name) ||
> + !compatible_optional_string(field->system, test_field->system) ||
> + !compatible_optional_string(field->event_name,
> + test_field->event_name))
> + return false;
> +
> + for (i = 0; i < HIST_FIELD_OPERANDS_MAX; i++) {
> + if (!field->operands[i] || !test_field->operands[i]) {
> + if (field->operands[i] != test_field->operands[i])
> + return false;
> + continue;
> + }
> + if (!compatible_hist_field(field->operands[i],
> + test_field->operands[i]))
if (!compatible_hist_field(field->operands[i],
test_field->operands[i], level + 1))
> + return false;
> + }
> +
> + return true;
> +}
> +
> static bool hist_trigger_match(struct event_trigger_data *data,
> struct event_trigger_data *data_test,
> struct event_trigger_data *named_data,
> @@ -6481,7 +6527,6 @@ static bool hist_trigger_match(struct event_trigger_data *data,
> {
> struct tracing_map_sort_key *sort_key, *sort_key_test;
> struct hist_trigger_data *hist_data, *hist_data_test;
> - struct hist_field *key_field, *key_field_test;
> unsigned int i;
>
> if (named_data && (named_data != data_test) &&
> @@ -6506,23 +6551,8 @@ static bool hist_trigger_match(struct event_trigger_data *data,
> }
>
> for_each_hist_field(i, hist_data) {
> - key_field = hist_data->fields[i];
> - key_field_test = hist_data_test->fields[i];
> -
> - if (key_field->flags != key_field_test->flags)
> - return false;
> - if (!compatible_field(key_field->field, key_field_test->field))
> - return false;
> - if (key_field->offset != key_field_test->offset)
> - return false;
> - if (key_field->size != key_field_test->size)
> - return false;
> - if (key_field->is_signed != key_field_test->is_signed)
> - return false;
> - if (!!key_field->var.name != !!key_field_test->var.name)
> - return false;
> - if (key_field->var.name &&
> - strcmp(key_field->var.name, key_field_test->var.name) != 0)
> + if (!compatible_hist_field(hist_data->fields[i],
> + hist_data_test->fields[i]))
if (!compatible_hist_field(hist_data->fields[i],
hist_data_test->fields[i], 0))
-- Steve
> return false;
> }
>