From: sashiko-bot@kernel.org
To: "Li Pengfei" <ljdlns1987@gmail.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v8 2/5] tracing: Use the stackmap from the ftrace stack recording path
Date: Sat, 07 Nov 2026 06:17:49 +0000 [thread overview]
Message-ID: <sashiko-outbox-202658@kernel.org> (raw)
In-Reply-To: <20261107055139.3138633-3-lipengfei28@xiaomi.com>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] tracing: missing RCU grace period in update_marker_trace()
on disable [1]
--
commit 7075e3df3e37a58db04cf4e9626607b29d78b5fc
Author: Pengfei Li <lipengfei28@xiaomi.com>
tracing: Use the stackmap from the ftrace stack recording path
This commit hooks the stackmap into __ftrace_trace_stack() when the new
stackmap trace option is enabled, recording a TRACE_STACK_ID event with
the stack cookie and adding a "free" command to stack_map to release the
map when disabled.
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 18710c190c924..cdae2976d224f 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
[ ... ]
> @@ -3996,6 +4101,15 @@ int set_tracer_flag(struct trace_array *tr, u64 mask, int enabled)
> return -EINVAL;
>
> switch (mask) {
> + case TRACE_ITER(STACKMAP):
> + if (enabled) {
> + int ret = stackmap_set_flag(tr);
> +
> + if (ret)
> + return ret;
> + }
> + break;
> +
> case TRACE_ITER(TRACE_PRINTK):
[Severity: Critical]
This problem wasn't introduced by this patch, but can disabling
TRACE_ITER(COPY_MARKER) in set_tracer_flag() cause a use-after-free of tr
or corrupt marker_copies [1]?
kernel/trace/trace.c:update_marker_trace() {
...
if (!(tr->trace_flags & TRACE_ITER(COPY_MARKER)))
return false;
list_del_rcu(&tr->marker_list);
tr->trace_flags &= ~TRACE_ITER(COPY_MARKER);
return true;
}
In set_tracer_flag(), the TRACE_ITER(COPY_MARKER) case calls
update_marker_trace() without waiting for an RCU grace period when
disabling the flag. Meanwhile, tracing_mark_write() and
tracing_mark_raw_write() walk marker_copies under RCU without holding
event_mutex:
CPU0 CPU1
tracing_mark_write()
rcu_read_lock_sched_notrace()
list_for_each_entry_rcu(tr,
&marker_copies, marker_list)
set_tracer_flag(tr, COPY_MARKER, 0)
update_marker_trace(tr, 0)
list_del_rcu(&tr->marker_list)
tr->trace_flags &= ~COPY_MARKER
__remove_instance(tr)
if (update_marker_trace(tr, 0))
synchronize_rcu() // skipped
free_trace_buffers(tr)
kfree(tr)
__trace_array_vprintk(tr->...) <-- use-after-free
Because COPY_MARKER was already cleared by set_tracer_flag(),
__remove_instance() sees update_marker_trace(tr, 0) return false, skips
synchronize_rcu(), and frees tr while CPU0 is still writing to it.
Similarly, toggling COPY_MARKER off and immediately back on re-inserts
tr->marker_list with list_add_rcu() before concurrent RCU readers have
finished traversing from it.
[1] https://sashiko.dev/#/bug/linux-3d780d38-c496-44e0-a5a4-9138bd4d11a0
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261107055139.3138633-1-lipengfei28@xiaomi.com?part=2
next prev parent reply other threads:[~2026-11-07 6:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 5:51 [PATCH v8 0/5] tracing: Add stack trace deduplication for the ring buffer Li Pengfei
2026-11-07 5:51 ` [PATCH v8 1/5] tracing: Add lock-free stackmap for stack trace deduplication Li Pengfei
2026-11-07 5:51 ` [PATCH v8 2/5] tracing: Use the stackmap from the ftrace stack recording path Li Pengfei
2026-11-07 6:17 ` sashiko-bot [this message]
2026-11-07 22:35 ` kernel test robot
2026-11-08 7:24 ` Pengfei Li
2026-11-07 5:51 ` [PATCH v8 3/5] tracing: Add stackmap statistics interface Li Pengfei
2026-11-07 6:04 ` sashiko-bot
2026-11-07 6:28 ` Li Pengfei
2026-11-07 5:51 ` [PATCH v8 4/5] Documentation: tracing: Document the ftrace stackmap Li Pengfei
2026-11-07 5:51 ` [PATCH v8 5/5] selftests/ftrace: Add a stackmap basic functionality test Li Pengfei
2026-11-07 6:07 ` sashiko-bot
2026-11-07 6:28 ` Li Pengfei
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-202658@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=ljdlns1987@gmail.com \
--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.