Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nFPyH-0001QB-HP for mharc-grub-devel@gnu.org; Wed, 02 Feb 2022 19:27:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFPyE-0001In-9e for grub-devel@gnu.org; Wed, 02 Feb 2022 19:27:30 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:5774) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFPyB-0006yn-NN for grub-devel@gnu.org; Wed, 02 Feb 2022 19:27:29 -0500 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 212KwoJS024816 for ; Thu, 3 Feb 2022 00:27:26 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 : content-type : mime-version; s=corp-2021-07-09; bh=fIo2WrYSMW1eYmphvF69aNQWNr4gdKAxB/7PiSV1LsI=; b=Mf+A6QunbqxT5F4X7XTDzZBGp24qhm7N3/y8t/ODA8A5kESjPQgZWB1zCv1iSZoKsZiK vf2hqvsROgZ8sbCepqzz/P7Y6XIES1okUFGMJUqrBVTebXfdXsaCbv9ZDpo+P+3aaSi/ KnmeeYA7j2v4FLyajyRB6c/5cyaDHUuzPolzmjMaY6+17b/LbPmS2Gcg89MdvY+kHWse qyhvHj9T4EmJL7tIaN7Hf5qmx2GTYgKFJv2j7UUC6xVgWqoZF3hcXI8ilkT97vLIS0UB IM1cbXYyUW7kzqEQnxLGBovGKvGjGYN6pI/6B1XaskV3JFAKuwkNwRFSIgt+XAG3KTQ2 vQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3dxjatyv3f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Feb 2022 00:27:26 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 2130FFuB062105 for ; Thu, 3 Feb 2022 00:27:25 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2177.outbound.protection.outlook.com [104.47.57.177]) by aserp3020.oracle.com with ESMTP id 3dvwd96pjp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Feb 2022 00:27:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g8svB9hULpxsmlHGVbsKs8ZVsPQC5cL9+CpzqHweeuOBJgaxa8HGM7HKY9+c4LIEL/95gd7Ttb3vs3iUZLu3bWdGpeD44U0B8g+3aXksDacTH/AOX0enROUXmeItHMpDAfYdeKrH+b1HA5Q14AzRkkiL5WWvH4TO4c9l/mUtQvaFs23yNj9MWu4ZdRq71mL6TxCnSInM6QNrW//hJslGij7LJgnUxHIxDNSPzK4GHkwnNb1cP+tUqglhjANA2lJujabLnT7TI5kdkG3YZkp481DB7qUI4AT57H3Y7p9v1zhnjmx9eDVrK+K5z/jUZIpHMwfUYXphoj7habQkRXUPKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fIo2WrYSMW1eYmphvF69aNQWNr4gdKAxB/7PiSV1LsI=; b=GCHIlmNVapOyECiyFbFXmxTkq1xzN4srGz5Nlw/a2aiPYqKvS/jk1ovnAcMFO2jULR9C2VEBZempQXd6i+MyEsNqxsB/OSE7u15Ysfr91DenIOnPAkzPSNwYGVWPkdEpA3mxzdXgzzcCPwLS0Z7o5oxmzgHR6v85z9mOm2FgfWXwTcwL8WRiEZOqXrXkwrzETlFTBOEUsU0N0niUoWLLaBKonn/kMCK9jT/kmkUl/cgm++28fykv/nZnuZR6MDoqGnUHcdBDdd0/UNwRygtzyyviZcVua+zQuD+fnXUKpOCXolPb/W+u2EciUcD5XOp17NnHeKunm/xQhagysacmhQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fIo2WrYSMW1eYmphvF69aNQWNr4gdKAxB/7PiSV1LsI=; b=UYJeBQzwArHYovMvsYx1Ro+1ofHMN5UzsF4jmvlapD7Q1fu/34QnEXyNWNPsV8Q5V09qv6jluZWrY9a8ttLo4M/yiLxE64d36Rc/TXpZGeZFoCiG/QDcy0kI5YTwP7fQRc03xZluya4+BNBLpt5G6DrUQqAcx1EZ4WbDWkfrM38= Received: from DM6PR10MB2986.namprd10.prod.outlook.com (2603:10b6:5:6b::26) by SN6PR10MB2702.namprd10.prod.outlook.com (2603:10b6:805:48::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Thu, 3 Feb 2022 00:27:23 +0000 Received: from DM6PR10MB2986.namprd10.prod.outlook.com ([fe80::29f1:b031:153c:c9f9]) by DM6PR10MB2986.namprd10.prod.outlook.com ([fe80::29f1:b031:153c:c9f9%5]) with mapi id 15.20.4951.012; Thu, 3 Feb 2022 00:27:23 +0000 From: Alec Brown To: grub-devel@gnu.org Cc: daniel.kiper@oracle.com, darren.kenny@oracle.com Subject: [PATCH 4/4] util/grub-module-verifierXX.c: Add module_size parameter to functions for sanity checking Date: Wed, 2 Feb 2022 19:27:00 -0500 Message-Id: <1643848020-8197-5-git-send-email-alec.r.brown@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1643848020-8197-1-git-send-email-alec.r.brown@oracle.com> References: <1643848020-8197-1-git-send-email-alec.r.brown@oracle.com> Content-Type: text/plain X-ClientProxiedBy: BL1PR13CA0443.namprd13.prod.outlook.com (2603:10b6:208:2c3::28) To DM6PR10MB2986.namprd10.prod.outlook.com (2603:10b6:5:6b::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 58a2802d-3555-488c-f739-08d9e6abf261 X-MS-TrafficTypeDiagnostic: SN6PR10MB2702:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zqF0c2ZRgvZL6T+PoCNBsFl6k2+0ca2v1ekotLNW6lQRjiUEWpcBptVTydb33VBmHZoTYJSgOqPbpiK+PNtW0nZXVHxzjM5mauFxtbynoiOCUmNT4bFlF/dmuD9j5oUScvUGk9Dz7BiZuq3S+SV1xwvtdm6mcVTDtP/wYMdcTlQfhl5Bvnxs2tUsXbOmkVQ0PuYK7Kj/567kJwYguRwZADTh8omgDHlLKezDssnDR24GgPmQfOpRA+M+oNr+WIhmobh8oXuPrZTsvOXv9tBTqPQUww0FLa3sAVi7SyfH36iuZHveXOr/jpimjKo6GYLuumybGZduVg/5UOjQQg2wIyl1yAOTh2qtiag5PgnyouXoVbLYEMdHWq2sropOcgoARzlF6CHf09Mkd1uOruhJS2kaze6QsrfMTrPfVgvZwd8EI164hWMgaWRRqfkmWh+GufKCEC61+mkHcWT1vvgDud2ujBLzMWVOwLNUPp46oN7UtTXzX+oP7Eo1r8TYtWnQEMPbVpSRiSIiNuI3MaozkAmE2iskkla4L+4CGRzHqjP2MfZY5jqzOrwmducHBUvjw6lEMkUwADdAQwI0mlWwzqikS85uceb56p5NUqr5TuhFOH8SkucgDth0CWLfNtJvgTBVNxgfzNgAbenbWmGJHg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR10MB2986.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(26005)(186003)(508600001)(6666004)(6512007)(2616005)(6506007)(83380400001)(6486002)(107886003)(2906002)(316002)(6916009)(66946007)(66556008)(8676002)(8936002)(66476007)(86362001)(4326008)(36756003)(5660300002)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Lfx1f007aTKaIyqc2+e+0eo2dI5AfXfyF4xKJWZ8M8LIHgFTO5Ijwxo9DCQx?= =?us-ascii?Q?BZI3Hz8CcLH8TofDDvtw22oH3gAf1wJVIEcvnoIFkdOx127IiFQJiv2RVWVb?= =?us-ascii?Q?KcflCjz2bNbrzPLD5EqACEYljoXxwDb0jI0SA6Tx+zrHlarFMA1URD5Z5Dn1?= =?us-ascii?Q?JivGL5SJ3FNR7oAoPMQZXhRbkFbGtB3+hNyZRCHkgF9VQvFJHgCLkkoUO1Rz?= =?us-ascii?Q?c++nr9ekXX0khNZ8oTJx93REBtiw7u1ZL1b7+AHVe3KgZaknEb1vmmNF26sW?= =?us-ascii?Q?hEdGZL6MnWCMZZ2XI0WJlFuedLqs5zU/b1cAZ/aEsTRfIgaiFVEf0oZ98oDz?= =?us-ascii?Q?1m37Akkk9cU01TzXqFvppsWa8esNmizbchvCvBLNHL4DP6q86GJIhIsOf6nu?= =?us-ascii?Q?uKm0qFf2UTrUMugsLEzcmRqyhDDTpiSBw5Jr14u0aYmOi2HqBbUWrNg9vBeH?= =?us-ascii?Q?/HrY0NYX1/baV7ND8C0FkWGooO9Ogy04Wb/p2C5nI7VDr+89+U/W0uxVoem8?= =?us-ascii?Q?6fTc1IRNdj236K4kLAPXEpRbC3o1gtF54V6Tv6K7jvpEgIiiB3pIHhnhEkko?= =?us-ascii?Q?NIpNWDysadi1dulLf8QHp1LUW2dqBwzB+xDABNkFTryx49O/CSj0sYNZhGxl?= =?us-ascii?Q?oVorhcVjR5BuT+hE4g4DIrKagm//KJUrJi8VaQNjCg8nyS3+oNfDKKqlIBlp?= =?us-ascii?Q?lcfcuzKqB/Am6uSMyd3TpvudD+bE7G7wYrxySkr4qh098OHjNVj8VFqbId8P?= =?us-ascii?Q?xyZum5i4mHbvTlqTltPHIqD0DXZH792B7KPygy4lruJkhI3CSBj+P/6uf0Y8?= =?us-ascii?Q?OVC/H9YtgvzNaxi2PK3Can9IIt0U6/UMHFZdyWhfsXXG3uh7JBI3ZIbIM6ry?= =?us-ascii?Q?ynuZvTeYvUggxLgBtvAPiCVJT+5vX+rQTTe4y2fnzijdKGDPmA5opGW+ROcr?= =?us-ascii?Q?1qvyiJ0sZYmdzq1L2PbCnKQWPEAxKCwRb7sK7km2G+oOlRI+HT/G33FVugZJ?= =?us-ascii?Q?2O38lXbza3WriEdx8ET3PdB9mEdEztdYiQW2ly/vbcBYyoeR/HHXv4GQUKRp?= =?us-ascii?Q?3nzu9bhLXVVCjri7mo7snXdotd0ynRBW1M4tgOjmUCqg1fiPTurwlT9H5IZm?= =?us-ascii?Q?fwGvpWdMfsrow6d8gyAS6DwGTarmh9UtxLxxqfddlTr8zxEoXUd308mh7G+f?= =?us-ascii?Q?VjjOSEbfDoN4w1MZRDRkLipcFmmRV+KBPSZKkE7J9dRARgyfUQYSRFtPo50+?= =?us-ascii?Q?9N7vSQaNEHoXFAvJe0XSbWju9pKmwlBb6ZErw2V1zARheuF7S6DG+tFRBD9C?= =?us-ascii?Q?botUeZOoJIyG2/J29s7LWqt7hThS0o7GAM3qjhjt6CM9rbB4vdyQTrv8seOK?= =?us-ascii?Q?hLZprA7K6enIYeYRv6uo8/VmyB+ujFK0qu1y9e2QZYB9J13J006LL96qnQO4?= =?us-ascii?Q?Qdh/BXx0wwCImDNJp+P7HycHIr3Ny81HeXGTOt/VDUgG5WZh9xeumslqZDep?= =?us-ascii?Q?oe8fAmnWSASfaEYqj4KGLY7ernXp2dUTfhVm+TE4qvgmhMUTP2A9jBBtPEaP?= =?us-ascii?Q?NrSt88GPe7DidNucsEhWqRzveFuaiUqpzGlXcPC8tKko578/1dCFcDKZVpaM?= =?us-ascii?Q?7EQfRV8N4yO+Hh/3pk/LzFM=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 58a2802d-3555-488c-f739-08d9e6abf261 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB2986.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 00:27:23.1032 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vecy7GaUbn4NLPB/+bb/scIgT5FlGmnrpvst20VOvXlRa2Ezl/ihzQVXvUv1zQzva5LLFS8N9Sjh7P4aKFSELQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB2702 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10246 signatures=673430 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202030000 X-Proofpoint-GUID: K5Lcq5zYEK_oNttP-hGg3wCuHMZIoPoj X-Proofpoint-ORIG-GUID: K5Lcq5zYEK_oNttP-hGg3wCuHMZIoPoj 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, 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, 03 Feb 2022 00:27:30 -0000 In grub-module-verifierXX.c, the function grub_module_verifyXX() performs an initial check that the ELF section headers are within the module's size but doesn't check if the sections being accessed have contents that are within the module's size. In particular, we need to check that sh_offset and sh_size are less than the module's size. However, for some section header types we don't need to make these checks. For the type SHT_NULL, the section header is marked as inactive and the rest of the members within the section header have undefined values, so we don't need to check for sh_offset or sh_size. In the case of the type SHT_NOBITS, sh_offset has a conceptual offset which may be beyond the module size. Also, this type's sh_size may have a non-zero size, but a section of this type will take up no space in the module. This can all be checked in the function get_shdr(), but in order to do so, the parameter module_size must be added to functions so that the value of the module size can be used in get_shdr() from grub_module_verifyXX(). Signed-off-by: Alec Brown --- util/grub-module-verifierXX.c | 69 ++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c index 3a5265aff..ac7b6fa78 100644 --- a/util/grub-module-verifierXX.c +++ b/util/grub-module-verifierXX.c @@ -132,10 +132,21 @@ grub_target_to_host_real (const struct grub_module_verifier_arch *arch, grub_uin } static Elf_Shdr * -get_shdr (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, Elf_Word index) +get_shdr (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, Elf_Word index, size_t module_size) { - return (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff) + - index * grub_target_to_host16 (e->e_shentsize)); + Elf_Shdr *s; + + s = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff) + + index * grub_target_to_host16 (e->e_shentsize)); + /* Check that the header being accessed isn't outside the module size */ + if (grub_target_to_host32 (s->sh_type) != SHT_NULL && grub_target_to_host32 (s->sh_type) != SHT_NOBITS) + { + if (grub_target_to_host (s->sh_offset) > module_size) + grub_util_error ("Section %d starts after the end of the module", index); + if (grub_target_to_host (s->sh_offset) + grub_target_to_host (s->sh_size) > module_size) + grub_util_error ("Section %d ends after the end of the module", index); + } + return s; } static Elf_Word @@ -147,7 +158,7 @@ get_shnum (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e) shnum = grub_target_to_host16 (e->e_shnum); if (shnum == SHN_UNDEF) { - s = get_shdr (arch, e, 0); + s = get_shdr (arch, e, 0, 0); shnum = grub_target_to_host (s->sh_size); if (shnum < SHN_LORESERVE) grub_util_error ("Invalid number of section header table entries in sh_size: %d", shnum); @@ -162,7 +173,7 @@ get_shnum (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e) } static Elf_Word -get_shstrndx (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e) +get_shstrndx (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, size_t module_size) { Elf_Shdr *s; Elf_Word shstrndx; @@ -170,7 +181,7 @@ get_shstrndx (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e) shstrndx = grub_target_to_host16 (e->e_shstrndx); if (shstrndx == SHN_XINDEX) { - s = get_shdr (arch, e, 0); + s = get_shdr (arch, e, 0, 0); shstrndx = grub_target_to_host (s->sh_link); if (shstrndx < SHN_LORESERVE) grub_util_error ("Invalid section header table index in sh_link: %d", shstrndx); @@ -185,18 +196,18 @@ get_shstrndx (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e) } static Elf_Shdr * -find_section (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const char *name) +find_section (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const char *name, size_t module_size) { Elf_Shdr *s; const char *str; unsigned i; - s = get_shdr (arch, e, get_shstrndx (arch, e)); + s = get_shdr (arch, e, get_shstrndx (arch, e, module_size), module_size); str = (char *) e + grub_target_to_host (s->sh_offset); - for (i = 0, s = get_shdr (arch, e, 0); + for (i = 0, s = get_shdr (arch, e, 0, 0); i < get_shnum (arch, e); - i++, s = get_shdr (arch, e, i)) + i++, s = get_shdr (arch, e, i, module_size)) if (strcmp (str + grub_target_to_host32 (s->sh_name), name) == 0) return s; return NULL; @@ -204,9 +215,9 @@ find_section (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const c static void check_license (const char * const filename, - const struct grub_module_verifier_arch *arch, Elf_Ehdr *e) + const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, size_t module_size) { - Elf_Shdr *s = find_section (arch, e, ".module_license"); + Elf_Shdr *s = find_section (arch, e, ".module_license", module_size); if (s && (strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3") == 0 || strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3+") == 0 || strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv2+") == 0)) @@ -215,15 +226,15 @@ check_license (const char * const filename, } static Elf_Sym * -get_symtab (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, Elf_Word *size, Elf_Word *entsize) +get_symtab (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, Elf_Word *size, Elf_Word *entsize, size_t module_size) { unsigned i; Elf_Shdr *s; Elf_Sym *sym; - for (i = 0, s = get_shdr (arch, e, 0); + for (i = 0, s = get_shdr (arch, e, 0, 0); i < get_shnum (arch, e); - i++, s = get_shdr (arch, e, i)) + i++, s = get_shdr (arch, e, i, module_size)) if (grub_target_to_host32 (s->sh_type) == SHT_SYMTAB) break; @@ -253,7 +264,7 @@ is_whitelisted (const char *modname, const char **whitelist) static void check_symbols (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const char *modname, - const char **whitelist_empty) + const char **whitelist_empty, size_t module_size) { Elf_Sym *sym; Elf_Word size, entsize; @@ -261,7 +272,7 @@ check_symbols (const struct grub_module_verifier_arch *arch, /* Module without symbol table and without .moddeps section is useless at boot time, so catch it early to prevent build errors */ - sym = get_symtab (arch, e, &size, &entsize); + sym = get_symtab (arch, e, &size, &entsize, module_size); if (!sym) { Elf_Shdr *s; @@ -273,7 +284,7 @@ check_symbols (const struct grub_module_verifier_arch *arch, if (is_whitelisted (modname, whitelist_empty)) return; - s = find_section (arch, e, ".moddeps"); + s = find_section (arch, e, ".moddeps", module_size); if (!s) grub_util_error ("%s: no symbol table and no .moddeps section", modname); @@ -328,13 +339,13 @@ is_symbol_local(Elf_Sym *sym) static void section_check_relocations (const char * const modname, const struct grub_module_verifier_arch *arch, void *ehdr, - Elf_Shdr *s, size_t target_seg_size) + Elf_Shdr *s, size_t target_seg_size, size_t module_size) { Elf_Rel *rel, *max; Elf_Sym *symtab; Elf_Word symtabsize, symtabentsize; - symtab = get_symtab (arch, ehdr, &symtabsize, &symtabentsize); + symtab = get_symtab (arch, ehdr, &symtabsize, &symtabentsize, module_size); if (!symtab) grub_util_error ("%s: relocation without symbol table", modname); @@ -410,14 +421,14 @@ section_check_relocations (const char * const modname, static void check_relocations (const char * const modname, - const struct grub_module_verifier_arch *arch, Elf_Ehdr *e) + const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, size_t module_size) { Elf_Shdr *s; unsigned i; - for (i = 0, s = get_shdr (arch, e, 0); + for (i = 0, s = get_shdr (arch, e, 0, 0); i < get_shnum (arch, e); - i++, s = get_shdr (arch, e, i)) + i++, s = get_shdr (arch, e, i, module_size)) if (grub_target_to_host32 (s->sh_type) == SHT_REL || grub_target_to_host32 (s->sh_type) == SHT_RELA) { Elf_Shdr *ts; @@ -430,9 +441,9 @@ check_relocations (const char * const modname, /* Find the target segment. */ if (grub_target_to_host32 (s->sh_info) >= get_shnum (arch, e)) grub_util_error ("%s: orphaned reloc section", modname); - ts = get_shdr (arch, e, grub_target_to_host32 (s->sh_info)); + ts = get_shdr (arch, e, grub_target_to_host32 (s->sh_info), module_size); - section_check_relocations (modname, arch, e, s, grub_target_to_host (ts->sh_size)); + section_check_relocations (modname, arch, e, s, grub_target_to_host (ts->sh_size), module_size); } } @@ -474,17 +485,17 @@ SUFFIX(grub_module_verify) (const char * const filename, grub_util_error ("%s: ELF sections outside core", filename); } - check_license (filename, arch, e); + check_license (filename, arch, e, size); Elf_Shdr *s; const char *modname; - s = find_section (arch, e, ".modname"); + s = find_section (arch, e, ".modname", size); if (!s) grub_util_error ("%s: no module name found", filename); modname = (const char *) e + grub_target_to_host (s->sh_offset); - check_symbols(arch, e, modname, whitelist_empty); - check_relocations(modname, arch, e); + check_symbols(arch, e, modname, whitelist_empty, size); + check_relocations(modname, arch, e, size); } -- 2.27.0