* [PATCH] accel/ethosu: include secondary weight/scale extents in region_size[] accounting
@ 2026-06-05 19:33 Muhammad Bilal
2026-06-05 19:50 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Muhammad Bilal @ 2026-06-05 19:33 UTC (permalink / raw)
To: robh
Cc: tomeu, ogabbay, tzimmermann, Frank.Li, dri-devel, linux-kernel,
stable, Muhammad Bilal
calc_sizes() updates region_size[] with the extent of weight[0] and
scale[0] within their hardware regions, but omits weight[1..3] and
scale[1]. Since no NPU_SET_WEIGHT1_REGION, NPU_SET_WEIGHT2_REGION,
NPU_SET_WEIGHT3_REGION, or NPU_SET_SCALE1_REGION commands exist in the
command set, secondary buffers implicitly share the same hardware region
as weight[0] and scale[0] respectively.
The omission means region_size[] reflects only the primary buffer extent.
If a secondary weight or scale buffer extends beyond the primary one,
region_size[] may underestimate the required GEM buffer size.
Fix by extending the region_size[] update in calc_sizes() to cover
weight[1..3] and scale[1], skipping entries that still hold the
U64_MAX/U32_MAX sentinel values written by cmd_state_init().
Fixes: 5a5e9c0228e6 ("accel: Add Arm Ethos-U NPU driver")
Cc: stable@vger.kernel.org
Suggested-by: Rob Herring <robh@kernel.org>
Signed-off-by: Muhammad Bilal <meatuni001@gmail.com>
---
drivers/accel/ethosu/ethosu_gem.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/accel/ethosu/ethosu_gem.c b/drivers/accel/ethosu/ethosu_gem.c
index 7994e7073..152733b6a 100644
--- a/drivers/accel/ethosu/ethosu_gem.c
+++ b/drivers/accel/ethosu/ethosu_gem.c
@@ -271,6 +271,8 @@ static int calc_sizes(struct drm_device *ddev,
}
if (weight) {
+ int i;
+
dev_dbg(ddev->dev, "op %d: W:%d:0x%llx-0x%llx\n",
op, st->weight[0].region, st->weight[0].base,
st->weight[0].base + st->weight[0].length - 1);
@@ -280,6 +282,14 @@ static int calc_sizes(struct drm_device *ddev,
info->region_size[st->weight[0].region] =
max(info->region_size[st->weight[0].region],
st->weight[0].base + st->weight[0].length);
+ for (i = 1; i < ARRAY_SIZE(st->weight); i++) {
+ if (st->weight[i].base == U64_MAX ||
+ st->weight[i].length == U32_MAX)
+ continue;
+ info->region_size[st->weight[0].region] =
+ max(info->region_size[st->weight[0].region],
+ st->weight[i].base + st->weight[i].length);
+ }
}
if (scale) {
@@ -292,6 +302,11 @@ static int calc_sizes(struct drm_device *ddev,
info->region_size[st->scale[0].region] =
max(info->region_size[st->scale[0].region],
st->scale[0].base + st->scale[0].length);
+ if (st->scale[1].base != U64_MAX &&
+ st->scale[1].length != U32_MAX)
+ info->region_size[st->scale[0].region] =
+ max(info->region_size[st->scale[0].region],
+ st->scale[1].base + st->scale[1].length);
}
len = feat_matrix_length(info, &st->ofm, st->ofm.width,
--
2.54.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] accel/ethosu: include secondary weight/scale extents in region_size[] accounting
2026-06-05 19:33 [PATCH] accel/ethosu: include secondary weight/scale extents in region_size[] accounting Muhammad Bilal
@ 2026-06-05 19:50 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-06-05 19:50 UTC (permalink / raw)
To: Muhammad Bilal; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Userspace can bypass GEM bounds validation for secondary weight and scale buffers by explicitly setting their length to U32_MAX or omitting their base address initialization.
- [High] The feature matrix bounds calculation in `feat_matrix_length()` only evaluates the base address of the final active tile, ignoring earlier tiles and allowing OOB DMA.
- [High] DMA length validation fails to check the lower bound for operations with negative strides, enabling OOB accesses before the GEM object's base IOVA.
--
commit 7486f97fafb727f5b9b006f0446971da1e03b741
Author: Muhammad Bilal <meatuni001@gmail.com>
Subject: accel/ethosu: include secondary weight/scale extents in region_size[] accounting
This commit updates calc_sizes() to account for the extents of secondary
weight and scale buffers when calculating required GEM buffer sizes.
Previously, these secondary buffers were omitted from the region size
calculations, which could underestimate the required size.
> diff --git a/drivers/accel/ethosu/ethosu_gem.c b/drivers/accel/ethosu/ethosu_gem.c
> --- a/drivers/accel/ethosu/ethosu_gem.c
> +++ b/drivers/accel/ethosu/ethosu_gem.c
> @@ -285,6 +285,8 @@ static int calc_sizes(struct drm_device *ddev,
> }
>
> if (weight) {
> + int i;
> +
> dev_dbg(ddev->dev, "op %d: W:%d:0x%llx-0x%llx\n",
> op, st->weight[0].region, st->weight[0].base,
> st->weight[0].base + st->weight[0].length - 1);
> @@ -294,6 +296,14 @@ static int calc_sizes(struct drm_device *ddev,
> info->region_size[st->weight[0].region] =
> max(info->region_size[st->weight[0].region],
> st->weight[0].base + st->weight[0].length);
> + for (i = 1; i < ARRAY_SIZE(st->weight); i++) {
> + if (st->weight[i].base == U64_MAX ||
> + st->weight[i].length == U32_MAX)
> + continue;
[Severity: High]
This isn't a bug introduced by this patch, but does this sentinel check in
calc_sizes() allow userspace to bypass validation for secondary weight
buffers?
If malicious userspace explicitly sends a command with a length of U32_MAX
and an out-of-bounds base address, this continue statement skips updating
the region size. Could the NPU hardware still execute the command using
the out-of-bounds base address, resulting in an out-of-bounds DMA access?
Alternatively, if the base address is omitted and left as U64_MAX, could
the hardware use a stale, out-of-bounds register offset from a previous
operation?
> + info->region_size[st->weight[0].region] =
> + max(info->region_size[st->weight[0].region],
> + st->weight[i].base + st->weight[i].length);
> + }
> }
>
> if (scale) {
[ ... ]
> @@ -306,6 +316,11 @@ static int calc_sizes(struct drm_device *ddev,
> info->region_size[st->scale[0].region] =
> max(info->region_size[st->scale[0].region],
> st->scale[0].base + st->scale[0].length);
> + if (st->scale[1].base != U64_MAX &&
> + st->scale[1].length != U32_MAX)
> + info->region_size[st->scale[0].region] =
[Severity: High]
This isn't a bug introduced by this patch, but the same sentinel bypass
issue exists here for the secondary scale buffer. Does this permit
arbitrary out-of-bounds DMA?
> + max(info->region_size[st->scale[0].region],
> + st->scale[1].base + st->scale[1].length);
> }
>
> len = feat_matrix_length(info, &st->ofm, st->ofm.width,
> st->ofm.height[2], st->ofm.depth);
[Severity: High]
This is a pre-existing issue, but does feat_matrix_length() properly
validate the base addresses of all tiles?
When calculating the feature matrix bounds in feat_matrix_length() in
drivers/accel/ethosu/ethosu_gem.c, the base address is validated like this:
if (fm->base[tile] == U64_MAX)
return U64_MAX;
addr = fm->base[tile] + y * fm->stride_y;
Could userspace set the base address of the first tile to an arbitrary
out-of-bounds address, and place the maximum spatial coordinates such that
they evaluate to the final tile? If so, the validation would only check the
base address of the final tile and ignore the earlier tiles, while the NPU
processes all tiles and performs an out-of-bounds DMA at the malicious
address.
[Severity: High]
This is another pre-existing issue, but does the bounds check logic in
dma_length() in drivers/accel/ethosu/ethosu_gem.c correctly handle negative
strides?
The function updates the upper bound without checking the lower bound
against 0:
if (dma->stride[0] < 0 && (u64)(-dma->stride[0]) > len)
return U64_MAX;
len += dma->stride[0];
Since the NPU supports negative strides that move the access pointer
backwards, a negative stride with a small offset could evaluate to a
negative address and wrap around. Could this allow the NPU to perform DMA
accesses to memory locations before the base address of the GEM object,
bypassing memory protections?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260605193311.48008-1-meatuni001@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-05 19:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-05 19:33 [PATCH] accel/ethosu: include secondary weight/scale extents in region_size[] accounting Muhammad Bilal
2026-06-05 19:50 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.