Skip to contentSkip to conversation

ring-buffer: Do not let subbuf be bigger than write mask

PATCH New Steven Rostedt 1 participant 1 message Feb 20, 2024

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH 1/1 ring-buffer: Do not let subbuf be bigger than write mask

From: "Steven Rostedt (Google)" <[email protected]>

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.

Fixes 2808e31ec12e5 ("ring-buffer: Add interface for configuring trace sub buffer size")
---
 kernel/trace/ring_buffer.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/trace/ring_buffer.c +4 -0
index aa54266f5e1f..3852f3b001cc 100644
@@ -5878,6 +5878,10 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
 	if (psize <= BUF_PAGE_HDR_SIZE)
 		return -EINVAL;
 
+	/* Size of a subbuf cannot be greater than the write counter */
+	if (psize > RB_WRITE_MASK + 1)
+		return -EINVAL;
+
 	old_order = buffer->subbuf_order;
 	old_size = buffer->subbuf_size;
 
Signature · 1 line
2.43.0