]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ring-buffer: Fix subbuf_ids memory leak in rb_allocate_cpu_buffer() error path
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Fri, 31 Jul 2026 14:16:46 +0000 (23:16 +0900)
committerSteven Rostedt <rostedt@goodmis.org>
Fri, 31 Jul 2026 23:48:27 +0000 (19:48 -0400)
In rb_allocate_cpu_buffer(), cpu_buffer->subbuf_ids is allocated using
kcalloc() when buffer->remote is non-NULL. If a subsequent page allocation
fails (e.g., ring_buffer_desc_page() returns NULL or rb_allocate_pages()
fails), execution jumps to fail_free_reader.

While __free(kfree) automatically frees the outer cpu_buffer structure
at scope exit, kfree(cpu_buffer) does not recursively free nested heap
pointers such as cpu_buffer->subbuf_ids, resulting in a memory leak.

Fix this by explicitly freeing cpu_buffer->subbuf_ids in the
fail_free_reader error unwinding path when cpu_buffer->remote is set.

Link: https://patch.msgid.link/178550740672.380917.6067449683620196150.stgit@devnote2
Fixes: 2e67fabd8b77 ("ring-buffer: Introduce ring-buffer remotes")
Assisted-by: Antigravity:gemini-3.6-flash
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Reviewed-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/ring_buffer.c

index 78d3875a47a57fbd8975db8dbab1614e725381d0..8e2485bb3aa87ee3b83999350492092cb91a5e78 100644 (file)
@@ -2599,6 +2599,7 @@ rb_allocate_cpu_buffer(struct trace_buffer *buffer, long nr_pages, int cpu)
        return_ptr(cpu_buffer);
 
  fail_free_reader:
+       kfree(cpu_buffer->subbuf_ids);
        free_buffer_page(cpu_buffer->reader_page);
 
        return NULL;