Skip to content

Commit ef9ee4a

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
perf/x86: Fix possible Spectre-v1 indexing for hw_perf_event cache_*
> 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 <[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]>
1 parent 4411ec1 commit ef9ee4a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

arch/x86/events/core.c

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

305305
config = attr->config;
306306

307-
cache_type = (config >> 0) & 0xff;
307+
cache_type = (config >> 0) & 0xff;
308308
if (cache_type >= PERF_COUNT_HW_CACHE_MAX)
309309
return -EINVAL;
310+
cache_type = array_index_nospec(cache_type, PERF_COUNT_HW_CACHE_MAX);
310311

311312
cache_op = (config >> 8) & 0xff;
312313
if (cache_op >= PERF_COUNT_HW_CACHE_OP_MAX)
313314
return -EINVAL;
315+
cache_op = array_index_nospec(cache_op, PERF_COUNT_HW_CACHE_OP_MAX);
314316

315317
cache_result = (config >> 16) & 0xff;
316318
if (cache_result >= PERF_COUNT_HW_CACHE_RESULT_MAX)
317319
return -EINVAL;
320+
cache_result = array_index_nospec(cache_result, PERF_COUNT_HW_CACHE_RESULT_MAX);
318321

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

0 commit comments

Comments
 (0)