[PATCH v3 1/3] tracing: Hold file reference in splice buffer_ref
From: Masami Hiramatsu (Google)
Date: Fri Dec 04 2026 - 01:07:16 EST
From: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
tracing_buffers_splice_read() stores a raw pointer to
iter->array_buffer->buffer in each struct buffer_ref attached to the pipe
buffers, and buffer_ref_release() later dereferences ref->buffer in
ring_buffer_free_read_page() when the pipe drains or closes.
However, struct buffer_ref does not hold a reference to the source file
(and thus the owning struct trace_array). If the trace_pipe_raw file
descriptor is closed while spliced pages are still sitting in the pipe
and the trace instance is then destroyed (via manual rmdir or backup
instance autoremove), ring_buffer_free_read_page() dereferences the freed
trace_buffer, causing a use-after-free.
Store a get_file(file) reference in struct buffer_ref for each spliced
page and release it via fput() in buffer_ref_release() after
ring_buffer_free_read_page(). Holding the file reference keeps the
trace_array (including tr->trace_ref, so tracer switches and instance
removal return -EBUSY until the pipe drains) and its ring buffer alive
without taking trace_types_lock on the splice data path.
Fixes: 0c8916c34203 ("tracing: Add rmdir to remove multibuffer instances")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
---
Changes in v3:
- Newly added.
---
kernel/trace/trace.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index f153ffedb9d2..e657b01fca37 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -42,6 +42,7 @@
#include <linux/init.h>
#include <linux/panic_notifier.h>
#include <linux/poll.h>
+#include <linux/file.h>
#include <linux/nmi.h>
#include <linux/fs.h>
#include <linux/trace.h>
@@ -7228,6 +7229,7 @@ int tracing_buffers_release(struct inode *inode, struct file *file)
}
struct buffer_ref {
+ struct file *file;
struct trace_buffer *buffer;
struct buffer_data_read_page *rpage;
int cpu;
@@ -7239,6 +7241,7 @@ static void buffer_ref_release(struct buffer_ref *ref)
if (!refcount_dec_and_test(&ref->refcount))
return;
ring_buffer_free_read_page(ref->buffer, ref->cpu, ref->rpage);
+ fput(ref->file);
kfree(ref);
}
@@ -7357,6 +7360,7 @@ ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos,
break;
}
+ ref->file = get_file(file);
page = virt_to_page(ring_buffer_read_page_data(ref->rpage));
spd.pages[i] = page;