All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] misc: fastrpc: reject oversized DMA allocations
@ 2026-06-25  8:56 Yousef Alhouseen
  2026-06-25  8:56 ` [PATCH 2/3] misc: fastrpc: fix map cleanup paths Yousef Alhouseen
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Yousef Alhouseen @ 2026-06-25  8:56 UTC (permalink / raw)
  To: Srinivas Kandagatla, Amol Maheshwari
  Cc: Konrad Dybcio, Arnd Bergmann, Greg Kroah-Hartman, linux-arm-msm,
	dri-devel, linux-kernel, Yousef Alhouseen

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-06-25 13:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-25  8:56 [PATCH 1/3] misc: fastrpc: reject oversized DMA allocations Yousef Alhouseen
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

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.