From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f41.google.com (mail-yx1-f41.google.com [74.125.224.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3ED0387345 for ; Thu, 25 Jun 2026 08:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782377844; cv=none; b=EaSn/T3451pz5j733dN687dFPg5pQQJvbDM7B5IrrkPnR4QEDuvwUbRvyb+4UFaJlQ+aMUjrQkqyvI2f4XVjS++WVUNazNxWwMK4novbwjZBt/aLCHYtZ3VYNhp55ES77O9PnvILUo/USOarS2avF+AP6QjbuSr6LJCcF8RFVuo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782377844; c=relaxed/simple; bh=lmA4nhBvMT9tW7gbg3hSIPL7ZKk1QgJkw5SszEVlhEU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=niqmR3YeAGYS79T7B7MGkbvcsD5QnCBgKiewsLJOZCbw2K8qmz6XocaaQUH8BOvQVZi0XiQfPlH7CrhRNCcT7c97sqeQNNM533iSc/K1NKRZ/Nzg9dLLgquc3s+zatAtHRgOhftS9zPCtUD/ivuw8rC5wPFaPehva6eCCDvP+Rs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nyBJrK/P; arc=none smtp.client-ip=74.125.224.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nyBJrK/P" Received: by mail-yx1-f41.google.com with SMTP id 956f58d0204a3-662c360aa73so2105698d50.3 for ; Thu, 25 Jun 2026 01:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782377842; x=1782982642; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=B4FF8nNbzEIIdzHCql4jtvlByyo4hD6ECsylMtCq6+k=; b=nyBJrK/PAJzyRkC4h9pJmpFDaHqmVztYM7KOQ7RrSH6iiDoxGzzhovt1nPuWbtOIBg 3CB596vWBVCxUkgjxumQpYhFPaY94doST4s7K3ndB8yCJHgeNt9V7SjqgEDj9qQY9Qp5 sAJ9YtPuPygc/k80f6GypAPzJRpTIgt6+ZUYLzHtf4O7BMlCzKrU320iqbbqvyBh1tSy TnbstpgsWAosJXY5MINV88gKtT9vmWo/gVGz45CWggcInbAziz2bdDf2fQEjm1gxIY4b WqwWtA/eoHPHHUEEfjpLY8t15tr48gAs3GskSY3/rYpX93xq+HvA8ebUkHKxHqVMI+Xt ktHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782377842; x=1782982642; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=B4FF8nNbzEIIdzHCql4jtvlByyo4hD6ECsylMtCq6+k=; b=fQpKlsJ6N2+nd6lu47g9oCY0UBPMelouhvGaDIIQrSt4C9G4u8rCgWAkgHP8ZzrnlV 7aAGhJ6vXepoKx2wZOd6US0xNUs+jH70m9u6t9deLs6jRuyQ8IWE9CdZ99W33tRcxO7I rPHkkBQu6R4LR45ZqO4fXzhuF7iRtbcgAg8c8nFV7p/mpIUMpDrZM8XIQqIhYfAzhqXc tF/hLJrmCKx00otBaQFeZ8K8vNrzagU5T//nqvviPE6IpcOW4NUHjS1MneZIxAfC6IUD gWDSlP+28OjRgF9DtPGh51gJC5nERn/06u4JfSY2hh0DBqs+tF8U3VRC9ifK1LG/2cDW jNIg== X-Forwarded-Encrypted: i=1; AHgh+RqeW+KNht7yuxYS2p00EOEKCfZuzoixGSq1Qn9ChlLzxVLBneJHRuA7kvzzf52CnD1gnu9wjrbH7oreO58=@vger.kernel.org X-Gm-Message-State: AOJu0YyyAFjCb0yZUUYi2v/VtQesJL+b6RHP9zgigIAKcGQbsMaF5UHh iVwglxm0VUMLsc1Dnrt4TQ9/hgJ5eaRiqA3qtESTBHyixcZOtzDreqEd X-Gm-Gg: AfdE7cllF01wIxVJXFgtst3iA5GmNtfaJPMJQvKUBf6cyqZ1dz9hAwnyuUSFEit9PAc iuYIwQJyc3ie45L02OeiDr1jia66Gb2vX5CFC3BK1T5OaH9Suis7KSaSF0RN7Km0U5E2rpEsTX5 NKJwukDvfW0vP3+dkL4Y3KoFXJTxHoPO3mp9QIf+yqPJDRbeY+nRvpUK5MQmvvQQCtG2xwax854 v1Vud0sB0s0Bf6uFdu/PVaM+TgFpxspzWKfZGXGLNqr4p8eTrFt3928qjut2Uq/xjS9I6SkczzO mN+MuETJewQm0gR59fan4sKVp/nQ01x3fWYvZTxUEzsur7MA0WA93osXRPDA8OsfBK4zhdaa0er Gi9rL0ZRfyqPEJSW1+XOPRUAsKuWDyYkOF0bK+NG44PocFq7qLXYNRcwf+0xgcFDJko93f9m4Qk BOz4ExfTGft0TaBuQhKdjzz1A76aOYJbaOZ1V1 X-Received: by 2002:a05:690e:e8f:b0:662:e0b5:33b with SMTP id 956f58d0204a3-66487debde5mr1230262d50.8.1782377841950; Thu, 25 Jun 2026 01:57:21 -0700 (PDT) Received: from Dev-Null-MSI ([2a0d:3344:52ac:a808:98a4:4381:be45:536f]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6647f785f6bsm1105061d50.6.2026.06.25.01.57.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2026 01:57:21 -0700 (PDT) From: Yousef Alhouseen To: Srinivas Kandagatla , Amol Maheshwari Cc: Konrad Dybcio , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Yousef Alhouseen Subject: [PATCH 1/3] misc: fastrpc: reject oversized DMA allocations Date: Thu, 25 Jun 2026 10:56:57 +0200 Message-ID: <20260625085659.4469-1-alhouseenyousef@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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