* [PATCH] tracing/histograms: Reject non-stacktrace fields for synthetic stacktrace fields
@ 2026-10-12 15:58 Lee Jones
2026-10-12 16:13 ` sashiko-bot
0 siblings, 1 reply; 3+ messages in thread
From: Lee Jones @ 2026-10-12 15:58 UTC (permalink / raw)
To: lee, Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
linux-kernel, linux-trace-kernel
Cc: stable
In check_synth_field(), when a synthetic event field is a stacktrace
(field->is_stack) and the histogram field is not a "long[" stacktrace
array, validation falls through to the generic size and signedness
comparison.
Because parse_synth_field() sets a stacktrace field's type to
"__data_loc unsigned long[]", its size is sizeof(u64) and
synth_field_signed() marks it as signed. Consequently, any 8-byte
signed scalar histogram field passes the fallback check, and its scalar
value is subsequently dereferenced as a kernel stacktrace pointer in
get_field_size() and trace_stack().
Reject any mismatch between field->is_stack and a "long[" histogram
field type in check_synth_field().
Fixes: 00cf3d672a9d ("tracing: Allow synthetic events to pass around stacktraces")
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
kernel/trace/trace_events_hist.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 8af97fd4ee2d..b09f5043e154 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -3946,7 +3946,10 @@ static int check_synth_field(struct synth_event *event,
&& field->is_dynamic)
return 0;
- if (strstr(hist_field->type, "long[") && field->is_stack)
+ if (!!strstr(hist_field->type, "long[") != field->is_stack)
+ return -EINVAL;
+
+ if (field->is_stack)
return 0;
if (strcmp(field->type, hist_field->type) != 0) {
--
2.56.0.385.gd3acb90ef8-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] tracing/histograms: Reject non-stacktrace fields for synthetic stacktrace fields
2026-10-12 15:58 [PATCH] tracing/histograms: Reject non-stacktrace fields for synthetic stacktrace fields Lee Jones
@ 2026-10-12 16:13 ` sashiko-bot
2026-10-13 9:19 ` Lee Jones
0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-10-12 16:13 UTC (permalink / raw)
To: Lee Jones; +Cc: linux-trace-kernel
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] tracing: check_synth_field regression for __bitmask and stacktraces
- [High] tracing: arbitrary memory read via scalar to string synthetic field mapping
--
commit 4813d717e995df13871068dd6fd996711ca8965d
Author: Lee Jones <lee@kernel.org>
tracing/histograms: Reject non-stacktrace fields for synthetic stacktrace fields
In check_synth_field(), when a synthetic event field is a stacktrace
and the histogram field is not a "long[" stacktrace array, validation falls
through to the generic size and signedness comparison. This allows any
8-byte signed scalar histogram field to pass the fallback check and be
dereferenced as a kernel stacktrace pointer. This commit attempts to reject
these mismatches by enforcing that field->is_stack matches the "long[" type.
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index 8af97fd4ee2d5..b09f5043e1543 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -3946,7 +3946,10 @@ static int check_synth_field(struct synth_event *event,
> && field->is_dynamic)
> return 0;
>
> - if (strstr(hist_field->type, "long[") && field->is_stack)
> + if (!!strstr(hist_field->type, "long[") != field->is_stack)
> + return -EINVAL;
[Severity: High]
Does this heuristic falsely match the long[ substring in __data_loc unsigned
long[] from __bitmask and __cpumask fields?
If is_stack == false, this logic seems to falsely reject valid mappings.
If is_stack == true, this appears to bypass validation and allow a 32-bit
__data_loc integer to be passed as the field value. Could this 32-bit integer
then be cast to a pointer and dereferenced in
trace_events_synth.c:get_field_size() and trace_stack(), potentially causing
a kernel panic?
> +
> + if (field->is_stack)
> return 0;
>
> if (strcmp(field->type, hist_field->type) != 0) {
> if (field->size != hist_field->size ||
> (!field->is_string && field->is_signed != hist_field->is_signed))
> return -EINVAL;
> }
[Severity: High]
It looks like this fallback logic fails to reject a scalar-to-string mapping.
When creating a dynamic string synthetic field, its size is set to sizeof(u64)
and is_string is true. Because field->size equals hist_field->size (8 bytes)
and !field->is_string short-circuits the type/signedness check, will an 8-byte
scalar successfully map to a dynamic string?
If an attacker-controlled scalar is passed, can it be cast to a kernel pointer
in trace_events_synth.c:trace_string() and used with fetch_store_strlen() to
arbitrarily read kernel memory?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261012155805.1103972-1-lee@kernel.org?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] tracing/histograms: Reject non-stacktrace fields for synthetic stacktrace fields
2026-10-12 16:13 ` sashiko-bot
@ 2026-10-13 9:19 ` Lee Jones
0 siblings, 0 replies; 3+ messages in thread
From: Lee Jones @ 2026-10-13 9:19 UTC (permalink / raw)
To: sashiko-reviews; +Cc: linux-trace-kernel
On Mon, 12 Oct 2026, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] tracing: check_synth_field regression for __bitmask and stacktraces
> - [High] tracing: arbitrary memory read via scalar to string synthetic field mapping
Fixing now - v2 to follow shortly. Bear with.
> --
>
> commit 4813d717e995df13871068dd6fd996711ca8965d
> Author: Lee Jones <lee@kernel.org>
>
> tracing/histograms: Reject non-stacktrace fields for synthetic stacktrace fields
>
> In check_synth_field(), when a synthetic event field is a stacktrace
> and the histogram field is not a "long[" stacktrace array, validation falls
> through to the generic size and signedness comparison. This allows any
> 8-byte signed scalar histogram field to pass the fallback check and be
> dereferenced as a kernel stacktrace pointer. This commit attempts to reject
> these mismatches by enforcing that field->is_stack matches the "long[" type.
>
> > diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> > index 8af97fd4ee2d5..b09f5043e1543 100644
> > --- a/kernel/trace/trace_events_hist.c
> > +++ b/kernel/trace/trace_events_hist.c
> > @@ -3946,7 +3946,10 @@ static int check_synth_field(struct synth_event *event,
> > && field->is_dynamic)
> > return 0;
> >
> > - if (strstr(hist_field->type, "long[") && field->is_stack)
> > + if (!!strstr(hist_field->type, "long[") != field->is_stack)
> > + return -EINVAL;
>
> [Severity: High]
> Does this heuristic falsely match the long[ substring in __data_loc unsigned
> long[] from __bitmask and __cpumask fields?
>
> If is_stack == false, this logic seems to falsely reject valid mappings.
>
> If is_stack == true, this appears to bypass validation and allow a 32-bit
> __data_loc integer to be passed as the field value. Could this 32-bit integer
> then be cast to a pointer and dereferenced in
> trace_events_synth.c:get_field_size() and trace_stack(), potentially causing
> a kernel panic?
>
> > +
> > + if (field->is_stack)
> > return 0;
> >
> > if (strcmp(field->type, hist_field->type) != 0) {
> > if (field->size != hist_field->size ||
> > (!field->is_string && field->is_signed != hist_field->is_signed))
> > return -EINVAL;
> > }
>
> [Severity: High]
> It looks like this fallback logic fails to reject a scalar-to-string mapping.
>
> When creating a dynamic string synthetic field, its size is set to sizeof(u64)
> and is_string is true. Because field->size equals hist_field->size (8 bytes)
> and !field->is_string short-circuits the type/signedness check, will an 8-byte
> scalar successfully map to a dynamic string?
>
> If an attacker-controlled scalar is passed, can it be cast to a kernel pointer
> in trace_events_synth.c:trace_string() and used with fetch_store_strlen() to
> arbitrarily read kernel memory?
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261012155805.1103972-1-lee@kernel.org?part=1
--
Lee Jones
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-13 9:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-12 15:58 [PATCH] tracing/histograms: Reject non-stacktrace fields for synthetic stacktrace fields Lee Jones
2026-10-12 16:13 ` sashiko-bot
2026-10-13 9:19 ` Lee Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox