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 <quic_anane@quicinc.com>
(cherry picked from commit 96a6c4a8768f73ba9041c15511f0d5888507c8f4)
This commit is contained in:
Anandu Krishnan E 2025-05-07 15:05:08 +05:30 • committed by Michael Bestas
commit 26a278473b
No known key found for this signature in database
GPG key ID: CC95044519BE6669

View file

@ -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);
}