[PATCH v4 07/31] accel: ethosu: Limit perfmon counters to UAPI
From: Rob Herring (Arm)
Date: Thu Oct 29 2026 - 09:53:58 EST
The perfmon creation UAPI has a fixed eight-entry counter array, but
only the hardware counter count limits ncounters. A device reporting more
than eight counters would allow out-of-bounds accesses to the request and
perfmon counter arrays.
Reject counts exceeding the UAPI array bound.
Fixes: 5a5e9c0228e6 ("accel: Add Arm Ethos-U NPU driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Rob Herring (Arm) <robh@xxxxxxxxxx>
---
v4:
- New patch
---
drivers/accel/ethosu/ethosu_perfmon.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/accel/ethosu/ethosu_perfmon.c b/drivers/accel/ethosu/ethosu_perfmon.c
index 0ae2df3ceac8..2a9b3cc1447b 100644
--- a/drivers/accel/ethosu/ethosu_perfmon.c
+++ b/drivers/accel/ethosu/ethosu_perfmon.c
@@ -165,8 +165,9 @@ int ethosu_ioctl_perfmon_create(struct drm_device *dev, void *data,
int ret;
u32 id;
- /* Number of monitored counters cannot exceed HW limits. */
- if (req->ncounters > ethosu->npu_info.pmu_counters)
+ /* Number of monitored counters cannot exceed HW or UAPI limits. */
+ if (req->ncounters > ethosu->npu_info.pmu_counters ||
+ req->ncounters > DRM_ETHOSU_MAX_PERF_EVENT_COUNTERS)
return -EINVAL;
/* Make sure all counters are valid. */
--
2.53.0