Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ring-buffer: Fix possible dereference of uninitialized pointer

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: 5f3b6e839f3c ("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>

authored by

Daniil Dulov and committed by
Steven Rostedt (Google)
f1547779 3c6e577d

+2 -1
+2 -1
kernel/trace/ring_buffer.c
··· 1919 1919 if (!meta || !meta->head_buffer) 1920 1920 return; 1921 1921 1922 + orig_head = head_page = cpu_buffer->head_page; 1923 + 1922 1924 /* Do the reader page first */ 1923 1925 ret = rb_validate_buffer(cpu_buffer->reader_page->page, cpu_buffer->cpu); 1924 1926 if (ret < 0) { ··· 1931 1929 entry_bytes += local_read(&cpu_buffer->reader_page->page->commit); 1932 1930 local_set(&cpu_buffer->reader_page->entries, ret); 1933 1931 1934 - orig_head = head_page = cpu_buffer->head_page; 1935 1932 ts = head_page->page->time_stamp; 1936 1933 1937 1934 /*