Skip to content

Commit 021f1b7

Browse files
committed
accel: ethosu: Handle possible underflow in IFM size calculations
If the command stream has larger padding sizes than the IFM and OFM diminsions, then the calculations will underflow to a negative value. The result is a very large region bounds which is caught on submit, but it's better to catch it earlier. Current mesa ethosu driver has a signedness bug which resulted in padding of 127 (the max) and triggers this issue. Reviewed-and-Tested-by: Anders Roxell <anders.roxell@linaro.org> Link: https://patch.msgid.link/20260218-ethos-fixes-v1-3-be3fa3ea9a30@kernel.org Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
1 parent 838ae99 commit 021f1b7

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

drivers/accel/ethosu/ethosu_gem.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,14 @@ static int calc_sizes(struct drm_device *ddev,
245245
((st->ifm.stride_kernel >> 1) & 0x1) + 1;
246246
u32 stride_x = ((st->ifm.stride_kernel >> 5) & 0x2) +
247247
(st->ifm.stride_kernel & 0x1) + 1;
248-
u32 ifm_height = st->ofm.height[2] * stride_y +
248+
s32 ifm_height = st->ofm.height[2] * stride_y +
249249
st->ifm.height[2] - (st->ifm.pad_top + st->ifm.pad_bottom);
250-
u32 ifm_width = st->ofm.width * stride_x +
250+
s32 ifm_width = st->ofm.width * stride_x +
251251
st->ifm.width - (st->ifm.pad_left + st->ifm.pad_right);
252252

253+
if (ifm_height < 0 || ifm_width < 0)
254+
return -EINVAL;
255+
253256
len = feat_matrix_length(info, &st->ifm, ifm_width,
254257
ifm_height, st->ifm.depth);
255258
dev_dbg(ddev->dev, "op %d: IFM:%d:0x%llx-0x%llx\n",

0 commit comments

Comments
 (0)