]> www.infradead.org Git - nvme.git/commit
ring-buffer: Make reading page consistent with the code logic
authorJeongjun Park <aha310510@gmail.com>
Fri, 10 Jan 2025 16:26:12 +0000 (01:26 +0900)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Mon, 13 Jan 2025 21:05:43 +0000 (16:05 -0500)
commit6e31b759b076eebb4184117234f0c4eb9e4bc460
tree119350c2e312ed1b0c42974390d61a02af9db3de
parent0568c6ebf072d913c437dbb5271f889a5e329007
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>
kernel/trace/ring_buffer.c