The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Tom Zanussi <tom.zanussi@linux.intel.com>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 1/2] tracing/histograms: Reject non-string fields for synthetic string fields
Date: Tue,  1 Dec 2026 14:29:06 +0000	[thread overview]
Message-ID: <20261201142918.1849179-2-lee@kernel.org> (raw)
In-Reply-To: <20261201142918.1849179-1-lee@kernel.org>

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@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 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


  reply	other threads:[~2026-12-01 14:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 14:29 [PATCH 0/2] tracing: Harden synthetic event string validation and copying Lee Jones
2026-12-01 14:29 ` Lee Jones [this message]
2026-12-01 14:29 ` [PATCH 2/2] tracing/synthetic: Bound dynamic string copy to reserved length Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201142918.1849179-2-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.org \
    --cc=tom.zanussi@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox