Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH] tracing: Do not cache the event across trace_pipe splice calls
@ 2026-12-04 18:50 David Carlier
  0 siblings, 0 replies; only message in thread
From: David Carlier @ 2026-12-04 18:50 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Mathieu Desnoyers, linux-trace-kernel, linux-kernel,
	David Carlier, stable

tracing_fill_pipe_page() leaves iter->ent set when an event does not
fit, and the next splice prints it without looking it up again. The
reader page it points into can be freed in between, for instance by a
write to buffer_subbuf_size_kb.

Look the event up on every call under the reader locks and clear
iter->ent before dropping them.

Fixes: 3c56819b14b0 ("tracing: splice support for tracing_pipe")
Cc: stable@vger.kernel.org
Signed-off-by: David Carlier <devnexen@gmail.com>
---
 kernel/trace/trace.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 181b565786a9..a399707b62c7 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -5626,14 +5626,20 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
 	if (ret <= 0)
 		goto out_err;
 
-	if (!iter->ent && !trace_find_next_entry_inc(iter)) {
+	trace_event_read_lock();
+	trace_access_lock(iter->cpu_file);
+
+	/*
+	 * An event that did not fit in the previous call was not consumed
+	 * so we look it up again in case the buffer changed in the meantime.
+	 */
+	if (!trace_find_next_entry_inc(iter)) {
+		trace_access_unlock(iter->cpu_file);
+		trace_event_read_unlock();
 		ret = -EFAULT;
 		goto out_err;
 	}
 
-	trace_event_read_lock();
-	trace_access_lock(iter->cpu_file);
-
 	/* Fill as many pages as possible. */
 	for (i = 0, rem = len; i < spd.nr_pages_max && rem; i++) {
 		spd.pages[i] = alloc_page(GFP_KERNEL);
@@ -5657,6 +5663,8 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
 		trace_seq_init(&iter->seq);
 	}
 
+	/* Do not keep a pointer into the ring buffer */
+	iter->ent = NULL;
 	trace_access_unlock(iter->cpu_file);
 	trace_event_read_unlock();
 	mutex_unlock(&iter->mutex);
-- 
2.55.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-04 18:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:50 [PATCH] tracing: Do not cache the event across trace_pipe splice calls David Carlier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox