ring_buffer_alloc_read_page() is racy with ring_buffer_subbuf_order_set,
it can allocate a reader page with an outdated order. This isn't a big
issue, the user can still re-allocate a new reader page and try again.

However, what is more problematic is if the value of subbuf_order
changes in the middle of ring_buffer_alloc_read_page(). In that case,
bpage->order might not match the actual allocated memory.

Use bpage->order for the allocation to prevent this race.

Fixes: bce761d75745 ("ring-buffer: Read and write to ring buffers with custom 
sub buffer size")
Reported-by: Sashiko <[email protected]>
Signed-off-by: Vincent Donnefort <[email protected]>

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 97449423d3a6..94552a433228 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -7018,7 +7018,7 @@ ring_buffer_alloc_read_page(struct trace_buffer *buffer, 
int cpu)
        if (bpage->data) {
                rb_init_data_page(bpage->data);
        } else {
-               bpage->data = alloc_cpu_data(cpu, 
cpu_buffer->buffer->subbuf_order);
+               bpage->data = alloc_cpu_data(cpu, bpage->order);
                if (!bpage->data) {
                        kfree(bpage);
                        return ERR_PTR(-ENOMEM);
-- 
2.55.0.691.gc56d675ccc-goog


Reply via email to