Skip to content

Commit f017197

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/intel/uncore: Validate MMIO address before accessing
An oops will be triggered, if perf tries to access an invalid address which exceeds the mapped area. Check the address before the actual access to MMIO sapce of an uncore unit. Suggested-by: David Laight <[email protected]> Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 1b94d31 commit f017197

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

arch/x86/events/intel/uncore.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ u64 uncore_mmio_read_counter(struct intel_uncore_box *box,
132132
if (!box->io_addr)
133133
return 0;
134134

135+
if (!uncore_mmio_is_valid_offset(box, event->hw.event_base))
136+
return 0;
137+
135138
return readq(box->io_addr + event->hw.event_base);
136139
}
137140

arch/x86/events/intel/uncore.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ static inline bool uncore_pmc_freerunning(int idx)
197197
return idx == UNCORE_PMC_IDX_FREERUNNING;
198198
}
199199

200+
static inline bool uncore_mmio_is_valid_offset(struct intel_uncore_box *box,
201+
unsigned long offset)
202+
{
203+
if (offset < box->pmu->type->mmio_map_size)
204+
return true;
205+
206+
pr_warn_once("perf uncore: Invalid offset 0x%lx exceeds mapped area of %s.\n",
207+
offset, box->pmu->type->name);
208+
209+
return false;
210+
}
211+
200212
static inline
201213
unsigned int uncore_mmio_box_ctl(struct intel_uncore_box *box)
202214
{

arch/x86/events/intel/uncore_snbep.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4483,6 +4483,9 @@ static void snr_uncore_mmio_enable_event(struct intel_uncore_box *box,
44834483
if (!box->io_addr)
44844484
return;
44854485

4486+
if (!uncore_mmio_is_valid_offset(box, hwc->config_base))
4487+
return;
4488+
44864489
writel(hwc->config | SNBEP_PMON_CTL_EN,
44874490
box->io_addr + hwc->config_base);
44884491
}
@@ -4495,6 +4498,9 @@ static void snr_uncore_mmio_disable_event(struct intel_uncore_box *box,
44954498
if (!box->io_addr)
44964499
return;
44974500

4501+
if (!uncore_mmio_is_valid_offset(box, hwc->config_base))
4502+
return;
4503+
44984504
writel(hwc->config, box->io_addr + hwc->config_base);
44994505
}
45004506

0 commit comments

Comments
 (0)