Skip to content

Commit 51dd0ba

Browse files
ring-buffer: Make reading page consistent with the code logic
JIRA: https://issues.redhat.com/browse/RHEL-86682 commit 6e31b75 Author: Jeongjun Park <aha310510@gmail.com> Date: Sat Jan 11 01:26:12 2025 +0900 ring-buffer: Make reading page consistent with the code logic In the loop of __rb_map_vma(), the 's' variable is calculated from the same logic that nr_pages is and they both come from nr_subbufs. But the relationship is not obvious and there's a WARN_ON_ONCE() around the 's' variable to make sure it never becomes equal to nr_subbufs within the loop. If that happens, then the code is buggy and needs to be fixed. The 'page' variable is calculated from cpu_buffer->subbuf_ids[s] which is an array of 'nr_subbufs' entries. If the code becomes buggy and 's' becomes equal to or greater than 'nr_subbufs' then this will be an out of bounds hit before the WARN_ON() is triggered and the code exiting safely. Make the 'page' initialization consistent with the code logic and assign it after the out of bounds check. Link: https://lore.kernel.org/20250110162612.13983-1-aha310510@gmail.com Signed-off-by: Jeongjun Park <aha310510@gmail.com> [ sdr: rewrote change log ] Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
1 parent 5db1aad commit 51dd0ba

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/trace/ring_buffer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7059,14 +7059,16 @@ static int __rb_map_vma(struct ring_buffer_per_cpu *cpu_buffer,
70597059
}
70607060

70617061
while (p < nr_pages) {
7062-
struct page *page = virt_to_page((void *)cpu_buffer->subbuf_ids[s]);
7062+
struct page *page;
70637063
int off = 0;
70647064

70657065
if (WARN_ON_ONCE(s >= nr_subbufs)) {
70667066
err = -EINVAL;
70677067
goto out;
70687068
}
70697069

7070+
page = virt_to_page((void *)cpu_buffer->subbuf_ids[s]);
7071+
70707072
for (; off < (1 << (subbuf_order)); off++, page++) {
70717073
if (p >= nr_pages)
70727074
break;

0 commit comments

Comments
 (0)