Skip to content

Commit 662218f

Browse files
Peter Zijlstragregkh
authored andcommitted
perf/x86: Fix possible Spectre-v1 indexing for hw_perf_event cache_*
commit ef9ee4a upstream. > arch/x86/events/core.c:319 set_ext_hw_attr() warn: potential spectre issue 'hw_cache_event_ids[cache_type]' (local cap) > arch/x86/events/core.c:319 set_ext_hw_attr() warn: potential spectre issue 'hw_cache_event_ids' (local cap) > arch/x86/events/core.c:328 set_ext_hw_attr() warn: potential spectre issue 'hw_cache_extra_regs[cache_type]' (local cap) > arch/x86/events/core.c:328 set_ext_hw_attr() warn: potential spectre issue 'hw_cache_extra_regs' (local cap) Userspace controls @config which contains 3 (byte) fields used for a 3 dimensional array deref. 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 fba70eb commit 662218f

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

arch/x86/events/core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,17 +303,20 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event *event)
303303

304304
config = attr->config;
305305

306-
cache_type = (config >> 0) & 0xff;
306+
cache_type = (config >> 0) & 0xff;
307307
if (cache_type >= PERF_COUNT_HW_CACHE_MAX)
308308
return -EINVAL;
309+
cache_type = array_index_nospec(cache_type, PERF_COUNT_HW_CACHE_MAX);
309310

310311
cache_op = (config >> 8) & 0xff;
311312
if (cache_op >= PERF_COUNT_HW_CACHE_OP_MAX)
312313
return -EINVAL;
314+
cache_op = array_index_nospec(cache_op, PERF_COUNT_HW_CACHE_OP_MAX);
313315

314316
cache_result = (config >> 16) & 0xff;
315317
if (cache_result >= PERF_COUNT_HW_CACHE_RESULT_MAX)
316318
return -EINVAL;
319+
cache_result = array_index_nospec(cache_result, PERF_COUNT_HW_CACHE_RESULT_MAX);
317320

318321
val = hw_cache_event_ids[cache_type][cache_op][cache_result];
319322

0 commit comments

Comments
 (0)