Skip to content

Commit 81bdd60

Browse files
Junhao Hewilldeacon
authored andcommitted
drivers/perf: hisi: hns3: Fix out-of-bound access when valid event group
The perf tool allows users to create event groups through following cmd [1], but the driver does not check whether the array index is out of bounds when writing data to the event_group array. If the number of events in an event_group is greater than HNS3_PMU_MAX_HW_EVENTS, the memory write overflow of event_group array occurs. Add array index check to fix the possible array out of bounds violation, and return directly when write new events are written to array bounds. There are 9 different events in an event_group. [1] perf stat -e '{pmu/event1/, ... ,pmu/event9/} Fixes: 66637ab ("drivers/perf: hisi: add driver for HNS3 PMU") Signed-off-by: Junhao He <[email protected]> Signed-off-by: Hao Chen <[email protected]> Acked-by: Jonathan Cameron <[email protected]> Reviewed-by: Jijie Shao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 77fce82 commit 81bdd60

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

drivers/perf/hisilicon/hns3_pmu.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,15 +1085,27 @@ static bool hns3_pmu_validate_event_group(struct perf_event *event)
10851085
return false;
10861086

10871087
for (num = 0; num < counters; num++) {
1088+
/*
1089+
* If we find a related event, then it's a valid group
1090+
* since we don't need to allocate a new counter for it.
1091+
*/
10881092
if (hns3_pmu_cmp_event(event_group[num], sibling))
10891093
break;
10901094
}
10911095

1096+
/*
1097+
* Otherwise it's a new event but if there's no available counter,
1098+
* fail the check since we cannot schedule all the events in
1099+
* the group simultaneously.
1100+
*/
1101+
if (num == HNS3_PMU_MAX_HW_EVENTS)
1102+
return false;
1103+
10921104
if (num == counters)
10931105
event_group[counters++] = sibling;
10941106
}
10951107

1096-
return counters <= HNS3_PMU_MAX_HW_EVENTS;
1108+
return true;
10971109
}
10981110

10991111
static u32 hns3_pmu_get_filter_condition(struct perf_event *event)

0 commit comments

Comments
 (0)