]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ring-buffer: Prevent off-by-one array access in ring_buffer_desc_page()
authorVincent Donnefort <vdonnefort@google.com>
Fri, 10 Apr 2026 12:45:27 +0000 (13:45 +0100)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 14 Apr 2026 09:13:09 +0000 (05:13 -0400)
As pointed out by Smatch, the ring-buffer descriptor array page_va is
counted by nr_page_va, but the accessor ring_buffer_desc_page() allows
access off by one.

Currently, this does not cause problems, as the page ID always comes
from a trusted source. Nonetheless, ensure robustness and fix the
accessor. While at it, make the page_id unsigned.

Link: https://patch.msgid.link/20260410124527.3563970-1-vdonnefort@google.com
Reported-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/ring_buffer.c

index 839a6424d0edc1c9abfcb7501050cb03d263a146..cef49f8871d2ec546e8d481a655d09cd256a07c4 100644 (file)
@@ -2238,9 +2238,9 @@ static struct ring_buffer_desc *ring_buffer_desc(struct trace_buffer_desc *trace
        return NULL;
 }
 
-static void *ring_buffer_desc_page(struct ring_buffer_desc *desc, int page_id)
+static void *ring_buffer_desc_page(struct ring_buffer_desc *desc, unsigned int page_id)
 {
-       return page_id > desc->nr_page_va ? NULL : (void *)desc->page_va[page_id];
+       return page_id >= desc->nr_page_va ? NULL : (void *)desc->page_va[page_id];
 }
 
 static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,