From nobody Mon Feb 9 07:20:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+102492+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+102492+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1680622838; cv=none; d=zohomail.com; s=zohoarc; b=De7vF267Dv6oJ2rgdGazAabtjF758H5XoZrrkB3nfwG/Fo69V0oJ6QzpG8Q59tT3ZasR4zS+1GC0XZrimrxcYWw4Xktz6uBGbGoBaWzDHUsqYykOkbvrEC4hXJWx1IyCIU7sS2VutLNRh3tRBEb2EEKXcixJYvcwNcAWuDsjl+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680622838; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=6Go4jb/0+r6PdheCrR9RwY9ruGDaFVqgALv3YtnZ0wE=; b=Gt3C+bajT+3QRDv4dJVsrwinvbe/pT5/eN7K5lARGdYGCdMxnxK9ysB1Bp1ImpWcI6vfaDV1wo48cdNQILjf3md2pAhLyEwjtCOxX008M28hmRyur6iMrm3g108ljr00ouTOewHzY4QK+w9KipG0OuHenLuKuX4ENqXu2AgigIs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+102492+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1680622838319447.0426515859866; Tue, 4 Apr 2023 08:40:38 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FayRYY1788612x3NoCgzePL4; Tue, 04 Apr 2023 08:40:37 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.105355.1680622837370587779 for ; Tue, 04 Apr 2023 08:40:37 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B6A1A6361E; Tue, 4 Apr 2023 15:40:36 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F311C433D2; Tue, 4 Apr 2023 15:40:33 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Michael Kinney , Liming Gao , Jiewen Yao , Michael Kubacki , Sean Brogan , Rebecca Cran , Leif Lindholm , Sami Mujawar , Taylor Beebe , =?UTF-8?q?Marvin=20H=C3=A4user?= , Bob Feng , Oliver Smith-Denny Subject: [edk2-devel] [PATCH v3 1/4] BaseTools/GenFw: Parse IBT/BTI support status from ELF note Date: Tue, 4 Apr 2023 17:40:19 +0200 Message-Id: <20230404154022.2776035-2-ardb@kernel.org> In-Reply-To: <20230404154022.2776035-1-ardb@kernel.org> References: <20230404154022.2776035-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ardb@kernel.org X-Gm-Message-State: Mq31R4ZHxWlStpqgjGTtKN9Mx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680622837; bh=TXsVHOeqjg0znHfYEmVo2i6i+VzwIM4e46N1jS1tvaQ=; h=Cc:Date:From:Reply-To:Subject:To; b=FsiiflXNFISX2Mir0PkjN6UGzK/fCTo9be9u3tlOpI7VFcVQ0YOmw+2n/weBuNSJnce R98mLAGqBarBz2CdLW/XXd8rVvR3SyrTwNMjeSH+2JExCLtayfLg7wqnyTYH1HLssIcmJ pyvEOG/KaDFnspJOteS8A2b6h4hfNXSux2I= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680622838691100005 Content-Type: text/plain; charset="utf-8" When performing ELF to PE/COFF conversion, parse any notes sections to decide whether the image supports forward CFI landing pads. This will be used to set the associated DllCharacteristicsEx flag in a subsequent patch. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny Acked-by: Michael Kubacki --- BaseTools/Source/C/GenFw/Elf64Convert.c | 50 ++++++++++++++++++++ BaseTools/Source/C/GenFw/elf_common.h | 9 ++++ 2 files changed, 59 insertions(+) diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/G= enFw/Elf64Convert.c index 8b50774beb1eebda..2a810e835d4a4a66 100644 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -770,6 +770,49 @@ WriteSectionRiscV64 ( } } =20 +STATIC UINT16 mDllCharacteristicsEx; + +STATIC +VOID +ParseNoteSection ( + CONST Elf_Shdr *Shdr + ) +{ + CONST Elf_Note *Note; + CONST UINT32 *Prop; + UINT32 Prop0; + UINT32 Prop2; + + Note =3D (Elf_Note *)((UINT8 *)mEhdr + Shdr->sh_offset); + + if ((Note->n_type =3D=3D NT_GNU_PROPERTY_TYPE_0) && + (Note->n_namesz =3D=3D sizeof ("GNU")) && + (strcmp ((CHAR8 *)(Note + 1), "GNU") =3D=3D 0) && + (Note->n_descsz > sizeof (UINT32[2]))) { + Prop =3D (UINT32 *)((UINT8 *)(Note + 1) + sizeof("GNU")); + + switch (mEhdr->e_machine) { + case EM_AARCH64: + Prop0 =3D GNU_PROPERTY_AARCH64_FEATURE_1_AND; + Prop2 =3D GNU_PROPERTY_AARCH64_FEATURE_1_BTI; + break; + + case EM_X86_64: + Prop0 =3D GNU_PROPERTY_X86_FEATURE_1_AND; + Prop2 =3D GNU_PROPERTY_X86_FEATURE_1_IBT; + break; + + default: + return; + } + if ((Prop[0] =3D=3D Prop0) && + (Prop[1] >=3D sizeof (UINT32)) && + ((Prop[2] & Prop2) !=3D 0)) { + mDllCharacteristicsEx |=3D EFI_IMAGE_DLLCHARACTERISTICS_EX_FORWARD_C= FI_COMPAT; + } + } +} + // // Elf functions interface implementation // @@ -826,6 +869,13 @@ ScanSections64 ( } } =20 + for (i =3D 0; i < mEhdr->e_shnum; i++) { + Elf_Shdr *shdr =3D GetShdrByIndex(i); + if (shdr->sh_type =3D=3D SHT_NOTE) { + ParseNoteSection (shdr); + } + } + // // Check if mCoffAlignment is larger than MAX_COFF_ALIGNMENT // diff --git a/BaseTools/Source/C/GenFw/elf_common.h b/BaseTools/Source/C/Gen= Fw/elf_common.h index 7b7fdeb3290dfa88..ccd32804b090a226 100644 --- a/BaseTools/Source/C/GenFw/elf_common.h +++ b/BaseTools/Source/C/GenFw/elf_common.h @@ -59,6 +59,15 @@ typedef struct { UINT32 n_type; /* Type of this note. */ } Elf_Note; =20 +#define NT_GNU_PROPERTY_TYPE_0 5 + +#define GNU_PROPERTY_X86_FEATURE_1_AND 0xc0000002 +#define GNU_PROPERTY_X86_FEATURE_1_IBT 0x1 + +#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 +#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI 0x1 +#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC 0x2 + /* Indexes into the e_ident array. Keep synced with http://www.sco.com/developers/gabi/latest/ch4.eheader.html */ #define EI_MAG0 0 /* Magic number, byte 0. */ --=20 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#102492): https://edk2.groups.io/g/devel/message/102492 Mute This Topic: https://groups.io/mt/98062731/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-