Re: [PATCH V2] ring-buffer: fix overflow in __rb_map_vma
From: Steven Rostedt <rostedt@goodmis.org>
Date: 2024-12-18 13:17:24
Also in:
lkml
From: Steven Rostedt <rostedt@goodmis.org>
Date: 2024-12-18 13:17:24
Also in:
lkml
On Wed, 18 Dec 2024 19:42:22 +0800 Edward Adam Davis [off-list ref] wrote:
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 7e257e855dd1..20f0e01b7a50 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c@@ -7019,7 +7019,11 @@ static int __rb_map_vma(struct ring_buffer_per_cpu *cpu_buffer, lockdep_assert_held(&cpu_buffer->mapping_lock); nr_subbufs = cpu_buffer->nr_pages + 1; /* + reader-subbuf */ - nr_pages = ((nr_subbufs + 1) << subbuf_order) - pgoff; /* + meta-page */ + nr_pages = ((nr_subbufs + 1) << subbuf_order); /* + meta-page */ + if (nr_pages < pgoff)
That probably should be <= as if it was equal...
+ return -EINVAL; + + nr_pages -= pgoff;
nr_pages would be zero and
nr_vma_pages = vma_pages(vma); if (!nr_vma_pages || nr_vma_pages > nr_pages)
this would return true, which the next line is: return -EINVAL; Why not catch it before going through all that? -- Steve
--