From: Pengpeng Hou <pengpeng@iscas.ac.cn>
To: srini@kernel.org, amahesh@qti.qualcomm.com, arnd@arndb.de,
gregkh@linuxfoundation.org
Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, pengpeng@iscas.ac.cn
Subject: [PATCH] misc: fastrpc: keep copied arguments inside the invoke buffer
Date: Tue, 24 Mar 2026 09:44:59 +0800 [thread overview]
Message-ID: <20260324014459.93364-1-pengpeng@iscas.ac.cn> (raw)
fastrpc_get_args() derives rpra[i].buf.pv from the overlap offset that
was computed from user-controlled argument pointers and lengths. The
resulting destination pointer is then used for copy_from_user() without
first checking that it still falls inside the allocated invoke buffer.
Validate the overlap-derived destination range before storing it in
rpra[i].buf.pv and before copying inline arguments into the invoke
buffer.
---
drivers/misc/fastrpc.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 47356a5d5804..d7f53300b899 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -993,6 +993,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
u64 len, rlen, pkt_size;
u64 pg_start, pg_end;
uintptr_t args;
+ uintptr_t buf_start, buf_end;
int metalen;
inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
@@ -1016,6 +1017,8 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
rpra = ctx->buf->virt;
list = fastrpc_invoke_buf_start(rpra, ctx->nscalars);
pages = fastrpc_phy_page_start(list, ctx->nscalars);
+ buf_start = (uintptr_t)ctx->buf->virt;
+ buf_end = buf_start + pkt_size;
args = (uintptr_t)ctx->buf->virt + metalen;
rlen = pkt_size - metalen;
ctx->rpra = rpra;
@@ -1053,6 +1056,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
pages[i].size = (pg_end - pg_start + 1) * PAGE_SIZE;
} else {
+ uintptr_t dst;
if (ctx->olaps[oix].offset == 0) {
rlen -= ALIGN(args, FASTRPC_ALIGN) - args;
@@ -1064,7 +1068,18 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
if (rlen < mlen)
goto bail;
- rpra[i].buf.pv = args - ctx->olaps[oix].offset;
+ if (ctx->olaps[oix].offset > args - buf_start) {
+ err = -EINVAL;
+ goto bail;
+ }
+
+ dst = args - ctx->olaps[oix].offset;
+ if (len > buf_end - dst) {
+ err = -EINVAL;
+ goto bail;
+ }
+ rpra[i].buf.pv = dst;
+
pages[i].addr = ctx->buf->dma_addr -
ctx->olaps[oix].offset +
(pkt_size - rlen);
--
2.50.1 (Apple Git-155)
next reply other threads:[~2026-03-24 9:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-24 1:44 Pengpeng Hou [this message]
2026-03-24 9:41 ` [PATCH] misc: fastrpc: keep copied arguments inside the invoke buffer Konrad Dybcio
2026-03-24 21:05 ` Claude review: " Claude Code Review Bot
2026-03-24 21:05 ` 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=20260324014459.93364-1-pengpeng@iscas.ac.cn \
--to=pengpeng@iscas.ac.cn \
--cc=amahesh@qti.qualcomm.com \
--cc=arnd@arndb.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--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