Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH v2] tracing: compare named histogram expressions recursively
@ 2026-12-03 19:49 Kyuwon Cho
  2026-12-03 20:09 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-12-03 19:49 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Masami Hiramatsu, Mathieu Desnoyers, Tom Zanussi, Namhyung Kim,
	linux-kernel, linux-trace-kernel

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@skku.edu>
---

Changes in v2:
- Correct the Fixes trailer to 100719dcef44, which introduced recursive
  expression operands, as identified by Sashiko.

v1: https://lore.kernel.org/all/179620737571.2194197.15463715908322121429@skku.edu/

A reproducer is available on request.

The issue was found by an LLM-guided test generator that we are
developing as a research prototype.

 kernel/trace/trace_events_hist.c | 65 +++++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 18 deletions(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index d4702ad4e003..63d06f39a5cb 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -6474,6 +6474,51 @@ 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)
+{
+	unsigned int i;
+
+	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) ||
+	    !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]))
+			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 +6526,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 +6550,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]))
 			return false;
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03 20:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 19:49 [PATCH v2] tracing: compare named histogram expressions recursively Kyuwon Cho
2026-12-03 20:09 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox