Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v20 04/11] tracing/wprobe: Add wprobe (watchpoint probe) trace event support
Date: Mon, 16 Nov 2026 05:56:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-216236@kernel.org> (raw)
In-Reply-To: <179480679855.38065.12988926948228161902.stgit@devnote2>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] tracing/wprobe: unheld lock and symbol lookup in
  trace_wprobe_match()
- [Medium] tracing/wprobe: TASK_SIZE check in
  trace_wprobe_is_valid_addr()
- [Medium] tracing/wprobe: trace_ctx underflow in wprobe_trace_handler()
--

commit ba36417426baa731cd50929b7289160f5b44d5a3
Author: Masami Hiramatsu (Google) <mhiramat@kernel.org>

tracing/wprobe: Add wprobe (watchpoint probe) trace event support

This commit adds hardware-breakpoint-based dynamic trace event support
(wprobe) to trace data read and write accesses and log the access context
and fetchargs.

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
> new file mode 100644
> index 0000000000000..644183cf5155e
> --- /dev/null
> +++ b/kernel/trace/trace_wprobe.c
[ ... ]
> +static bool trace_wprobe_match_command_head(struct trace_wprobe *tw,
> +					    int argc, const char **argv)
> +{
> +	char *symbol __free(kfree) = NULL;
> +	unsigned long addr;
> +	int type, len, offset;
> +
> +	if (!argc)
> +		return true;
> +
> +	if (parse_address_spec(argv[0], &addr, &type, &len, &symbol, &offset))
> +		return false;
> +
> +	if (tw->type != type || tw->len != len)
> +		return false;
> +
> +	if (tw->symbol) {
> +		if (!symbol || strcmp(tw->symbol, symbol) != 0 ||
> +		    tw->offset != offset)
> +			return false;
> +	} else if (symbol || tw->addr != addr) {
> +		return false;
> +	}
> +
> +	argc--;
> +	argv++;
> +	return trace_probe_match_command_args(&tw->tp, argc, argv);
> +}

[Severity: Medium]
Can calling parse_address_spec() from trace_wprobe_match_command_head()
trigger a lockdep warning and race on trace_probe_log?

dyn_event_release() invokes pos->ops->match() under event_mutex without
holding dyn_event_ops_mutex.  When argv[0] does not parse as a valid wprobe
specification (for example, while dyn_event_release() walks past a wprobe
when removing another probe type with arguments, or when a user passes a
non-matching spec), parse_address_spec() calls trace_probe_log_err() ->
__trace_probe_log_err():

kernel/trace/trace_probe.c:__trace_probe_log_err() {
	lockdep_assert_held(&dyn_event_ops_mutex);

	if (!trace_probe_log.argv || !trace_probe_log.argc)
		return;
    ...
}

Because dyn_event_ops_mutex is not held, lockdep_assert_held() fires and
__trace_probe_log_err() can race with a concurrent dyn_event_create() thread
initializing or freeing trace_probe_log.argv.

In addition, parse_address_spec() requires kallsyms_lookup_name() to succeed
even when matching a symbol-based wprobe where only tw->symbol and tw->offset
are compared.  If the watched module has been unloaded, kallsyms_lookup_name()
returns 0 and prevents removing the wprobe using its full specification.

[ ... ]

> +static void wprobe_trace_handler(struct trace_wprobe *tw,
> +				 unsigned long addr,
> +				 struct pt_regs *regs,
> +				 struct trace_event_file *trace_file)
> +{
> +	struct wprobe_trace_entry_head *entry;
> +	struct trace_event_call *call = trace_probe_event_call(&tw->tp);
> +	struct trace_event_buffer fbuffer;
> +	int dsize;
> +
> +	if (WARN_ON_ONCE(call != trace_file->event_call))
> +		return;
> +
> +	if (trace_trigger_soft_disabled(trace_file))
> +		return;
> +
> +	if (READ_ONCE(tw->addr) != addr)
> +		return;
> +
> +	dsize = __get_data_size(&tw->tp, (void *)addr, NULL);
> +
> +	entry = trace_event_buffer_reserve(&fbuffer, trace_file,
> +					   sizeof(*entry) + tw->tp.size + dsize);
> +	if (!entry)
> +		return;

[Severity: Medium]
Does calling trace_event_buffer_reserve() without disabling preemption
underflow trace_ctx when CONFIG_PREEMPTION is enabled?

Hardware breakpoint exceptions invoke perf_bp_event() -> ... ->
wprobe_perf_handler() with interrupts disabled, without incrementing the low
8-bit preemption count.  trace_event_buffer_reserve() calls
tracing_gen_ctx_dec(), which decrements trace_ctx assuming the caller disabled
preemption.  When a watchpoint hits in preemptible kernel context where the
preemption and migration-disable counts are 0, subtracting 1 underflows those
fields to 0xff and borrows from bit 16 (TRACE_FLAG_IRQS_OFF), corrupting the
recorded preempt_count and clearing the irqs-off flag in the trace entry.
Acquiring guard(preempt_notrace)() before trace_event_buffer_reserve() (as in
trace_fprobe.c) avoids the underflow.

[ ... ]

> +static bool trace_wprobe_is_valid_addr(unsigned long addr, int len)
> +{
> +	if (addr < TASK_SIZE)
> +		return false;
> +
> +	if (addr & (len - 1))
> +		return false;
> +
> +	return true;
> +}

[Severity: Medium]
Should trace_wprobe_is_valid_addr() check TASK_SIZE_MAX (or
arch_check_bp_in_kernelspace()) instead of TASK_SIZE?

On 64-bit architectures with CONFIG_COMPAT, TASK_SIZE evaluates to the
current task's address limit (such as IA32_PAGE_OFFSET when a 32-bit task
writes to dynamic_events), which allows addresses in [TASK_SIZE,
TASK_SIZE_MAX) to pass validation and register a CPU-wide hardware watchpoint
on a 64-bit user-space address.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=4

  reply	other threads:[~2026-11-16  5:56 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  5:25 [PATCH v20 00/11] tracing: wprobe: x86: Add wprobe for watchpoint Masami Hiramatsu (Google)
2026-11-16  5:26 ` [PATCH v20 01/11] x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API Masami Hiramatsu (Google)
2026-11-16  5:47   ` sashiko-bot
2026-11-16  5:26 ` [PATCH v20 02/11] HWBP: Add modify_local_hw_breakpoint_addr() API Masami Hiramatsu (Google)
2026-11-16  5:26 ` [PATCH v20 03/11] perf/hw_breakpoint: Add register_wide_hw_breakpoint_cpuslocked() API Masami Hiramatsu (Google)
2026-11-16  5:26 ` [PATCH v20 04/11] tracing/wprobe: Add wprobe (watchpoint probe) trace event support Masami Hiramatsu (Google)
2026-11-16  5:56   ` sashiko-bot [this message]
2026-11-16  5:26 ` [PATCH v20 05/11] x86: hw_breakpoint: Add a kconfig to clarify when a breakpoint fires Masami Hiramatsu (Google)
2026-11-16  5:27 ` [PATCH v20 06/11] selftests: tracing: Add a basic testcase for wprobe Masami Hiramatsu (Google)
2026-11-16  5:27 ` [PATCH v20 07/11] selftests: tracing: Add syntax " Masami Hiramatsu (Google)
2026-11-16  5:27 ` [PATCH v20 08/11] tracing/wprobe: Add set_wprobe and clear_wprobe event triggers Masami Hiramatsu (Google)
2026-11-16  5:27 ` [PATCH v20 09/11] selftests: tracing: Add wprobe trigger testcases Masami Hiramatsu (Google)
2026-11-16  5:52   ` sashiko-bot
2026-11-16  5:27 ` [PATCH v20 10/11] tracing/wprobe: Support BTF typecast in fetchargs Masami Hiramatsu (Google)
2026-11-16  5:27 ` [PATCH v20 11/11] tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger Masami Hiramatsu (Google)
2026-11-16  5:50   ` sashiko-bot

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=sashiko-outbox-216236@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-trace-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox