Skip to content

Commit e78fb4e

Browse files
committed
ring-buffer: Do not let subbuf be bigger than write mask
The data on the subbuffer is measured by a write variable that also contains status flags. The counter is just 20 bits in length. If the subbuffer is bigger than then counter, it will fail. Make sure that the subbuffer can not be set to greater than the counter that keeps track of the data on the subbuffer. Link: https://lore.kernel.org/linux-trace-kernel/20240220095112.77e9cb81@gandalf.local.home Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Fixes: 2808e31 ("ring-buffer: Add interface for configuring trace sub buffer size") Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent b401b62 commit e78fb4e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

kernel/trace/ring_buffer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5877,6 +5877,10 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
58775877
if (psize <= BUF_PAGE_HDR_SIZE)
58785878
return -EINVAL;
58795879

5880+
/* Size of a subbuf cannot be greater than the write counter */
5881+
if (psize > RB_WRITE_MASK + 1)
5882+
return -EINVAL;
5883+
58805884
old_order = buffer->subbuf_order;
58815885
old_size = buffer->subbuf_size;
58825886

0 commit comments

Comments
 (0)