From: sashiko-bot@kernel.org
To: "Henry Martin" <bsdhenrymartin@gmail.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v3] tracing/probes: Fix use-after-free on field name/type of multi-probe events
Date: Tue, 25 Aug 2026 11:37:13 +0000 [thread overview]
Message-ID: <20260825113714.188131F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260825111210.3271443-1-bsdhenrymartin@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Error handling in `traceprobe_define_arg_fields()` does not clean up `tpe->field_strings` or reset `tpe->nr_field_strings` on failure, leading to a memory leak, slab out-of-bounds write, and arbitrary free upon retry.
--
--- Patch [1]: [PATCH v3] tracing/probes: Fix use-after-free on field name/type of multi-probe events ---
commit b40c9f727280d82f97af5f38c001f0fd57efcf5e
Author: Henry Martin <bsdhenrymartin@gmail.com>
tracing/probes: Fix use-after-free on field name/type of multi-probe events
This commit addresses a use-after-free issue where an event's fields might
reference freed memory after one of its probes is removed. It fixes this by
allocating a duplicate set of name and type strings directly owned by the
trace_probe_event, ensuring they outlive any individual probe.
> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> index 36dff277de464..3057d31c57376 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -965,19 +965,48 @@ int traceprobe_set_print_fmt(struct trace_probe *tp, enum probe_print_type ptype
> int traceprobe_define_arg_fields(struct trace_event_call *event_call,
> size_t offset, struct trace_probe *tp)
> {
> + struct trace_probe_event *tpe = trace_probe_event_from_call(event_call);
> int ret, i;
>
> + /*
> + * A field created by trace_define_field() only stores the name and
> + * type pointers, it does not copy the strings. Here they point into
> + * the probe_arg of @tp, which is freed when @tp is removed. For a
> + * multi-probe event the field list is defined once by the first probe
> + * but kept alive by the surviving siblings, so removing that first
> + * probe would leave the fields referencing freed memory. Make the
> + * event own duplicates that live as long as the event call itself.
> + */
> + if (tp->nr_args) {
> + tpe->field_strings = kcalloc(tp->nr_args * 2, sizeof(char *),
> + GFP_KERNEL);
> + if (!tpe->field_strings)
> + return -ENOMEM;
> + }
> +
> /* Set argument names as fields */
> for (i = 0; i < tp->nr_args; i++) {
> struct probe_arg *parg = &tp->args[i];
> const char *fmt = parg->type->fmttype;
> int size = parg->type->size;
> + char *name, *type;
>
> if (parg->fmt)
> fmt = parg->fmt;
> if (parg->count)
> size *= parg->count;
> - ret = trace_define_field(event_call, fmt, parg->name,
> +
> + name = kstrdup(parg->name, GFP_KERNEL);
> + type = kstrdup(fmt, GFP_KERNEL);
> + if (!name || !type) {
> + kfree(name);
> + kfree(type);
> + return -ENOMEM;
> + }
> + tpe->field_strings[tpe->nr_field_strings++] = name;
> + tpe->field_strings[tpe->nr_field_strings++] = type;
> +
> + ret = trace_define_field(event_call, type, name,
> offset + parg->offset, size,
> parg->type->is_signed,
> FILTER_OTHER);
> + if (ret)
> + return ret;
[Severity: High]
If trace_define_field() fails, does this error path leak the newly allocated
strings and the tpe->field_strings array?
Looking at event_define_fields() in kernel/trace/trace_events.c, the return
value from this function is ignored:
if (field->type == TRACE_FUNCTION_TYPE) {
field->define_fields(call);
break;
}
Since the return value is ignored and the event's field list remains empty
if the first argument fails, couldn't the system invoke this function again
on retry if there are multiple trace array instances?
If it is retried, the initial kcalloc() unconditionally overwrites
tpe->field_strings, leaking the old array.
Additionally, since tpe->nr_field_strings is not reset on failure, wouldn't
a retry start appending string pointers out of bounds of the new array?
This appears like it could eventually cause trace_probe_event_free() to read
out-of-bounds pointers and pass them to kfree().
> }
> return 0;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260825111210.3271443-1-bsdhenrymartin@gmail.com?part=1
next prev parent reply other threads:[~2026-08-25 11:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 7:10 [PATCH] tracing: Fix use-after-free on field name/type of dynamic probe events Henry Martin
2026-08-24 7:27 ` sashiko-bot
2026-08-24 18:43 ` Steven Rostedt
2026-08-25 11:12 ` [PATCH v3] tracing/probes: Fix use-after-free on field name/type of multi-probe events Henry Martin
2026-08-25 11:37 ` sashiko-bot [this message]
2026-08-25 14:22 ` Steven Rostedt
2026-08-26 3:00 ` [PATCH v4] tracing/probes: Fix use-after-free on field name/type of events with multiple probes Henry Martin
2026-08-26 3:11 ` [PATCH v3] tracing/probes: Fix use-after-free on field name/type of multi-probe events henry martin
2026-08-25 13:51 ` Steven Rostedt
[not found] ` <CAEnQdOo0qHQK5veJp0Ybf3Hm3Gn2iUicL9Xj_bTNZKhoMfFOTw@mail.gmail.com>
2026-08-25 13:38 ` [PATCH] tracing: Fix use-after-free on field name/type of dynamic probe events 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=20260825113714.188131F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bsdhenrymartin@gmail.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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