Skip to content
/ linux Public

Commit 75668e5

Browse files
rostedtgregkh
authored andcommitted
tracing: Fix trace_marker copy link list updates
[ Upstream commit 07183aa ] When the "copy_trace_marker" option is enabled for an instance, anything written into /sys/kernel/tracing/trace_marker is also copied into that instances buffer. When the option is set, that instance's trace_array descriptor is added to the marker_copies link list. This list is protected by RCU, as all iterations uses an RCU protected list traversal. When the instance is deleted, all the flags that were enabled are cleared. This also clears the copy_trace_marker flag and removes the trace_array descriptor from the list. The issue is after the flags are called, a direct call to update_marker_trace() is performed to clear the flag. This function returns true if the state of the flag changed and false otherwise. If it returns true here, synchronize_rcu() is called to make sure all readers see that its removed from the list. But since the flag was already cleared, the state does not change and the synchronization is never called, leaving a possible UAF bug. Move the clearing of all flags below the updating of the copy_trace_marker option which then makes sure the synchronization is performed. Also use the flag for checking the state in update_marker_trace() instead of looking at if the list is empty. Cc: stable@vger.kernel.org Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Link: https://patch.msgid.link/20260318185512.1b6c7db4@gandalf.local.home Fixes: 7b382ef ("tracing: Allow the top level trace_marker to write into another instances") Reported-by: Sasha Levin <sashal@kernel.org> Closes: https://lore.kernel.org/all/20260225133122.237275-1-sashal@kernel.org/ Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 79f0faf commit 75668e5

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

kernel/trace/trace.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -569,18 +569,18 @@ static bool update_marker_trace(struct trace_array *tr, int enabled)
569569
lockdep_assert_held(&event_mutex);
570570

571571
if (enabled) {
572-
if (!list_empty(&tr->marker_list))
572+
if (tr->trace_flags & TRACE_ITER_COPY_MARKER)
573573
return false;
574574

575575
list_add_rcu(&tr->marker_list, &marker_copies);
576576
tr->trace_flags |= TRACE_ITER_COPY_MARKER;
577577
return true;
578578
}
579579

580-
if (list_empty(&tr->marker_list))
580+
if (!(tr->trace_flags & TRACE_ITER_COPY_MARKER))
581581
return false;
582582

583-
list_del_init(&tr->marker_list);
583+
list_del_rcu(&tr->marker_list);
584584
tr->trace_flags &= ~TRACE_ITER_COPY_MARKER;
585585
return true;
586586
}
@@ -10232,18 +10232,19 @@ static int __remove_instance(struct trace_array *tr)
1023210232

1023310233
list_del(&tr->list);
1023410234

10235-
/* Disable all the flags that were enabled coming in */
10236-
for (i = 0; i < TRACE_FLAGS_MAX_SIZE; i++) {
10237-
if ((1 << i) & ZEROED_TRACE_FLAGS)
10238-
set_tracer_flag(tr, 1 << i, 0);
10239-
}
10240-
1024110235
if (printk_trace == tr)
1024210236
update_printk_trace(&global_trace);
1024310237

10238+
/* Must be done before disabling all the flags */
1024410239
if (update_marker_trace(tr, 0))
1024510240
synchronize_rcu();
1024610241

10242+
/* Disable all the flags that were enabled coming in */
10243+
for (i = 0; i < TRACE_FLAGS_MAX_SIZE; i++) {
10244+
if ((1 << i) & ZEROED_TRACE_FLAGS)
10245+
set_tracer_flag(tr, 1 << i, 0);
10246+
}
10247+
1024710248
tracing_set_nop(tr);
1024810249
clear_ftrace_function_probes(tr);
1024910250
event_trace_del_tracer(tr);

0 commit comments

Comments
 (0)