From: sashiko-bot@kernel.org
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v12 11/11] tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger
Date: Fri, 07 Aug 2026 15:59:30 +0000 [thread overview]
Message-ID: <20260807155931.302251F000E9@smtp.kernel.org> (raw)
In-Reply-To: <178611692137.237811.11807565234101581407.stgit@devnote2>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium] Speculative field parsing for `clear_wprobe` commands unconditionally logs spurious errors and masks genuine syntax/memory errors.
Pre-existing issues:
- [Critical] Mixing `__free` scope-based cleanup with manual async cleanup on the error path causes double free and lockless list corruption.
--
--- Patch [11]: [PATCH v12 11/11] tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger ---
commit f9bc82719437cd2a74bad3f90ad83888d83a0ed4
Author: Masami Hiramatsu (Google) <mhiramat@kernel.org>
tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger
Allow set_wprobe trigger to use BTF struct offset resolution to specify
the target address field.
Link: https://lore.kernel.org/all/59637b96946653393a7ad3c7de094094796b39c2.1785067572.git.wangjinchao600@gmail.com/
> diff --git a/kernel/trace/trace_wprobe.c b/kernel/trace/trace_wprobe.c
> index c64bbdc90a40c..565c106a93805 100644
> --- a/kernel/trace/trace_wprobe.c
> +++ b/kernel/trace/trace_wprobe.c
[ ... ]
> @@ -1013,10 +1190,9 @@ static int wprobe_trigger_cmd_parse(struct event_command *cmd_ops,
> */
> struct wprobe_trigger_data *wprobe_data __free(free_wprobe_trigger_data) = NULL;
> struct event_trigger_data *trigger_data __free(kfree) = NULL;
[Severity: Critical]
This is a pre-existing issue, but does using __free() here cause a double-free
on the error paths?
If event_trigger_register() fails later in wprobe_trigger_cmd_parse(), it
calls event_trigger_free(trigger_data). This queues the trigger onto the
lockless trigger_data_free_list for asynchronous freeing by a background
kthread.
However, when the error path returns without clearing trigger_data, the
compiler-inserted __free destructors execute synchronously. This immediately
frees both wprobe_data and trigger_data while they are still linked in the
kthread's cleanup list.
When the kthread eventually processes the list, could it traverse freed
memory, trigger a use-after-free, and attempt to free the objects again?
> - char *event_str, *field_str, *count_str, *comment;
> + char *event_str, *comment;
> struct trace_event_file *wprobe_file;
> struct trace_array *tr = file->tr;
> - struct trace_event_call *event;
> bool remove, clear = false;
> struct trace_wprobe *tw;
> char *param, *filter;
[ ... ]
> @@ -1075,42 +1251,24 @@ static int wprobe_trigger_cmd_parse(struct event_command *cmd_ops,
>
> /* clear_wprobe does not need field. */
> if (!clear) {
> - char *offs;
> + char *field_str = strsep(¶m, ":");
>
> - /* Find target field, which must be equivarent to "void *" */
> - field_str = strsep(¶m, ":");
> if (!field_str) {
> wprobe_trigger_log_err(file, glob, strlen(glob), WPROBE_NEED_FIELD);
> return -EINVAL;
> }
> -
> - offs = strpbrk(field_str, "+-");
> - if (offs) {
> - long val;
> -
> - if (kstrtol(offs, 0, &val) < 0) {
> - wprobe_trigger_log_err(file, glob, offs - glob, BAD_DEREF_OFFS);
> - return -EINVAL;
> - }
> - wprobe_data->adjust = val;
> - *offs = '\0';
> - }
> -
> - event = file->event_call;
> - field = trace_find_event_field(event, field_str);
> - if (!field) {
> - wprobe_trigger_log_err(file, glob, field_str - glob, NO_EVENT_FIELD);
> - return -ENOENT;
> - }
> -
> - if (field->size != sizeof(void *)) {
> - wprobe_trigger_log_err(file, glob, field_str - glob, WPROBE_BAD_FIELD);
> - return -ENOEXEC;
> + ret = wprobe_trigger_field_parse(field_str, file, wprobe_data, glob);
> + if (ret < 0)
> + return ret;
> + } else if (param) {
> + char *orig_param = param;
> + char *field_str = strsep(¶m, ":");
> +
> + ret = wprobe_trigger_field_parse(field_str, file, wprobe_data, glob);
> + if (ret < 0) {
> + /* field_str was not a field, so it must be count_str */
> + param = orig_param;
> }
[Severity: Medium]
Will this speculative field parsing unconditionally log spurious errors?
When a valid clear_wprobe command is given with a count but no field (e.g.,
clear_wprobe:watch:10), this branch speculatively attempts to parse 10 as a
field string. wprobe_trigger_field_parse() fails and unconditionally calls
wprobe_trigger_log_err(), leaving a bogus NO_EVENT_FIELD error in the trace
error_log:
kernel/trace/trace_wprobe.c:wprobe_trigger_field_parse() {
...
field = trace_find_event_field(file->event_call, field_str);
if (!field) {
wprobe_trigger_log_err(file, glob, field_str - glob, NO_EVENT_FIELD);
return -ENOENT;
}
...
}
Because this code falls back to parsing the parameter as a count upon any
negative return code, the command ultimately succeeds, but the user
receives a false-positive error in the logs.
Additionally, if field parsing encounters a genuine error (like -EINVAL
from a malformed BTF offset or -ENOMEM), will it be swallowed by the fallback
and incorrectly masked?
> - wprobe_data->offset = field->offset;
> - wprobe_data->field = kstrdup(field_str, GFP_KERNEL);
> - if (!wprobe_data->field)
> - return -ENOMEM;
> }
>
> trigger_data = trigger_data_alloc(cmd_ops, cmd, param, wprobe_data);
--
Sashiko AI review · https://sashiko.dev/#/patchset/178611679753.237811.10190793347982785419.stgit@devnote2?part=11
prev parent reply other threads:[~2026-08-07 15:59 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 15:33 [PATCH v12 00/11] tracing: wprobe: x86: Add wprobe for watchpoint Masami Hiramatsu (Google)
2026-08-07 15:33 ` [PATCH v12 01/11] x86/hw_breakpoints: Make DR7 updates NMI safe Masami Hiramatsu (Google)
2026-08-07 16:01 ` sashiko-bot
2026-08-07 15:33 ` [PATCH v12 02/11] x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API Masami Hiramatsu (Google)
2026-08-07 15:50 ` sashiko-bot
2026-08-07 15:33 ` [PATCH v12 03/11] HWBP: Add modify_local_hw_breakpoint_addr() API Masami Hiramatsu (Google)
2026-08-07 15:58 ` sashiko-bot
2026-08-07 15:34 ` [PATCH v12 04/11] tracing/wprobe: Add wprobe (watchpoint probe) trace event support Masami Hiramatsu (Google)
2026-08-07 15:59 ` sashiko-bot
2026-08-07 15:34 ` [PATCH v12 05/11] x86: hw_breakpoint: Add a kconfig to clarify when a breakpoint fires Masami Hiramatsu (Google)
2026-08-07 15:34 ` [PATCH v12 06/11] selftests: tracing: Add a basic testcase for wprobe Masami Hiramatsu (Google)
2026-08-07 15:34 ` [PATCH v12 07/11] selftests: tracing: Add syntax " Masami Hiramatsu (Google)
2026-08-07 15:34 ` [PATCH v12 08/11] tracing/wprobe: Add set_wprobe and clear_wprobe event triggers Masami Hiramatsu (Google)
2026-08-07 15:54 ` sashiko-bot
2026-08-07 15:34 ` [PATCH v12 09/11] selftests: ftrace: Add wprobe trigger testcase Masami Hiramatsu (Google)
2026-08-07 15:53 ` sashiko-bot
2026-08-07 15:35 ` [PATCH v12 10/11] tracing/wprobe: Support BTF typecast in fetchargs Masami Hiramatsu (Google)
2026-08-07 15:35 ` [PATCH v12 11/11] tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger Masami Hiramatsu (Google)
2026-08-07 15:59 ` sashiko-bot [this message]
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=20260807155931.302251F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mhiramat@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.