Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues: - [High] Missing buffer range validation for scale buffers in elementwise operations. -- commit 316c3aea268f80d537aa6815e4f6d7b0890d7634 Author: Rob Herring (Arm) <[email protected]> accel: ethosu: Factor buffer bounds checks Move the repeated command-stream buffer range validation into a helper in preparation for validating all weight and scale streams. > diff --git a/drivers/accel/ethosu/ethosu_gem.c > b/drivers/accel/ethosu/ethosu_gem.c > index eda9f42239beb..9fce7caeeb9af 100644 > --- a/drivers/accel/ethosu/ethosu_gem.c > +++ b/drivers/accel/ethosu/ethosu_gem.c [ ... ] > @@ -303,24 +319,16 @@ static int calc_sizes(struct drm_device *ddev, [ ... ] > if (scale) { > dev_dbg(ddev->dev, "op %d: S:%d:0x%llx-0x%llx\n", > op, st->scale[0].region, st->scale[0].base, > st->scale[0].base + st->scale[0].length - 1); > - if (st->scale[0].region < 0 || st->scale[0].base == U64_MAX || > - st->scale[0].length == U32_MAX) > + if (buffer_size(info, &st->scale[0], st->scale[0].region)) > return -EINVAL; > - info->region_size[st->scale[0].region] = > - max(info->region_size[st->scale[0].region], > - st->scale[0].base + st->scale[0].length); > } [Severity: High] This isn't a bug introduced by this patch, but while calc_sizes() validates the scale buffer, does calc_sizes_elemwise() miss this validation for elementwise operations? In ethosu_gem_cmdstream_copy_and_validate(), NPU_OP_ELEMENTWISE calculates use_scale, but it never passes it to calc_sizes_elemwise(): drivers/accel/ethosu/ethosu_gem.c:ethosu_gem_cmdstream_copy_and_validate() { ... case NPU_OP_ELEMENTWISE: use_scale = ethosu_is_u65(edev) ? (st.ifm2.broadcast & 0x80) : (st.ifm2.broadcast == 8); use_ifm2 = !(use_scale || (param == 5) || (param == 6) || (param == 7) || (param == 0x24)); use_ifm = st.ifm.broadcast != 8; ret = calc_sizes_elemwise(ddev, info, cmd, &st, use_ifm, use_ifm2); if (ret) return ret; ... } Because calc_sizes_elemwise() only checks ifm, ifm2, and ofm, could a malicious command stream with an undersized scale buffer bypass validation here? This would allow an out-of-bounds memory read by the NPU when the elementwise operation uses a scale stream. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=7
