From: Muhammad Bilal <meatuni001@gmail.com>
To: robh@kernel.org
Cc: tomeu@tomeuvizoso.net, ogabbay@kernel.org, tzimmermann@suse.de,
Frank.Li@nxp.com, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Muhammad Bilal <meatuni001@gmail.com>
Subject: [PATCH] accel/ethosu: fix integer overflow in dma_length()
Date: Sun, 24 May 2026 05:16:58 +0000 [thread overview]
Message-ID: <20260524051659.70654-1-meatuni001@gmail.com> (raw)
dma_length() computes the total DMA transfer length as:
len = ((len + stride[0]) * size0 + stride[1]) * size1
where len and stride[] are 64-bit values derived from user-supplied
40-bit command stream fields, and size0/size1 are user-supplied u16
values.
The final multiplication by size1 (up to 65535) on an intermediate
result that can already be ~2^55 easily exceeds 2^64, wrapping the
u64 result to a small positive value.
This wrapped value is then stored in info->region_size[] and compared
against gem->size in ethosu_job.c:
if (cmd_info->region_size[i] > gem->size)
return -EOVERFLOW;
A userspace caller can craft stride and size values so that the
calculated length wraps to zero or a small value, passing this check
while the hardware executes a DMA transfer with the original large
strides, accessing memory far outside the GEM buffer.
Fix by replacing the unchecked multiplications with
check_mul_overflow(), returning U64_MAX on overflow. The callers
of dma_length() already treat U64_MAX as an error sentinel.
Fixes: 5a5e9c0228e6 ("accel: Add Arm Ethos-U NPU driver")
Cc: stable@vger.kernel.org
Signed-off-by: Muhammad Bilal <meatuni001@gmail.com>
---
drivers/accel/ethosu/ethosu_gem.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/accel/ethosu/ethosu_gem.c b/drivers/accel/ethosu/ethosu_gem.c
index 5a02285a4986..1f132611a6ce 100644
--- a/drivers/accel/ethosu/ethosu_gem.c
+++ b/drivers/accel/ethosu/ethosu_gem.c
@@ -2,6 +2,7 @@
/* Copyright 2025 Arm, Ltd. */
#include <linux/err.h>
+#include <linux/overflow.h>
#include <linux/slab.h>
#include <drm/ethosu_accel.h>
@@ -165,11 +166,13 @@ static u64 dma_length(struct ethosu_validated_cmdstream_info *info,
if (mode >= 1) {
len += dma->stride[0];
- len *= dma_st->size0;
+ if (check_mul_overflow(len, (u64)dma_st->size0, &len))
+ return U64_MAX;
}
if (mode == 2) {
len += dma->stride[1];
- len *= dma_st->size1;
+ if (check_mul_overflow(len, (u64)dma_st->size1, &len))
+ return U64_MAX;
}
if (dma->region >= 0)
info->region_size[dma->region] = max(info->region_size[dma->region],
--
2.53.0
next reply other threads:[~2026-05-25 6:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-24 5:16 Muhammad Bilal [this message]
2026-05-24 6:06 ` [PATCH v2] accel/ethosu: fix integer overflow and underflow in dma_length() Muhammad Bilal
2026-05-24 10:37 ` [PATCH v3] accel/ethosu: fix arithmetic issues " Muhammad Bilal
2026-05-25 7:08 ` Claude review: " Claude Code Review Bot
2026-05-25 7:08 ` Claude review: accel/ethosu: fix integer overflow and underflow " Claude Code Review Bot
2026-05-25 7:08 ` Claude review: accel/ethosu: fix integer overflow " Claude Code Review Bot
2026-05-25 7:08 ` Claude Code Review Bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260524051659.70654-1-meatuni001@gmail.com \
--to=meatuni001@gmail.com \
--cc=Frank.Li@nxp.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ogabbay@kernel.org \
--cc=robh@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tomeu@tomeuvizoso.net \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox