Skip to content

Commit

Permalink
perf/x86: Fix potential out-of-bounds access
Browse files Browse the repository at this point in the history
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 <mroos@linux.ee>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Meelis Roos <mroos@linux.ee>
  • Loading branch information
Peter Zijlstra committed Dec 17, 2019
1 parent 57e04ee commit 1e69a0e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions arch/x86/events/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1642,9 +1642,12 @@ static struct attribute_group x86_pmu_format_group __ro_after_init = {

ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, char *page)
{
struct perf_pmu_events_attr *pmu_attr = \
struct perf_pmu_events_attr *pmu_attr =
container_of(attr, struct perf_pmu_events_attr, attr);
u64 config = x86_pmu.event_map(pmu_attr->id);
u64 config = 0;

if (pmu_attr->id < x86_pmu.max_events)
config = x86_pmu.event_map(pmu_attr->id);

/* string trumps id */
if (pmu_attr->event_str)
Expand Down Expand Up @@ -1713,6 +1716,9 @@ is_visible(struct kobject *kobj, struct attribute *attr, int idx)
{
struct perf_pmu_events_attr *pmu_attr;

if (idx >= x86_pmu.max_events)
return 0;

pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr.attr);
/* str trumps id */
return pmu_attr->event_str || x86_pmu.event_map(idx) ? attr->mode : 0;
Expand Down

0 comments on commit 1e69a0e

Please sign in to comment.