From: Steven Rostedt <rostedt@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
stable@vger.kernel.org, Lee Jones <lee@kernel.org>
Subject: [for-linus][PATCH 5/8] tracing/histograms: Reject non-string fields for synthetic string fields
Date: Thu, 03 Dec 2026 09:17:30 -0500 [thread overview]
Message-ID: <20261203141756.990099293@kernel.org> (raw)
In-Reply-To: 20261203141725.845506016@kernel.org
From: Lee Jones <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().
Cc: stable@vger.kernel.org
Fixes: b05e89ae7cf3 ("tracing: Accept different type for synthetic event fields")
Link: https://patch.msgid.link/20261201142918.1849179-2-lee@kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.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.53.0
next prev parent reply other threads:[~2026-12-03 14:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 14:17 [for-linus][PATCH 0/8] tracing: Fixes for v7.4 Steven Rostedt
2026-12-03 14:17 ` [for-linus][PATCH 1/8] tracing: Fix crash on lseek of recursed_functions file in WRONLY mode Steven Rostedt
2026-12-03 14:17 ` [for-linus][PATCH 2/8] tracing/filters: Fix glob matching on zero size string fields Steven Rostedt
2026-12-03 14:17 ` [for-linus][PATCH 3/8] ring-buffer: Use irqsave for the reader lock in ring_buffer_poll_remote Steven Rostedt
2026-12-03 14:17 ` [for-linus][PATCH 4/8] ring-buffer: Avoid reader_lock deadlock during panic Steven Rostedt
2026-12-03 14:17 ` Steven Rostedt [this message]
2026-12-03 14:17 ` [for-linus][PATCH 6/8] tracing: Free all event filters after RCU synchronization Steven Rostedt
2026-12-03 14:17 ` [for-linus][PATCH 7/8] tracing: Fix trace_event_file leak on read-only instances Steven Rostedt
2026-12-03 14:17 ` [for-linus][PATCH 8/8] tracing: Reject backup instance opens only after autoremove is queued Steven Rostedt
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=20261203141756.990099293@kernel.org \
--to=rostedt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=stable@vger.kernel.org \
/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