Skip to content
/ linux Public

Commit bc77986

Browse files
Daniil DulovSasha Levin
authored andcommitted
ring-buffer: Fix possible dereference of uninitialized pointer
[ Upstream commit f154777 ] There is a pointer head_page in rb_meta_validate_events() which is not initialized at the beginning of a function. This pointer can be dereferenced if there is a failure during reader page validation. In this case the control is passed to "invalid" label where the pointer is dereferenced in a loop. To fix the issue initialize orig_head and head_page before calling rb_validate_buffer. Found by Linux Verification Center (linuxtesting.org) with SVACE. Cc: stable@vger.kernel.org Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Link: https://patch.msgid.link/20260213100130.2013839-1-d.dulov@aladdin.ru Closes: https://lore.kernel.org/r/202406130130.JtTGRf7W-lkp@intel.com/ Fixes: 5f3b6e8 ("ring-buffer: Validate boot range memory events") Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c692db8 commit bc77986

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/trace/ring_buffer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,8 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)
18831883
if (!meta || !meta->head_buffer)
18841884
return;
18851885

1886+
orig_head = head_page = cpu_buffer->head_page;
1887+
18861888
/* Do the reader page first */
18871889
ret = rb_validate_buffer(cpu_buffer->reader_page->page, cpu_buffer->cpu);
18881890
if (ret < 0) {
@@ -1893,7 +1895,6 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)
18931895
entry_bytes += local_read(&cpu_buffer->reader_page->page->commit);
18941896
local_set(&cpu_buffer->reader_page->entries, ret);
18951897

1896-
orig_head = head_page = cpu_buffer->head_page;
18971898
ts = head_page->page->time_stamp;
18981899

18991900
/*

0 commit comments

Comments
 (0)