Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1q1CSr-00046F-8T for mharc-grub-devel@gnu.org; Mon, 22 May 2023 16:49:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1CSk-00044Q-Jo for grub-devel@gnu.org; Mon, 22 May 2023 16:49:02 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1CSh-0000Z7-TF for grub-devel@gnu.org; Mon, 22 May 2023 16:49:02 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34MKOJZL011983 for ; Mon, 22 May 2023 20:48:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-03-30; bh=MvHIbkumOnb5KDhUiHWycPvlXY8zj2OGUN4a3jyzUd0=; b=F1EiwQVTkpRExRDFz0q1m/FBPSVLckydG3KL/Bd/N/6hkEeGZCvoa9q7OicA/B2yNWTB Jy86grY4pSqP/oGIE83KAuVdV9/r94shoGGzZO+72lO5pnRRNv9p5PwB9P4nv63dMnEo Vs4HVmdjCdDToz7wf1+MzXOdpm8+EYErPlmyn7Q5f4q9piaVCVlr4cNxOtj947FJK6Qy Jxvg7Dv0ILd+tHtgf/ZLWdg67omhIVV7jXAIdMl7GoBsbT5RkFCaIOkqPunDq6xS3mAz vr05ivlHrsVcis6BDgkft7tkcBUnwOp8WfgcvkWSx0/Y+SdCZQMjhpOOZkl1GHPsFW4q jQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp7yunx7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 22 May 2023 20:48:56 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34MJaxCp028896 for ; Mon, 22 May 2023 20:48:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk29y4j4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 22 May 2023 20:48:53 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34MKmqeR012121 for ; Mon, 22 May 2023 20:48:52 GMT Received: from localhost (dhcp-10-152-9-171.usdhcp.oraclecorp.com [10.152.9.171]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk29y4ht-1; Mon, 22 May 2023 20:48:52 +0000 From: Alec Brown To: grub-devel@gnu.org Cc: daniel.kiper@oracle.com, alec.r.brown@oracle.com Subject: [PATCH 2/4] elf: Check section header region before allocating memory Date: Mon, 22 May 2023 16:52:47 -0400 Message-Id: <1684788769-21297-3-git-send-email-alec.r.brown@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1684788769-21297-1-git-send-email-alec.r.brown@oracle.com> References: <1684788769-21297-1-git-send-email-alec.r.brown@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-22_15,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=640 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305220176 X-Proofpoint-ORIG-GUID: mVjVRMenltO1wFvC5xoErNPXW_gxDnIz X-Proofpoint-GUID: mVjVRMenltO1wFvC5xoErNPXW_gxDnIz Received-SPF: pass client-ip=205.220.177.32; envelope-from=alec.r.brown@oracle.com; helo=mx0b-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, T_SCC_BODY_TEXT_LINE=-0.01 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: Mon, 22 May 2023 20:49:02 -0000 In grub-core/loader/multiboot_elfxx.c, space is being allocated for the section header region, but isn't verifying if the region is within the file's size. Before calling grub_calloc(), we can add a conditional to check if the section header region is smaller than the file size. Fixes: CID 314029 Fixes: CID 314038 Signed-off-by: Alec Brown --- grub-core/loader/multiboot_elfxx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c index 69f567588..52eaf9184 100644 --- a/grub-core/loader/multiboot_elfxx.c +++ b/grub-core/loader/multiboot_elfxx.c @@ -248,6 +248,9 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) { grub_uint8_t *shdr, *shdrptr; + if ((grub_off_t) ehdr->e_shoff + shnum * ehdr->e_shentsize > grub_file_size (mld->file)) + return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("ELF section header region is larger than the file size")); + shdr = grub_calloc (shnum, ehdr->e_shentsize); if (!shdr) return grub_errno; -- 2.27.0