Skip to content

Commit 1e69a0e

Browse files
author
Peter Zijlstra
committed
perf/x86: Fix potential out-of-bounds access
UBSAN reported out-of-bound accesses for x86_pmu.event_map(), it's arguments should be < x86_pmu.max_events. Make sure all users observe this constraint. Reported-by: Meelis Roos <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Tested-by: Meelis Roos <[email protected]>
1 parent 57e04ee commit 1e69a0e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arch/x86/events/core.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,9 +1642,12 @@ static struct attribute_group x86_pmu_format_group __ro_after_init = {
16421642

16431643
ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, char *page)
16441644
{
1645-
struct perf_pmu_events_attr *pmu_attr = \
1645+
struct perf_pmu_events_attr *pmu_attr =
16461646
container_of(attr, struct perf_pmu_events_attr, attr);
1647-
u64 config = x86_pmu.event_map(pmu_attr->id);
1647+
u64 config = 0;
1648+
1649+
if (pmu_attr->id < x86_pmu.max_events)
1650+
config = x86_pmu.event_map(pmu_attr->id);
16481651

16491652
/* string trumps id */
16501653
if (pmu_attr->event_str)
@@ -1713,6 +1716,9 @@ is_visible(struct kobject *kobj, struct attribute *attr, int idx)
17131716
{
17141717
struct perf_pmu_events_attr *pmu_attr;
17151718

1719+
if (idx >= x86_pmu.max_events)
1720+
return 0;
1721+
17161722
pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr.attr);
17171723
/* str trumps id */
17181724
return pmu_attr->event_str || x86_pmu.event_map(idx) ? attr->mode : 0;

0 commit comments

Comments
 (0)