Skip to content

Commit 5b83bcd

Browse files
committed
Merge tag 'trace-ringbuffer-v6.13-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull ring-buffer fixes from Steven Rostedt: - Fix possible overflow of mmapped ring buffer with bad offset If the mmap() to the ring buffer passes in a start address that is passed the end of the mmapped file, it is not caught and a slab-out-of-bounds is triggered. Add a check to make sure the start address is within the bounds - Do not use TP_printk() to boot mapped ring buffers As a boot mapped ring buffer's data may have pointers that map to the previous boot's memory map, it is unsafe to allow the TP_printk() to be used to read the boot mapped buffer's events. If a TP_printk() points to a static string from within the kernel it will not match the current kernel mapping if KASLR is active, and it can fault. Have it simply print out the raw fields. * tag 'trace-ringbuffer-v6.13-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: trace/ring-buffer: Do not use TP_printk() formatting for boot mapped buffers ring-buffer: Fix overflow in __rb_map_vma
2 parents 8faabc0 + 8cd6340 commit 5b83bcd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

kernel/trace/ring_buffer.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7019,7 +7019,11 @@ static int __rb_map_vma(struct ring_buffer_per_cpu *cpu_buffer,
70197019
lockdep_assert_held(&cpu_buffer->mapping_lock);
70207020

70217021
nr_subbufs = cpu_buffer->nr_pages + 1; /* + reader-subbuf */
7022-
nr_pages = ((nr_subbufs + 1) << subbuf_order) - pgoff; /* + meta-page */
7022+
nr_pages = ((nr_subbufs + 1) << subbuf_order); /* + meta-page */
7023+
if (nr_pages <= pgoff)
7024+
return -EINVAL;
7025+
7026+
nr_pages -= pgoff;
70237027

70247028
nr_vma_pages = vma_pages(vma);
70257029
if (!nr_vma_pages || nr_vma_pages > nr_pages)

kernel/trace/trace.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4206,6 +4206,15 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
42064206
if (event) {
42074207
if (tr->trace_flags & TRACE_ITER_FIELDS)
42084208
return print_event_fields(iter, event);
4209+
/*
4210+
* For TRACE_EVENT() events, the print_fmt is not
4211+
* safe to use if the array has delta offsets
4212+
* Force printing via the fields.
4213+
*/
4214+
if ((tr->text_delta || tr->data_delta) &&
4215+
event->type > __TRACE_LAST_TYPE)
4216+
return print_event_fields(iter, event);
4217+
42094218
return event->funcs->trace(iter, sym_flags, event);
42104219
}
42114220

0 commit comments

Comments
 (0)