From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BA1012C52C; Tue, 23 Jan 2024 00:15:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705968925; cv=none; b=MSyw6kzTRifcOM6ui+RN8Eanheus1qxw8DTG3JgjxQ3E4iqERyrKM6Nk1efYUXWqou42x52FixDBabLjMfrs4/FrBdNwCTu6X/1CZFvWNIKur24AUSi7gdydum6UaX8yI4HQemKmm6VwsGNKBzZmTBrSrW/aFHjAsqCqfPMpm8o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705968925; c=relaxed/simple; bh=zjlhkCDkbLl6tVBxvLr/jDPdC3pADY5RFzF9qg+AJF0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KkaFtVltC8cuCCl2Hg3liVvgTN0+YK1cUsxdUD6uZ6GhU4RN1v11vyu7J2BVhOZKNEZxJhmcwKeznL7h079R04Y2nedhUY0Rg4FK/mlpZGddf7a4qoHypSk4+jEGT7LcfwIKGfvaA2PujPiYw6lLTNp+oj4v/4lyU62EQ/j+6TU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CikYhjh/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CikYhjh/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2CF7C433F1; Tue, 23 Jan 2024 00:15:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705968925; bh=zjlhkCDkbLl6tVBxvLr/jDPdC3pADY5RFzF9qg+AJF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CikYhjh/TXjpVpaMCnIw/Jg5xFmRjnDBiV2B52o8wZ4NncvJtawlSWoVKHFzZvvXZ gQpXEKo5Cpv919gWgzFbr/sFfR+2GL4y/aqiHB4tk5Y2jy8jd7VlhpPR4hbYUYC5u1 bGoQGIemZkHgo1Tl9CYa/xjbwykpllA6RnAs1dQM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sergey Shtylyov , Kees Cook , Sasha Levin Subject: [PATCH 5.4 069/194] pstore: ram_core: fix possible overflow in persistent_ram_init_ecc() Date: Mon, 22 Jan 2024 15:56:39 -0800 Message-ID: <20240122235722.178807558@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235719.206965081@linuxfoundation.org> References: <20240122235719.206965081@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sergey Shtylyov [ Upstream commit 86222a8fc16ec517de8da2604d904c9df3a08e5d ] In persistent_ram_init_ecc(), on 64-bit arches DIV_ROUND_UP() will return 64-bit value since persistent_ram_zone::buffer_size has type size_t which is derived from the 64-bit *unsigned long*, while the ecc_blocks variable this value gets assigned to has (always 32-bit) *int* type. Even if that value fits into *int* type, an overflow is still possible when calculating the size_t typed ecc_total variable further below since there's no cast to any 64-bit type before multiplication. Declaring the ecc_blocks variable as *size_t* should fix this mess... Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool. Fixes: 9cc05ad97c57 ("staging: android: persistent_ram: refactor ecc support") Signed-off-by: Sergey Shtylyov Link: https://lore.kernel.org/r/20231105202936.25694-1-s.shtylyov@omp.ru Signed-off-by: Kees Cook Signed-off-by: Sasha Levin --- fs/pstore/ram_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c index 079f1a15cab0..679b250a3912 100644 --- a/fs/pstore/ram_core.c +++ b/fs/pstore/ram_core.c @@ -190,7 +190,7 @@ static int persistent_ram_init_ecc(struct persistent_ram_zone *prz, { int numerr; struct persistent_ram_buffer *buffer = prz->buffer; - int ecc_blocks; + size_t ecc_blocks; size_t ecc_total; if (!ecc_info || !ecc_info->ecc_size) -- 2.43.0