Skip to content

Commit a7b1374

Browse files
rostedtIngo Molnar
authored andcommitted
ring_buffer: add paranoid check for buffer page
If for some strange reason the buffer_page gets bigger, or the page struct gets smaller, I want to know this ASAP. The best way is to not let the kernel compile. This patch adds code to test the size of the struct buffer_page against the page struct and will cause compile issues if the buffer_page ever gets bigger than the page struct. Signed-off-by: Steven Rostedt <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 7a8e76a commit a7b1374

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

kernel/trace/ring_buffer.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ static void rb_free_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer)
289289
kfree(cpu_buffer);
290290
}
291291

292+
/*
293+
* Causes compile errors if the struct buffer_page gets bigger
294+
* than the struct page.
295+
*/
296+
extern int ring_buffer_page_too_big(void);
297+
292298
/**
293299
* ring_buffer_alloc - allocate a new ring_buffer
294300
* @size: the size in bytes that is needed.
@@ -305,6 +311,11 @@ struct ring_buffer *ring_buffer_alloc(unsigned long size, unsigned flags)
305311
int bsize;
306312
int cpu;
307313

314+
/* Paranoid! Optimizes out when all is well */
315+
if (sizeof(struct buffer_page) > sizeof(struct page))
316+
ring_buffer_page_too_big();
317+
318+
308319
/* keep it in its own cache line */
309320
buffer = kzalloc(ALIGN(sizeof(*buffer), cache_line_size()),
310321
GFP_KERNEL);

0 commit comments

Comments
 (0)