Commit
25132363c723afc39aace8b098f547ab4a0ea759
ring-buffer: Fix the sub-buffer array base in rb_meta_subbuf_idx()
On a persistent ring buffer, rb_meta_subbuf_idx() can return an index one
sub-buffer too high. rb_setup_ids_meta_page() then fills subbuf_ids[]
shifted by one and leaves subbuf_ids[0] NULL, which __rb_map_vma()
dereferences when userspace maps trace_pipe_raw. rb_update_meta_reader()
writes two such indices into meta->buffers[], which rb_cpu_meta_valid()
would reject on the next boot, discarding the previous boot's trace.
A CPU's sub-buffer array starts after its meta header and the nr_subbufs
integers that follow, aligned up to a sub-buffer. rb_meta_subbuf_idx()
inverts that calculation but skips only the integers, not the header, so
its base is one sub-buffer low whenever the omitted header size crosses
the alignment boundary.
Invert the calculation with rb_subbufs_from_meta() rather than repeating
it. rb_range_buffer() maps an index back to an address through the same
helper, so the two directions can no longer disagree.
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20260918071507.1019251-1-donggeunyoo.kernel@gmail.com
Fixes: b14d032973d4 ("ring-buffer: Add ring_buffer_meta data")
Signed-off-by: Donggeun Yoo <donggeunyoo.kernel@gmail.com>
Reviewed-by: Vincent Donnefort <vdonnefort@google.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Donggeun Yoo <donggeunyoo.kernel@gmail.com> · 2026-09-18 07:15 UTC · committed by Steven Rostedt
1 file changed,
+1
−3
modified kernel/trace/ring_buffer.c
| @@ -3630,10 +3630,8 @@ static void rb_inc_iter(struct ring_buffer_iter *iter) | |||
| 3630 | 3630 | /* Return the index into the sub-buffers for a given sub-buffer */ | |
| 3631 | 3631 | static int rb_meta_subbuf_idx(struct ring_buffer_cpu_meta *meta, void *subbuf) | |
| 3632 | 3632 | { | |
| 3633 | - | void *subbuf_array; | |
| 3633 | + | void *subbuf_array = rb_subbufs_from_meta(meta); | |
| 3634 | 3634 | ||
| 3635 | - | subbuf_array = (void *)meta + sizeof(int) * meta->nr_subbufs; | |
| 3636 | - | subbuf_array = (void *)ALIGN((unsigned long)subbuf_array, meta->subbuf_size); | |
| 3637 | 3635 | return (subbuf - subbuf_array) / meta->subbuf_size; | |
| 3638 | 3636 | } | |
| 3639 | 3637 | ||