Skip to content

Commit d0f2d6e

Browse files
committed
ring-buffer: Add magic and struct size to boot up meta data
Add a magic number as well as save the struct size of the ring_buffer_meta structure in the meta data to also use as validation. Updating the magic number could be used to force a invalidation between kernel versions, and saving the structure size is also a good method to make sure the content is what is expected. Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Vincent Donnefort <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent bca704f commit d0f2d6e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

kernel/trace/ring_buffer.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444

4545
static void update_pages_handler(struct work_struct *work);
4646

47+
#define RING_BUFFER_META_MAGIC 0xBADFEED
48+
4749
struct ring_buffer_meta {
50+
int magic;
51+
int struct_size;
4852
unsigned long text_addr;
4953
unsigned long data_addr;
5054
unsigned long first_buffer;
@@ -1627,6 +1631,13 @@ static bool rb_meta_valid(struct ring_buffer_meta *meta, int cpu,
16271631
unsigned long buffers_end;
16281632
int i;
16291633

1634+
/* Check the meta magic and meta struct size */
1635+
if (meta->magic != RING_BUFFER_META_MAGIC ||
1636+
meta->struct_size != sizeof(*meta)) {
1637+
pr_info("Ring buffer boot meta[%d] mismatch of magic or struct size\n", cpu);
1638+
return false;
1639+
}
1640+
16301641
/* The subbuffer's size and number of subbuffers must match */
16311642
if (meta->subbuf_size != subbuf_size ||
16321643
meta->nr_subbufs != nr_pages + 1) {
@@ -1858,6 +1869,9 @@ static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages)
18581869

18591870
memset(meta, 0, next_meta - (void *)meta);
18601871

1872+
meta->magic = RING_BUFFER_META_MAGIC;
1873+
meta->struct_size = sizeof(*meta);
1874+
18611875
meta->nr_subbufs = nr_pages + 1;
18621876
meta->subbuf_size = PAGE_SIZE;
18631877

0 commit comments

Comments
 (0)