Skip to content

Commit 49145bc

Browse files
sumanthkorikkarVasily Gorbik
authored andcommitted
s390/perf_cpum_cf: Add missing array_index_nospec() to __hw_perf_event_init()
ev variable is userspace controlled via event->attr.config and used as an array index after bounds checking, but without speculation barriers. Add the missing array_index_nospec() call to prevent speculative execution. Cc: stable@vger.kernel.org Fixes: 212188a ("[S390] perf: add support for s390x CPU counters") Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com> Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com> Acked-by: Thomas Richter <tmricht@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent 4bb06b6 commit 49145bc

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

arch/s390/kernel/perf_cpum_cf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/init.h>
1616
#include <linux/miscdevice.h>
1717
#include <linux/perf_event.h>
18+
#include <linux/nospec.h>
1819

1920
#include <asm/cpu_mf.h>
2021
#include <asm/hwctrset.h>
@@ -768,6 +769,7 @@ static int __hw_perf_event_init(struct perf_event *event, unsigned int type)
768769
if (!is_userspace_event(ev)) {
769770
if (ev >= ARRAY_SIZE(cpumf_generic_events_user))
770771
return -EOPNOTSUPP;
772+
ev = array_index_nospec(ev, ARRAY_SIZE(cpumf_generic_events_user));
771773
ev = cpumf_generic_events_user[ev];
772774
}
773775
} else if (!attr->exclude_kernel && attr->exclude_user) {
@@ -778,6 +780,7 @@ static int __hw_perf_event_init(struct perf_event *event, unsigned int type)
778780
if (!is_userspace_event(ev)) {
779781
if (ev >= ARRAY_SIZE(cpumf_generic_events_basic))
780782
return -EOPNOTSUPP;
783+
ev = array_index_nospec(ev, ARRAY_SIZE(cpumf_generic_events_basic));
781784
ev = cpumf_generic_events_basic[ev];
782785
}
783786
}

0 commit comments

Comments
 (0)