Skip to content

Commit 625ed52

Browse files
Zheng Yejianrostedt
authored andcommitted
ring-buffer: Clearly check null ptr returned by rb_set_head_page()
In error case, 'buffer_page' returned by rb_set_head_page() is NULL, currently check '&buffer_page->list' is equivalent to check 'buffer_page' due to 'list' is the first member of 'buffer_page', but suppose it is not some time, 'head_page' would be wild memory while check would be bypassed. Link: https://lore.kernel.org/linux-trace-kernel/20230414071729.57312-1-zhengyejian1@huawei.com Cc: <mhiramat@kernel.org> Signed-off-by: Zheng Yejian <zhengyejian1@huawei.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 88fe1ec commit 625ed52

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

kernel/trace/ring_buffer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,10 +2054,11 @@ rb_insert_pages(struct ring_buffer_per_cpu *cpu_buffer)
20542054
struct list_head *head_page, *prev_page, *r;
20552055
struct list_head *last_page, *first_page;
20562056
struct list_head *head_page_with_bit;
2057+
struct buffer_page *hpage = rb_set_head_page(cpu_buffer);
20572058

2058-
head_page = &rb_set_head_page(cpu_buffer)->list;
2059-
if (!head_page)
2059+
if (!hpage)
20602060
break;
2061+
head_page = &hpage->list;
20612062
prev_page = head_page->prev;
20622063

20632064
first_page = pages->next;

0 commit comments

Comments
 (0)