Skip to content

Commit c64ca00

Browse files
Peter Zijlstragregkh
authored andcommitted
perf/core: Fix possible Spectre-v1 indexing for ->aux_pages[]
commit 4411ec1 upstream. > kernel/events/ring_buffer.c:871 perf_mmap_to_page() warn: potential spectre issue 'rb->aux_pages' Userspace controls @pgoff through the fault address. Sanitize the array index before doing the array dereference. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: <stable@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vince Weaver <vincent.weaver@maine.edu> Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5edbd2d commit c64ca00

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

kernel/events/ring_buffer.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/slab.h>
1515
#include <linux/circ_buf.h>
1616
#include <linux/poll.h>
17+
#include <linux/nospec.h>
1718

1819
#include "internal.h"
1920

@@ -844,8 +845,10 @@ perf_mmap_to_page(struct ring_buffer *rb, unsigned long pgoff)
844845
return NULL;
845846

846847
/* AUX space */
847-
if (pgoff >= rb->aux_pgoff)
848-
return virt_to_page(rb->aux_pages[pgoff - rb->aux_pgoff]);
848+
if (pgoff >= rb->aux_pgoff) {
849+
int aux_pgoff = array_index_nospec(pgoff - rb->aux_pgoff, rb->aux_nr_pages);
850+
return virt_to_page(rb->aux_pages[aux_pgoff]);
851+
}
849852
}
850853

851854
return __perf_mmap_to_page(rb, pgoff);

0 commit comments

Comments
 (0)