Skip to contentSkip to conversation

ring-buffer: Prevent off-by-one array access in ring_buffer_desc_page()

PATCH New Vincent Donnefort 1 participant 1 message Apr 10

Subsystems (2)
lore
Share & tools
lore

Vincent Donnefort

author maintainer
#0 lore raw

PATCH 1/1 ring-buffer: Prevent off-by-one array access in ring_buffer_desc_page()

As pointed out by Smatch, the ring-buffer descriptor array page_va is counted by nr_page_va, but the accessor ring_buffer_desc_page() allows access off by one.

Currently, this does not cause problems, as the page ID always comes from a trusted source. Nonetheless, ensure robustness and fix the accessor. While at it, make the page_id unsigned.

---

Currently based on kvmarm/next.

kernel/trace/ring_buffer.c +2 -2
index 96e0d80d492b..2c77020e7aac 100644
@@ -2238,9 +2238,9 @@ static struct ring_buffer_desc *ring_buffer_desc(struct trace_buffer_desc *trace
 	return NULL;
 }
 
-static void *ring_buffer_desc_page(struct ring_buffer_desc *desc, int page_id)
+static void *ring_buffer_desc_page(struct ring_buffer_desc *desc, unsigned int page_id)
 {
-	return page_id > desc->nr_page_va ? NULL : (void *)desc->page_va[page_id];
+	return page_id >= desc->nr_page_va ? NULL : (void *)desc->page_va[page_id];
 }
 
 static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,

base-commit: 94b4ae79ebb42a8a6f2124b4d4b033b15a98e4f9

Signature · 1 line
2.53.0.1213.gd9a14994de-goog