Skip to content

Commit 54f7be5

Browse files
Steven Rostedtrostedt
authored andcommitted
ring-buffer: Fix NULL pointer if rb_set_head_page() fails
The function rb_set_head_page() searches the list of ring buffer pages for a the page that has the HEAD page flag set. If it does not find it, it will do a WARN_ON(), disable the ring buffer and return NULL, as this should never happen. But if this bug happens to happen, not all callers of this function can handle a NULL pointer being returned from it. That needs to be fixed. Cc: [email protected] # 3.0+ Signed-off-by: Steven Rostedt <[email protected]>
1 parent 70f77b3 commit 54f7be5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

kernel/trace/ring_buffer.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,8 @@ rb_insert_pages(struct ring_buffer_per_cpu *cpu_buffer)
13961396
struct list_head *head_page_with_bit;
13971397

13981398
head_page = &rb_set_head_page(cpu_buffer)->list;
1399+
if (!head_page)
1400+
break;
13991401
prev_page = head_page->prev;
14001402

14011403
first_page = pages->next;
@@ -2934,7 +2936,7 @@ unsigned long ring_buffer_oldest_event_ts(struct ring_buffer *buffer, int cpu)
29342936
unsigned long flags;
29352937
struct ring_buffer_per_cpu *cpu_buffer;
29362938
struct buffer_page *bpage;
2937-
unsigned long ret;
2939+
unsigned long ret = 0;
29382940

29392941
if (!cpumask_test_cpu(cpu, buffer->cpumask))
29402942
return 0;
@@ -2949,7 +2951,8 @@ unsigned long ring_buffer_oldest_event_ts(struct ring_buffer *buffer, int cpu)
29492951
bpage = cpu_buffer->reader_page;
29502952
else
29512953
bpage = rb_set_head_page(cpu_buffer);
2952-
ret = bpage->page->time_stamp;
2954+
if (bpage)
2955+
ret = bpage->page->time_stamp;
29532956
raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
29542957

29552958
return ret;
@@ -3260,6 +3263,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
32603263
* Splice the empty reader page into the list around the head.
32613264
*/
32623265
reader = rb_set_head_page(cpu_buffer);
3266+
if (!reader)
3267+
goto out;
32633268
cpu_buffer->reader_page->list.next = rb_list_head(reader->list.next);
32643269
cpu_buffer->reader_page->list.prev = reader->list.prev;
32653270

0 commit comments

Comments
 (0)