Skip to content

Commit 7093d5d

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 <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vince Weaver <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6467123 commit 7093d5d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

@@ -863,8 +864,10 @@ perf_mmap_to_page(struct ring_buffer *rb, unsigned long pgoff)
863864
return NULL;
864865

865866
/* AUX space */
866-
if (pgoff >= rb->aux_pgoff)
867-
return virt_to_page(rb->aux_pages[pgoff - rb->aux_pgoff]);
867+
if (pgoff >= rb->aux_pgoff) {
868+
int aux_pgoff = array_index_nospec(pgoff - rb->aux_pgoff, rb->aux_nr_pages);
869+
return virt_to_page(rb->aux_pages[aux_pgoff]);
870+
}
868871
}
869872

870873
return __perf_mmap_to_page(rb, pgoff);

0 commit comments

Comments
 (0)