Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nhMTP-0002nK-5f for mharc-grub-devel@gnu.org; Wed, 20 Apr 2022 22:23:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50050) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhMTN-0002ma-Vn for grub-devel@gnu.org; Wed, 20 Apr 2022 22:23:10 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:61586) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhMTK-00066X-0U for grub-devel@gnu.org; Wed, 20 Apr 2022 22:23:09 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23KM41r8019815 for ; Thu, 21 Apr 2022 02:23:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2021-07-09; bh=u11hTVX0rsWzNTRB4IdwAs25a1ItUgl4Dpysms/aYOQ=; b=Fh/EqoAH5UgboV4vcRTkI1gv6C4BCl+yRjsx9VpWlevftYjmGL1gtOzCaYBihJ7OW2oh U7d2Ni+KB3PL0H2+jmPwpddNft8Gf2t+zZf6WAbXep/mbnvDijjMy5im9ehF+uck10uH jLMm7SsqxptCVcXMP1NADDzfsPb+ZYGKpbDHjveOeDLo88ObwWTLzR7JQH8j5XjMT1XT +MrSAZ7rWZwxXI+IQUI8xZ3RIzu6fterRYKg/l+nfNDenX68OfJmKikRmazAirfVFlHW g5gB+pdbIUSQ1E85jSIIL43YfmF+AkxfFP+ZzrtB7jfUT83rRxETyrMB6yQkkAGyLsW8 cg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com with ESMTP id 3ffmd1atux-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 21 Apr 2022 02:23:00 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23L26AIk002336 for ; Thu, 21 Apr 2022 02:23:00 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3ffm890jke-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 21 Apr 2022 02:23:00 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 23L2JWu6035474 for ; Thu, 21 Apr 2022 02:22:59 GMT Received: from localhost (dhcp-10-152-14-18.usdhcp.oraclecorp.com [10.152.14.18]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3ffm890jk4-1; Thu, 21 Apr 2022 02:22:59 +0000 From: Alec Brown To: grub-devel@gnu.org Cc: daniel.kiper@oracle.com, darren.kenny@oracle.com, alec.r.brown@oracle.com Subject: [PATCH v3 0/5] Fix coverity bugs and add checks for elf values in grub-core Date: Wed, 20 Apr 2022 22:23:12 -0400 Message-Id: <1650507797-12137-1-git-send-email-alec.r.brown@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-Proofpoint-ORIG-GUID: AmCvfAGgl4Wf9Itk82cP71FO6hMRIWnM X-Proofpoint-GUID: AmCvfAGgl4Wf9Itk82cP71FO6hMRIWnM 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_H5=0.001, RCVD_IN_MSPIKE_WL=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: Thu, 21 Apr 2022 02:23:10 -0000 v3: Added check for e_shoff, made starting words lowercase in error messages, and added comment to why return pointers are set to 0. Coverity identified several untrusted loop bounds and untrusted allocation size bugs in grub-core/loader/i386/bsdXX.c and grub-core/loader/multiboot_elfXX.c. Upon review of these bugs, I found that specific checks weren't being made to various elf header values based on the elf manual page. This patch series addresses the coverity bugs, as well as adds functions to check for the correct elf header values. The Coverity bugs being addressed are: CID 314018 CID 314030 CID 314031 CID 314039 Alec Brown (5): grub-core/loader/i386/bsdXX.c: Avoid downcasting (char *) to (Elf_Shdr *) elf: Validate number of elf section header table entries elf: Validate elf section header table index for section name string table elf: Validate number of elf program header table entries util/grub-module-verifierXX.c: Add e_shoff check in get_shdr() grub-core/kern/elf.c | 15 +++++++++++++++ grub-core/kern/elfXX.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ grub-core/loader/i386/bsdXX.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------- grub-core/loader/multiboot_elfxx.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++------------------------- include/grub/elf.h | 18 ++++++++++++++++++ util/grub-module-verifierXX.c | 3 +++ 6 files changed, 273 insertions(+), 77 deletions(-)