From: Yousef Alhouseen <alhouseenyousef@gmail.com>
To: Srinivas Kandagatla <srini@kernel.org>,
Amol Maheshwari <amahesh@qti.qualcomm.com>
Cc: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>,
Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org,
Yousef Alhouseen <alhouseenyousef@gmail.com>
Subject: [PATCH 1/3] misc: fastrpc: reject oversized DMA allocations
Date: Thu, 25 Jun 2026 10:56:57 +0200 [thread overview]
Message-ID: <20260625085659.4469-1-alhouseenyousef@gmail.com> (raw)
FastRPC keeps invoke and mmap buffer sizes in u64 fields, but coherent
DMA allocation takes a size_t. On 32-bit builds, a size above SIZE_MAX
can be truncated before allocation while the larger value is still used
in the message sent to the DSP.
Reject sizes that cannot fit in size_t before allocating the DMA buffer.
Also make the inline payload alignment step overflow-aware so a
near-U64_MAX accumulator cannot wrap before the later bounds checks.
Signed-off-by: Yousef Alhouseen <alhouseenyousef@gmail.com>
---
drivers/misc/fastrpc.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index bfdf8ab6a..8992b5c0c 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -437,6 +437,9 @@ static int __fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev,
{
struct fastrpc_buf *buf;
+ if (size > SIZE_MAX)
+ return -EOVERFLOW;
+
buf = kzalloc_obj(*buf);
if (!buf)
return -ENOMEM;
@@ -1035,8 +1038,14 @@ static int fastrpc_get_payload_size(struct fastrpc_invoke_ctx *ctx, int metalen,
u64 len = ctx->olaps[oix].mend -
ctx->olaps[oix].mstart;
- if (ctx->olaps[oix].offset == 0)
- size = ALIGN(size, FASTRPC_ALIGN);
+ if (ctx->olaps[oix].offset == 0) {
+ u64 aligned;
+
+ if (check_add_overflow(size, FASTRPC_ALIGN - 1,
+ &aligned))
+ return -EOVERFLOW;
+ size = aligned & ~(FASTRPC_ALIGN - 1);
+ }
if (check_add_overflow(size, len, &size))
return -EOVERFLOW;
--
2.54.0
next reply other threads:[~2026-06-25 8:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-25 8:56 Yousef Alhouseen [this message]
2026-06-25 8:56 ` [PATCH 2/3] misc: fastrpc: fix map cleanup paths Yousef Alhouseen
2026-06-25 8:56 ` [PATCH 3/3] misc: fastrpc: protect interrupted mmap cleanup Yousef Alhouseen
2026-06-25 9:48 ` [PATCH 1/3] misc: fastrpc: reject oversized DMA allocations Greg Kroah-Hartman
2026-06-25 13:54 ` Yousef Alhouseen
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=20260625085659.4469-1-alhouseenyousef@gmail.com \
--to=alhouseenyousef@gmail.com \
--cc=amahesh@qti.qualcomm.com \
--cc=arnd@arndb.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=srini@kernel.org \
/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