Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1ojSUd-0003uX-K1 for mharc-grub-devel@gnu.org; Fri, 14 Oct 2022 17:45:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ojSUT-0003pw-Jf for grub-devel@gnu.org; Fri, 14 Oct 2022 17:45:14 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:14244) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ojSUQ-00013n-N7 for grub-devel@gnu.org; Fri, 14 Oct 2022 17:45:12 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29ELPeaC030434; Fri, 14 Oct 2022 21:45:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2022-7-12; bh=kLD2pQ1QDGUuxB6gBQnwqYmzX3wMdJ5KDwcpAeBS8aY=; b=cekNa0XAIkmPk8n/glMwFocnrw5upbXlKWe0pwI2/B3y06o0Qo1Quv2KvBVTqsCtEnOD EdZ0EI9325FlMcALj27wcdQjVa8zhimpj9ONF6nxXJxrUCfpn9XF+wPrq7CXuFlYmmtJ DAhz2D4d0u3ovqcpphgIq+O84T2hYkQUc8pE5zpvwrFSuIgw6SG2dGVOShZLO1etmiwH 5KFshWDJ4EXJsdtl3AYJmYaY3uwOy5yTPZuFGhV/miay/NOGmvNNCvMeS80NT0T0mlCR /A8mbIDRTk6/eg061M+07zI+YdOpqH79Cm27DfEdCjF6oMmgjPtSodrvRDIJA20GLbii jw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3k799sh23k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Oct 2022 21:45:03 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29EK003T019031; Fri, 14 Oct 2022 21:45:03 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3k2yn7n542-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Oct 2022 21:45:03 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29ELgvij023044; Fri, 14 Oct 2022 21:45:02 GMT Received: from localhost (dhcp-10-152-14-18.usdhcp.oraclecorp.com [10.152.14.18]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3k2yn7n53b-1; Fri, 14 Oct 2022 21:45:02 +0000 From: Alec Brown To: grub-devel@gnu.org Cc: daniel.kiper@oracle.com, alec.r.brown@oracle.com, darren.kenny@oracle.com, development@efficientek.com, ps@pks.im Subject: [PATCH v2] grub-core/disk/cryptodisk.c: Fix unintentional integer overflow Date: Fri, 14 Oct 2022 17:47:08 -0400 Message-Id: <1665784028-11871-1-git-send-email-alec.r.brown@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-14_11,2022-10-14_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 adultscore=0 malwarescore=0 phishscore=0 suspectscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210140119 X-Proofpoint-GUID: ulOPjuM4VXgAHav6b_6Cjy13tu8hpEVh X-Proofpoint-ORIG-GUID: ulOPjuM4VXgAHav6b_6Cjy13tu8hpEVh Received-SPF: pass client-ip=205.220.165.32; envelope-from=alec.r.brown@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Oct 2022 21:45:15 -0000 In the function grub_cryptodisk_endecrypt(), a for loop is incrementing the variable i by (1U << log_sector_size). The variable i is of type grub_size_t which is a 64-bit unsigned integer on x86_64 architecture. On the other hand, 1U is a 32-bit unsigned integer. By performing a left shift on a 32-bit value and assigning it to a 64-bit variable, the 64-bit variable may have incorrect values in the high 32-bits if the shift has an overflow. To avoid this, we replace 1U with (grub_size_t) 1. Fixes: CID 307788 Signed-off-by: Alec Brown --- There was a mistake in v1 of the commit message describing the issue in the code. This version fixes the commit message so that it's accurate. grub-core/disk/cryptodisk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 9f5dc7acb..cdcb882ca 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -239,7 +239,7 @@ grub_cryptodisk_endecrypt (struct grub_cryptodisk *dev, return (do_encrypt ? grub_crypto_ecb_encrypt (dev->cipher, data, data, len) : grub_crypto_ecb_decrypt (dev->cipher, data, data, len)); - for (i = 0; i < len; i += (1U << log_sector_size)) + for (i = 0; i < len; i += ((grub_size_t) 1 << log_sector_size)) { grub_size_t sz = ((dev->cipher->cipher->blocksize + sizeof (grub_uint32_t) - 1) -- 2.27.0