From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nFPyC-0001CK-46 for mharc-grub-devel@gnu.org; Wed, 02 Feb 2022 19:27:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFPyA-0001A8-9G for grub-devel@gnu.org; Wed, 02 Feb 2022 19:27:26 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:32368) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFPy8-0006wx-Fc for grub-devel@gnu.org; Wed, 02 Feb 2022 19:27:26 -0500 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 212KwXWf012992 for ; Thu, 3 Feb 2022 00:27:21 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=eSDkQoyscfY+Gq03LWvxhceyF0wAHhnWssO2lT8Lg+A=; b=nlWISBSgXA4Nv2okrf/DI2BkA/QlbnqR89R3xqgQo0/3GDm471I8HCzxjTLygYE5Bl34 1SMEFMkvtD6t65fO0lvTSmR/Mq2QE6Dp6oeBjL4AZ4ytrs2p19ECihbX2rNFUahMry9Z YXP8PR7JvjIQTeX1qu50i8+bUynT/SzS1UKcA58ck0oWfDfTywXM7hmQlDNahBzOMO23 UNc/l853GhQLjDIHiEh+Y1ONjsGcs9T7dMSrgqg78QFT8sRCFUwhi4YJnGRTctW1Y9X1 jfMTYqWWug9vncyeePo1dUkotEGdqs43Lzj+fPOueYo4TuCBDHhZNpHA1pt+07CUbMo0 dQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3dxj9fysc8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Feb 2022 00:27:21 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 2130FkqO099661 for ; Thu, 3 Feb 2022 00:27:20 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam08lp2042.outbound.protection.outlook.com [104.47.73.42]) by aserp3030.oracle.com with ESMTP id 3dvumje8r8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Feb 2022 00:27:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XJrzreBhwuUsYBVfXz235Wek6ne98Sy3Ut/Qx8eE6SOgXr4aOFLl+pLfHhwyprgaJChPFn81oWvxLoMPZawTZX46qEZqtGegPDcBCCr+ay9a6xEJjGOeANQGzZQaAe7PmLg4IHxy9LrSyEv7xPqVS1BcwbSIGhWnoLEo4TNZ63g2aKczYD7DqPFDXttWbzy3G0cGkX6l3LXKmrHO4NeGc+A0qyGldNuBD1gYqQl4ErOvmOj3mbPiuIQJBqWXXcAVFmMoRhudaSS6b1TibmVqFXgdMhFcJ7RBj9Nh64VV2zJMmtW06vfkNmb0fQRFZx2EpQtv5FOswby7idTyAmAFnQ== 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=eSDkQoyscfY+Gq03LWvxhceyF0wAHhnWssO2lT8Lg+A=; b=f/nU+1eKmxArJUJCT4+VMmTWO2hfw+fHG/BivF6A5dylAVbK4F2ORjgSb/b1+khBbJQ7oRm6qlUV0vJUTmT9RyZbccIvgwxBsJ04Z9IxtI1FjucLaKWvGIj3UsN4D8KZ/GHThIGGLA8FIe+oxUsQ0qS+dtajtt4UM++z4Ql9LXLJqxZfzvC3Sax22NYFsthDekRO8qZ3Eb3kORVpB4FbtDoeLqF/3FKfb5YpGMn3AUe73aFxSmUcCTokG5khlR9JnDwt7uC3N4UZ7htnuTvbvXKy5CyEM1uIa6/O1AcLa+0nLjq55/clmBoT+g2uS8w8/hhaxB4ckB8Q048wQd4vdQ== 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=eSDkQoyscfY+Gq03LWvxhceyF0wAHhnWssO2lT8Lg+A=; b=0RQEb6DcGQeA03S051pJsoer/nAq5HjWLnKCXSbUOtbqj1iNzXEoo0IlggZI2GJKdkN/am9Tx+YqGPTreTMZ956GWdoZ4ihpBd6uuY93PSl9yc6stWTDQVQqWzHB7ShtYxgZAuSouBJ8aUkOmhLEZg7las3idDwWVL1HA+7XuqM= Received: from DM6PR10MB2986.namprd10.prod.outlook.com (2603:10b6:5:6b::26) by MW4PR10MB5884.namprd10.prod.outlook.com (2603:10b6:303:18f::12) 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:18 +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:18 +0000 From: Alec Brown To: grub-devel@gnu.org Cc: daniel.kiper@oracle.com, darren.kenny@oracle.com Subject: [PATCH 1/4] util/grub-module-verifierXX.c: Add function to calculate section headers Date: Wed, 2 Feb 2022 19:26:57 -0500 Message-Id: <1643848020-8197-2-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: BL1PR13CA0435.namprd13.prod.outlook.com (2603:10b6:208:2c3::20) 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: d3d8c56d-5596-43af-af6f-08d9e6abefa2 X-MS-TrafficTypeDiagnostic: MW4PR10MB5884:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:983; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xETB/CVK+chhsDjg6zpchGOC7ys/6gCmX9f1qVXeL1A26x04e0pXfIzF3ka2QEpTwL8xKgkP5lieKQcd5BKmnNsoIIxHAiO9mM4+DfI2lKjgYhqYhjpCABs/1y0k8552heofNYVM6scw4nXUABlfzyan+QhoLCR0WFRjr8/WMhHkTOFM8wfD5WeiLo0stb8PNxhJ4eS00JFP0PCDF7hk77txQtgesjCHVop+6iFt8VxVHTC6N2PXQ04K4lx9kQLLd+ZxKyPr15xk1cCfPxryllgjEgpNRRkfnkmPRbTzhdhLtaEeh53W/l1h/k+9C3jojB1v6N44Xgh5Mh1CPKeePaBciLl/tu7NE48MgVLaWJzFIzWXpA0khihZgr/VHiac7bNISlwNHXAIpfwHLq9j75BDMCMp1OitjucWUOIRhrYVGbmGOUmE+86zM9/G81BV823lGInEm77vwlhzY4AT7z9v0dEXmed1tbPslcv5LU+lgT2rptDZABzF2kTvNH24ZNKdFJcB0msAAaREopljxWD3uhOZ/CEI1jszbV5G8h/12COHaKLYY2VwDFTFxJumoq3Lu+qtLuY3VPTg3sRNUJhpwjRiA6Qcln/nEECJqGrm8KiCK83a1o3/53IeGJP9goML2KJmGJD2hw65N2QXeQ== 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)(36756003)(2616005)(2906002)(508600001)(38100700002)(6486002)(316002)(6916009)(8936002)(8676002)(66476007)(6666004)(6512007)(66556008)(83380400001)(186003)(26005)(4326008)(6506007)(5660300002)(107886003)(66946007)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?4WnSW6zSoinuKQq1pXJ4sw8JOn7fmF5y0OzgtiUXqMMubwsVLrNGhk1I4Wkx?= =?us-ascii?Q?hk6rRIwOPsXL3mK04rEdkMduFpasN4XDd12gFI0cHG9pkgWCZNk0HmlL09hs?= =?us-ascii?Q?LsynzOvlfXEdG6B9IUL+uyrsBV+nQRMHcfZc/MvMelpviZobX8G4qwKi+Z2L?= =?us-ascii?Q?OGRTSlcGKO9Vk5sJJE0T4+7xo19CcpjDr26FqnxT8wRAd9Z92WauUaVZEM9f?= =?us-ascii?Q?0+8wZ4usjxlNdqsDDUGl9FG1cG2NO+puwOfTKniqWRAbWysl7qIq59SCqM0S?= =?us-ascii?Q?IN56AqG2iVsikS9C9/7yHoOTWDGb4d8z+4V9ZXTzIKwinAkGDQm1RGVUdNTm?= =?us-ascii?Q?CGaZa2eTko6QzgW05kdNMuHsXrfbE3Ez8KgaMeV5SZg9lIGEukoFHI7Dd8tI?= =?us-ascii?Q?OrgrnoniHFQcL8wIsCyW9hk2w2mIUVzXL2zvCeDt66qQ0avqSreDUzZoHJ5y?= =?us-ascii?Q?eBo79cFuo9zw5z9Evb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rgH+t?= =?us-ascii?Q?udX4AjVuLU0AWsI8SlRWYEba0emhtRi7Fs7TGtocKoQuIs+yyImJj7aJfK8L?= =?us-ascii?Q?aYyXZsz4hxgsOr4eqcuWdmR3UWO9VVPfBissaJI9IgyZHpJzF9zW1fKgYJmh?= =?us-ascii?Q?AiFF9KxyhtTcHRgywo6dq9eHks/pOM2W5fdez4Kk6ywkEGPIC0Gj642VElah?= =?us-ascii?Q?d3bnXDMyScx4AS+U/1vIalhtU/3Yg+cahb/nn/L4nnDHysfdYJBTjmXhiasC?= =?us-ascii?Q?Oi3ij+mYkIjOGxJJ4SyvKp4=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d3d8c56d-5596-43af-af6f-08d9e6abefa2 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:18.5254 (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: M83v5RqA1iSnYVoBd6DXzIStp1vnvriZ4KgKXzf/zdXqtck7+oXBIKRu9ZIGjT78z+0EK55KHUYWW0o0wpiH0w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB5884 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10246 signatures=673430 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 phishscore=0 mlxscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202030000 X-Proofpoint-GUID: rqcK1KjK2ttXf8pTHX8y0ekYzpJMinvO X-Proofpoint-ORIG-GUID: rqcK1KjK2ttXf8pTHX8y0ekYzpJMinvO 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, 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:26 -0000 Added the function get_shdr() which returns the section header at a given index parameter passed into this function. This helps traverse the section header table and reduces repeated calls to lengthy equations used to obtain section headers. Note that it may look as though the argument *arch isn't being used, it's actually required in order to use the macros grub_target_to_host*(x) which are unwinded to grub_target_to_host*_real(arch, (x)) based on defines earlier in the file. Signed-off-by: Alec Brown --- util/grub-module-verifierXX.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c index ceb24309a..92f9ae2a4 100644 --- a/util/grub-module-verifierXX.c +++ b/util/grub-module-verifierXX.c @@ -131,6 +131,12 @@ grub_target_to_host_real (const struct grub_module_verifier_arch *arch, grub_uin return grub_target_to_host32_real (arch, in); } +static Elf_Shdr * +get_shdr (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, Elf_Word index) +{ + return (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff) + + index * grub_target_to_host16 (e->e_shentsize)); +} static Elf_Shdr * find_section (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const char *name) @@ -139,12 +145,12 @@ find_section (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const c const char *str; unsigned i; - s = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff) + grub_target_to_host16 (e->e_shstrndx) * grub_target_to_host16 (e->e_shentsize)); + s = get_shdr (arch, e, grub_target_to_host16 (e->e_shstrndx)); str = (char *) e + grub_target_to_host (s->sh_offset); - for (i = 0, s = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff)); + for (i = 0, s = get_shdr (arch, e, 0); i < grub_target_to_host16 (e->e_shnum); - i++, s = (Elf_Shdr *) ((char *) s + grub_target_to_host16 (e->e_shentsize))) + i++, s = get_shdr (arch, e, i)) if (strcmp (str + grub_target_to_host32 (s->sh_name), name) == 0) return s; return NULL; @@ -166,13 +172,12 @@ static Elf_Sym * get_symtab (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, Elf_Word *size, Elf_Word *entsize) { unsigned i; - Elf_Shdr *s, *sections; + Elf_Shdr *s; Elf_Sym *sym; - sections = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff)); - for (i = 0, s = sections; + for (i = 0, s = get_shdr (arch, e, 0); i < grub_target_to_host16 (e->e_shnum); - i++, s = (Elf_Shdr *) ((char *) s + grub_target_to_host16 (e->e_shentsize))) + i++, s = get_shdr (arch, e, i)) if (grub_target_to_host32 (s->sh_type) == SHT_SYMTAB) break; @@ -364,9 +369,9 @@ check_relocations (const char * const modname, Elf_Shdr *s; unsigned i; - for (i = 0, s = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff)); + for (i = 0, s = get_shdr (arch, e, 0); i < grub_target_to_host16 (e->e_shnum); - i++, s = (Elf_Shdr *) ((char *) s + grub_target_to_host16 (e->e_shentsize))) + i++, s = get_shdr (arch, e, i)) if (grub_target_to_host32 (s->sh_type) == SHT_REL || grub_target_to_host32 (s->sh_type) == SHT_RELA) { Elf_Shdr *ts; @@ -379,7 +384,7 @@ check_relocations (const char * const modname, /* Find the target segment. */ if (grub_target_to_host32 (s->sh_info) >= grub_target_to_host16 (e->e_shnum)) grub_util_error ("%s: orphaned reloc section", modname); - ts = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff) + grub_target_to_host32 (s->sh_info) * grub_target_to_host16 (e->e_shentsize)); + ts = get_shdr (arch, e, grub_target_to_host32 (s->sh_info)); section_check_relocations (modname, arch, e, s, grub_target_to_host (ts->sh_size)); } -- 2.27.0