From 26a278473be90321b51a88082cd0a37e2dee3112 Mon Sep 17 00:00:00 2001 From: Anandu Krishnan E Date: Wed, 7 May 2025 15:05:08 +0530 Subject: [PATCH] dsp-kernel: Avoid overflow in ALIGN macro usage Check for potential overflow before using the ALIGN macro, as it is not overflow-safe. Change-Id: Iffa1b7a01a9e072fb748c93f6625d0f1a163d0f8 Signed-off-by: Anandu Krishnan E (cherry picked from commit 96a6c4a8768f73ba9041c15511f0d5888507c8f4) --- drivers/misc/fastrpc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index f1bfaad2ce27..3cf9ba563cfc 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -710,8 +710,12 @@ static u64 fastrpc_get_payload_size(struct fastrpc_invoke_ctx *ctx, int metalen) if (ctx->args[i].fd == 0 || ctx->args[i].fd == -1) { - if (ctx->olaps[oix].offset == 0) + if (ctx->olaps[oix].offset == 0) { + /* Check for overflow before align. */ + if (size > (ULLONG_MAX - (FASTRPC_ALIGN - 1))) + return 0; size = ALIGN(size, FASTRPC_ALIGN); + } size += (ctx->olaps[oix].mend - ctx->olaps[oix].mstart); }