From nobody Fri Apr 26 06:50:03 2024 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+101925+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+101925+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914897; cv=none; d=zohomail.com; s=zohoarc; b=Pheqjp39XBqFMQurytgho0CI4suExTHCHjKO5M0nUj9OBk0MiCN8SyPO6KxOOIKZseL3dxjLUxcLOoC3W4Ben0HA3PcW/qN3gJVPq5X3/k7mm7phXN6AyxRpAxu0zJ46sw2hObhj8B221kWMGsKQBzGPsRw6v6LJkjOHWpKAMLU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914897; 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=QJqD/LzCGuO5UMb5oHBz8T9wTvUp3Db22pLGh8DAcnY=; b=n3o2JXR4IQ9mqTcqGsoFI2gY2YMF1G/DNYQ5zz3sC5MZ60w1W983cmH2tKhda/tFKPHFTeMQ/jpddZaOqxJGI4OOXNvSEvwExMZIYkzZgfgYaQZyAR7vtE0GmFSVz6UIkezwK36Yz4t93718JUtsuV8Y6WtkoQepCxHZ79+rSyo= 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+101925+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 1679914897211884.1323336476394; Mon, 27 Mar 2023 04:01:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id DFF2YY1788612xoltKk6Oqva; Mon, 27 Mar 2023 04:01:36 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.31886.1679914896025099230 for ; Mon, 27 Mar 2023 04:01:36 -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 8E25861043; Mon, 27 Mar 2023 11:01:35 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73019C433D2; Mon, 27 Mar 2023 11:01:32 +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 Subject: [edk2-devel] [PATCH v2 01/17] MdePkg/ProcessorBind AARCH64: Add asm macro to emit GNU BTI note Date: Mon, 27 Mar 2023 13:00:56 +0200 Message-Id: <20230327110112.262503-2-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: TpbPxUlWUupo9thU6WQuJBXhx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914896; bh=mi1+2vcKNJL4z9FIfkKkTx85NaXVtnP9cOUb6Grjxdg=; h=Cc:Date:From:Reply-To:Subject:To; b=N5WodeSQDePNIy1e9xKIrlc5kCUgjy5euMJjJx2rp6krspriOdL6Ii0LW54tWH5vGCz diWiSPxp9m0wWWit8noYaqPGta4c7bQO36/o4yH4mxvjfNpwJjcwlFKIdu15UMfzy7v84 rAnmoi+yC6AFqJfPXnxPYs8Fjwq7Nv8/MUQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914899115100002 Content-Type: text/plain; charset="utf-8" Implement a CPP macro that can be called from .S files to emit the .note section carrying the annotation that informs the linker that the object file is compatible with BTI control flow integrity checks. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- MdePkg/Include/AArch64/ProcessorBind.h | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/MdePkg/Include/AArch64/ProcessorBind.h b/MdePkg/Include/AArch6= 4/ProcessorBind.h index abe2571245c665f3..11814f1ffaef698a 100644 --- a/MdePkg/Include/AArch64/ProcessorBind.h +++ b/MdePkg/Include/AArch64/ProcessorBind.h @@ -186,6 +186,37 @@ typedef INT64 INTN; #define GCC_ASM_IMPORT(func__) \ .extern _CONCATENATE (__USER_LABEL_PREFIX__, func__) =20 +#if defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT =3D=3D= 1 +#define AARCH64_BTI(__type) \ + .ifnc __type, ;\ + bti __type ;\ + .endif ;\ + .ifndef .Lgnu_bti_notesize ;\ + .pushsection .note.gnu.property, "a" ;\ + .set NT_GNU_PROPERTY_TYPE_0, 0x5 ;\ + .set GNU_PROPERTY_AARCH64_FEATURE_1_AND, 0xc0000000 ;\ + .set GNU_PROPERTY_AARCH64_FEATURE_1_BTI, 0x1 ;\ + .align 3 ;\ + .long .Lnamesize ;\ + .long .Lgnu_bti_notesize ;\ + .long NT_GNU_PROPERTY_TYPE_0 ;\ +0: .asciz "GNU" ;\ + .set .Lnamesize, . - 0b ;\ + .align 3 ;\ +1: .long GNU_PROPERTY_AARCH64_FEATURE_1_AND ;\ + .long .Lvalsize ;\ +2: .long GNU_PROPERTY_AARCH64_FEATURE_1_BTI ;\ + .set .Lvalsize, . - 2b ;\ + .align 3 ;\ + .set .Lgnu_bti_notesize, . - 1b ;\ + .popsection ;\ + .endif +#endif + +#endif + +#ifndef AARCH64_BTI +#define AARCH64_BTI(__type) #endif =20 /** --=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 (#101925): https://edk2.groups.io/g/devel/message/101925 Mute This Topic: https://groups.io/mt/97879282/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- From nobody Fri Apr 26 06:50:03 2024 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+101926+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+101926+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914902; cv=none; d=zohomail.com; s=zohoarc; b=X8b37ADSW9HB1kaG6EtNYBsA7BvXTS9CxY9E6M1xX/GrQ6N0Rm/rgh1xq18wFLEVZM/k9EgV5c8rsmxplr65HVbZBVCUsN7d4OVzp7q+GYCvEbT4uD0srAylqFcKG7DKLxbZQeE/z4TPtmojq5Jgk2o14ol/68g+AtB4q1nBHb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914902; 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=iR3wUS2LuzXESlgM/feeYDND87rZwrxgtIp1QOyuiLg=; b=MPOGGT4nCISU/hZqn+Wj+YxQzpNiXXl0wNHE5xj0I0Fs2Kj16jtoyhZmf7wjj6nKCScGVeEKl7gaPf8qcGCOqmY/o2dMTMf2myp5SdnNpEOs4teBXQN/XbJfVU1toRDvV3rx+cveM3/rENHJVU+4+sFZHSbK4iA9H9GJPOrhJXk= 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+101926+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 1679914902819990.3534866834101; Mon, 27 Mar 2023 04:01:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id yTrUYY1788612xwIZtqsrnWH; Mon, 27 Mar 2023 04:01:42 -0700 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web11.32009.1679914901399619742 for ; Mon, 27 Mar 2023 04:01:41 -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 ams.source.kernel.org (Postfix) with ESMTPS id 2F728B80DA9; Mon, 27 Mar 2023 11:01:39 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67FC0C433A4; Mon, 27 Mar 2023 11:01:35 +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 Subject: [edk2-devel] [PATCH v2 02/17] MdePkg/BaseCpuLib AARCH64: Make asm files BTI compatible Date: Mon, 27 Mar 2023 13:00:57 +0200 Message-Id: <20230327110112.262503-3-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: 8eROA2NqmQHW1dBVdo5DlC26x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914902; bh=8FR4hsLOi4vnU/G92mYtB9X877i/AL8rmbIhN7i6W0c=; h=Cc:Date:From:Reply-To:Subject:To; b=kqNBr+lU28gOBoQKFjcWBLy+xTLE+QY6RCL11pc4+6T/Wm8FK8Ri9XF8vS6deDGEmfK nbfr7AoennsntEAlK/PqaEM1Q6/pL5QEsYH9fOY7fk/IlPbgnfWaPx8MdswiNSyR/meX9 MyiBotB3mekmhVbWZ35vobeW3UTuyzBNOy8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914903154100002 Content-Type: text/plain; charset="utf-8" Add the BTI instructions and the associated note to make the AArch64 asm objects compatible with BTI enforcement. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- MdePkg/Library/BaseCpuLib/AArch64/CpuFlushTlb.S | 1 + MdePkg/Library/BaseCpuLib/AArch64/CpuSleep.S | 1 + 2 files changed, 2 insertions(+) diff --git a/MdePkg/Library/BaseCpuLib/AArch64/CpuFlushTlb.S b/MdePkg/Libra= ry/BaseCpuLib/AArch64/CpuFlushTlb.S index 82a7232268f59809..12c2421b6d327a7b 100644 --- a/MdePkg/Library/BaseCpuLib/AArch64/CpuFlushTlb.S +++ b/MdePkg/Library/BaseCpuLib/AArch64/CpuFlushTlb.S @@ -26,6 +26,7 @@ GCC_ASM_EXPORT(CpuFlushTlb) # )# # ASM_PFX(CpuFlushTlb): + AARCH64_BTI(c) tlbi vmalle1 // Invalidate Inst TLB and Data TLB dsb sy isb diff --git a/MdePkg/Library/BaseCpuLib/AArch64/CpuSleep.S b/MdePkg/Library/= BaseCpuLib/AArch64/CpuSleep.S index 410a271565edfb68..6853e0c56e0bb135 100644 --- a/MdePkg/Library/BaseCpuLib/AArch64/CpuSleep.S +++ b/MdePkg/Library/BaseCpuLib/AArch64/CpuSleep.S @@ -29,5 +29,6 @@ GCC_ASM_EXPORT(CpuSleep) # =20 ASM_PFX(CpuSleep): + AARCH64_BTI(c) wfi ret --=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 (#101926): https://edk2.groups.io/g/devel/message/101926 Mute This Topic: https://groups.io/mt/97879283/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- From nobody Fri Apr 26 06:50:03 2024 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+101927+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+101927+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914909; cv=none; d=zohomail.com; s=zohoarc; b=aCLssnMmKfDDmcIBi1L1pjwZCsq3EnniEUwz5QyzpDIb7YQyqQpISKE6QXgpjhKaGmEQeZP7nr1Q1cFkfVgrcSdKqdqq6FKEnZFA0VJSt8FnZG6jUpe+H4IQQz+1xVEFpIafETjezxoHlzORUO15I2ToE89P4gE57YKStSLqbJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914909; 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=0C/8DW+i7VgQ/4tBdhiICVltOsOG42cLNuO71zDeymg=; b=HVW8IxkzccTKuSIRBIRtbbNfaOLjqmANcdLdHq2dlwG9HFJVL8TQb2XJ9TG7fTjxi6uSyRR/QwIxnVpyB6KaN3TRg4YPjyy3M3yojde4mDpFDVZuNtKJQneSFJk1tsu5TGtAyI+pdSR4kSoe4vTp9uoRVkCj0kbKmTu1H0TFfYk= 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+101927+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 1679914909277374.19745520453534; Mon, 27 Mar 2023 04:01:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id f7S1YY1788612xtMwqsUd06k; Mon, 27 Mar 2023 04:01:48 -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.32012.1679914902986054583 for ; Mon, 27 Mar 2023 04:01:43 -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 678E2611AF; Mon, 27 Mar 2023 11:01:42 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5BE8AC433EF; Mon, 27 Mar 2023 11:01:38 +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 Subject: [edk2-devel] [PATCH v2 03/17] MdePkg/BaseIoLibIntrinsic AARCH64: Make asm files BTI compatible Date: Mon, 27 Mar 2023 13:00:58 +0200 Message-Id: <20230327110112.262503-4-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: liezaw1JyO0caF3LmfInIzZcx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914908; bh=sXkY72Y+CsxE0DwWmJRs2582kkqnmkr8RvK5nnIUtw8=; h=Cc:Date:From:Reply-To:Subject:To; b=rA4GFkfhCYHkyKtR5zvTRZKFbyyc7PiJ8AXpgH5iaPSXg/nvuFrcPoHAj3iFujvbb1w RlDS/EJPJA/hUX+zZvTNUJHsR2iWTXmjSjeGH1JOiRTPwETxdImYWrOmh9MdbfG8OoQP2 wreZb1u9jj2tHpchZ4/e87Xi5T514TvqKoc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914911178100015 Content-Type: text/plain; charset="utf-8" Add the BTI instructions and the associated note to make the AArch64 asm objects compatible with BTI enforcement. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- ArmVirtPkg/Library/ArmPlatformLibQemu/IdMap.S | 2 ++ MdePkg/Library/BaseIoLibIntrinsic/AArch64/ArmVirtMmio.S | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/ArmVirtPkg/Library/ArmPlatformLibQemu/IdMap.S b/ArmVirtPkg/Lib= rary/ArmPlatformLibQemu/IdMap.S index 584ffcb3ebe2ef34..b67f09ab61f2474e 100644 --- a/ArmVirtPkg/Library/ArmPlatformLibQemu/IdMap.S +++ b/ArmVirtPkg/Library/ArmPlatformLibQemu/IdMap.S @@ -57,3 +57,5 @@ idmap: /* level 0 */ .quad PAGE_XIP | (idx << 12) // 2044 KiB of R-X flash mappings .set idx, idx + 1 .endr + +AARCH64_BTI() diff --git a/MdePkg/Library/BaseIoLibIntrinsic/AArch64/ArmVirtMmio.S b/MdeP= kg/Library/BaseIoLibIntrinsic/AArch64/ArmVirtMmio.S index 00f1abec15f0ef08..77f562697ef971b5 100644 --- a/MdePkg/Library/BaseIoLibIntrinsic/AArch64/ArmVirtMmio.S +++ b/MdePkg/Library/BaseIoLibIntrinsic/AArch64/ArmVirtMmio.S @@ -29,6 +29,7 @@ GCC_ASM_EXPORT(MmioWrite64Internal) // @return The value read. // ASM_PFX(MmioRead8Internal): + AARCH64_BTI(c) ldrb w0, [x0] dmb ld ret @@ -44,6 +45,7 @@ ASM_PFX(MmioRead8Internal): // @param Value The value to write to the MMIO register. // ASM_PFX(MmioWrite8Internal): + AARCH64_BTI(c) dmb st strb w1, [x0] ret @@ -60,6 +62,7 @@ ASM_PFX(MmioWrite8Internal): // @return The value read. // ASM_PFX(MmioRead16Internal): + AARCH64_BTI(c) ldrh w0, [x0] dmb ld ret @@ -75,6 +78,7 @@ ASM_PFX(MmioRead16Internal): // @param Value The value to write to the MMIO register. // ASM_PFX(MmioWrite16Internal): + AARCH64_BTI(c) dmb st strh w1, [x0] ret @@ -91,6 +95,7 @@ ASM_PFX(MmioWrite16Internal): // @return The value read. // ASM_PFX(MmioRead32Internal): + AARCH64_BTI(c) ldr w0, [x0] dmb ld ret @@ -106,6 +111,7 @@ ASM_PFX(MmioRead32Internal): // @param Value The value to write to the MMIO register. // ASM_PFX(MmioWrite32Internal): + AARCH64_BTI(c) dmb st str w1, [x0] ret @@ -122,6 +128,7 @@ ASM_PFX(MmioWrite32Internal): // @return The value read. // ASM_PFX(MmioRead64Internal): + AARCH64_BTI(c) ldr x0, [x0] dmb ld ret @@ -137,6 +144,7 @@ ASM_PFX(MmioRead64Internal): // @param Value The value to write to the MMIO register. // ASM_PFX(MmioWrite64Internal): + AARCH64_BTI(c) dmb st str x1, [x0] ret --=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 (#101927): https://edk2.groups.io/g/devel/message/101927 Mute This Topic: https://groups.io/mt/97879284/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- From nobody Fri Apr 26 06:50:03 2024 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+101928+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+101928+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914906; cv=none; d=zohomail.com; s=zohoarc; b=etGl6iMX2UrlkKCSuTtJ6hedLSbE3pHbxwCI2goSMbvtpRBQzrwcukPup0y/W0V1r7Sb8WBHk65eJKgZ2oguvdCZ1nW/qJ+PbmKX9cxP1Dw2Do0lvol9FC7JyT518Cu2k6dfKoTt+aPMJe7rsCKEt6S8P7NpdUNKzO7DdtNIUz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914906; 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=a1k2J028px+6grIFiumXecvP/5Y+JeYzbqo6sOTfZ2c=; b=BQ7ekT8O/7Do6xr7G8t2DGKLYmTZ1qX/QOnpCLRYyQfE+n4mq+l29EwPo7IaRc0kNu9REpdSKb/xVrlPEJeyIPafwtosmouuNd185nntnM+IMG9+mMDp3xTzj533cBmvhKglLMaobQTmST743hqeorWEU/1nPjFn0injXYV1LMA= 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+101928+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 1679914906181324.0145710285526; Mon, 27 Mar 2023 04:01:46 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id C7veYY1788612xD5tv3bxMAf; Mon, 27 Mar 2023 04:01:45 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.31889.1679914904893707799 for ; Mon, 27 Mar 2023 04:01:44 -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 69B14611B0; Mon, 27 Mar 2023 11:01:44 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 506E7C4339E; Mon, 27 Mar 2023 11:01:41 +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 Subject: [edk2-devel] [PATCH v2 04/17] MdePkg/BaseLib AARCH64: Make LongJump() BTI compatible Date: Mon, 27 Mar 2023 13:00:59 +0200 Message-Id: <20230327110112.262503-5-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: EGpY9hO1iJF8tuWc366lXuzMx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914905; bh=x6xVYrE6HehKh1MLb+KQjmLBDJsI8JfuhmWnLAQIV2U=; h=Cc:Date:From:Reply-To:Subject:To; b=WytrC6KKFq5ZzrLNqTiJig/hEfw8T1kjhQbD9YZ0RZYQ48V+aXp+nt5QrZV5wH71qmA V+7J01ExLGJCDotdPz7Qef8wPOfbEZqHQluT+iTQOeYAREeCyMFa2Hl6wiY5ddBOlkIL8 GdVBDpG8pm+raItBttYKIstqNdw6YPouxFQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914907155100008 Content-Type: text/plain; charset="utf-8" Currently, the AArch64 implementation of LongJump() avoids using the RET instruction to perform the jump, even though the target address is held in the link register X30, as the nature of a long jump implies that the ordinary return address prediction machinery will not be able to make a correct prediction. However, LongJump() is rarely used, and the return stack will be out of sync in any case, so this optimization has little value in practice, and given that indirect calls other than function returns require a BTI landing pad at the call site, this optimization is not compatible with BTI. So let's just use RET instead. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S b/MdePkg/Libr= ary/BaseLib/AArch64/SetJumpLongJump.S index deefdf526b95ca93..1d5cfbf64470452f 100644 --- a/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S +++ b/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S @@ -85,7 +85,6 @@ ASM_PFX(InternalLongJump): cmp w1, #0 mov w0, #1 csel w0, w1, w0, ne - // use br not ret, as ret is guaranteed to mispredict - br x30 + ret =20 ASM_FUNCTION_REMOVE_IF_UNREFERENCED --=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 (#101928): https://edk2.groups.io/g/devel/message/101928 Mute This Topic: https://groups.io/mt/97879285/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- From nobody Fri Apr 26 06:50:03 2024 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+101929+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+101929+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914908; cv=none; d=zohomail.com; s=zohoarc; b=D45yx2E6fVrGTIvw+s7TlDhC6lB77hlPdoX5U7hF8/w94YQjp8dAoDkGap0NMQUxjNzPC0nSDd5si/gJAcmamwxTTK5CM6C1BYjfxFGnWCNO8b1U8J6/SUhbs78tfLKuKrCDno4fUKReHwqht859F4IB8TN9HvLGBIX21PGrsJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914908; 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=K3n77F0dAP/8W+Z4wJbYDyV/ofOWhU5kttbOVtT+dUc=; b=L47QTN9TS38ZOCcnB3YdzQLjJss/iSpPHt/Bco1rSt9LI9o8i/WMLJKMFE8ZDPIh+BE7/lRl/Q7WC0X1bz/9h7JuUzVre87sZUPp9onV/3UYXYAdtseo0G9nf2w2o6pSKJVOORNEKL2tne4kyTJoRk5I/RXdQ3KGyQpsmuN0ixQ= 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+101929+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 1679914908845601.7546154947457; Mon, 27 Mar 2023 04:01:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id lszvYY1788612x4gw5kSJ2ue; Mon, 27 Mar 2023 04:01:48 -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.32014.1679914907814396823 for ; Mon, 27 Mar 2023 04:01:47 -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 5DF1C611A9; Mon, 27 Mar 2023 11:01:47 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44983C4339C; Mon, 27 Mar 2023 11:01:44 +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 Subject: [edk2-devel] [PATCH v2 05/17] MdePkg/BaseLib AARCH64: Make asm files BTI compatible Date: Mon, 27 Mar 2023 13:01:00 +0200 Message-Id: <20230327110112.262503-6-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: J4fgwfH41q6LReggfHlEYKTAx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914908; bh=GhIfg2JaLZ4KYbExDISX9/XFmtQX7UnCLJFVpAVpbfE=; h=Cc:Date:From:Reply-To:Subject:To; b=TfHCpiCxJ2yR02yMGoU8CFJaHRmcuktVl903kgTFRuPCMjE0FYu9IkLew36h3eQj7LS P3s586Q7Axb/3LkGd5JW68UdddNf1dsAmYRN0xCOwan9ZUpP2/ic7ELfRfjonhGjRlMQh Z3929pO6fyVOCA5pbiEhcc72wacN0ePWlEI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914909195100011 Content-Type: text/plain; charset="utf-8" Add the BTI instructions and the associated note to make the AArch64 asm objects compatible with BTI enforcement. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- MdePkg/Library/BaseLib/AArch64/CpuBreakpoint.S | 1 + MdePkg/Library/BaseLib/AArch64/DisableInterrupts.S | 1 + MdePkg/Library/BaseLib/AArch64/EnableInterrupts.S | 1 + MdePkg/Library/BaseLib/AArch64/GetInterruptsState.S | 1 + MdePkg/Library/BaseLib/AArch64/MemoryFence.S | 1 + MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S | 2 ++ MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.S | 1 + MdePkg/Library/BaseLib/AArch64/SwitchStack.S | 2 ++ 8 files changed, 10 insertions(+) diff --git a/MdePkg/Library/BaseLib/AArch64/CpuBreakpoint.S b/MdePkg/Librar= y/BaseLib/AArch64/CpuBreakpoint.S index 7524fb18820c2fa3..24a1ac371884bb1d 100644 --- a/MdePkg/Library/BaseLib/AArch64/CpuBreakpoint.S +++ b/MdePkg/Library/BaseLib/AArch64/CpuBreakpoint.S @@ -27,5 +27,6 @@ GCC_ASM_EXPORT(CpuBreakpoint) # ); # ASM_PFX(CpuBreakpoint): + AARCH64_BTI(c) svc 0xdbdb // Superviser exception. Takes 16bit arg -> Armv7 had = 'swi' here. ret diff --git a/MdePkg/Library/BaseLib/AArch64/DisableInterrupts.S b/MdePkg/Li= brary/BaseLib/AArch64/DisableInterrupts.S index f0faf16b06a3fcae..3f562461614ad294 100644 --- a/MdePkg/Library/BaseLib/AArch64/DisableInterrupts.S +++ b/MdePkg/Library/BaseLib/AArch64/DisableInterrupts.S @@ -26,5 +26,6 @@ GCC_ASM_EXPORT(DisableInterrupts) # ); # ASM_PFX(DisableInterrupts): + AARCH64_BTI(c) msr daifset, #DAIF_WR_IRQ_BIT ret diff --git a/MdePkg/Library/BaseLib/AArch64/EnableInterrupts.S b/MdePkg/Lib= rary/BaseLib/AArch64/EnableInterrupts.S index 97eeb13fbe5d2145..0f1377f51c7e88f7 100644 --- a/MdePkg/Library/BaseLib/AArch64/EnableInterrupts.S +++ b/MdePkg/Library/BaseLib/AArch64/EnableInterrupts.S @@ -26,5 +26,6 @@ GCC_ASM_EXPORT(EnableInterrupts) # ); # ASM_PFX(EnableInterrupts): + AARCH64_BTI(c) msr daifclr, #DAIF_WR_IRQ_BIT ret diff --git a/MdePkg/Library/BaseLib/AArch64/GetInterruptsState.S b/MdePkg/L= ibrary/BaseLib/AArch64/GetInterruptsState.S index bf8b829bb2b1749d..26787a5b9bddcd7e 100644 --- a/MdePkg/Library/BaseLib/AArch64/GetInterruptsState.S +++ b/MdePkg/Library/BaseLib/AArch64/GetInterruptsState.S @@ -33,6 +33,7 @@ GCC_ASM_EXPORT(GetInterruptState) # ); # ASM_PFX(GetInterruptState): + AARCH64_BTI(c) mrs x0, daif tst x0, #DAIF_RD_IRQ_BIT // Check IRQ mask; set Z=3D1 if clear/un= masked cset w0, eq // if Z=3D1 (eq) return 1, else 0 diff --git a/MdePkg/Library/BaseLib/AArch64/MemoryFence.S b/MdePkg/Library/= BaseLib/AArch64/MemoryFence.S index e553bd2dc9fcf63f..ad5b92a9a72bd65c 100644 --- a/MdePkg/Library/BaseLib/AArch64/MemoryFence.S +++ b/MdePkg/Library/BaseLib/AArch64/MemoryFence.S @@ -28,6 +28,7 @@ GCC_ASM_EXPORT(MemoryFence) # ); # ASM_PFX(MemoryFence): + AARCH64_BTI(c) // System wide Data Memory Barrier. dmb sy ret diff --git a/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S b/MdePkg/Libr= ary/BaseLib/AArch64/SetJumpLongJump.S index 1d5cfbf64470452f..0d902d94d31c4a35 100644 --- a/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S +++ b/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S @@ -46,6 +46,7 @@ GCC_ASM_EXPORT(InternalLongJump) # ); # ASM_PFX(SetJump): + AARCH64_BTI(c) mov x16, sp // use IP0 so save SP #define REG_PAIR(REG1, REG2, OFFS) stp REG1, REG2, [x0, OFFS] #define REG_ONE(REG1, OFFS) str REG1, [x0, OFFS] @@ -75,6 +76,7 @@ ASM_PFX(SetJump): # ); # ASM_PFX(InternalLongJump): + AARCH64_BTI(c) #define REG_PAIR(REG1, REG2, OFFS) ldp REG1, REG2, [x0, OFFS] #define REG_ONE(REG1, OFFS) ldr REG1, [x0, OFFS] GPR_LAYOUT diff --git a/MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.S b/MdePkg/L= ibrary/BaseLib/AArch64/SpeculationBarrier.S index a20d6aed0cdd5284..248ee01e52c27367 100644 --- a/MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.S +++ b/MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.S @@ -28,6 +28,7 @@ GCC_ASM_EXPORT(SpeculationBarrier) # ); # ASM_PFX(SpeculationBarrier): + AARCH64_BTI(c) dsb sy isb ret diff --git a/MdePkg/Library/BaseLib/AArch64/SwitchStack.S b/MdePkg/Library/= BaseLib/AArch64/SwitchStack.S index f3bce6a09bc2d555..837c65b45e73024e 100644 --- a/MdePkg/Library/BaseLib/AArch64/SwitchStack.S +++ b/MdePkg/Library/BaseLib/AArch64/SwitchStack.S @@ -35,6 +35,7 @@ GCC_ASM_EXPORT(CpuPause) # ); # ASM_PFX(InternalSwitchStackAsm): + AARCH64_BTI(c) mov x29, #0 mov x30, x0 mov sp, x3 @@ -57,6 +58,7 @@ ASM_PFX(InternalSwitchStackAsm): # ) # ASM_PFX(CpuPause): + AARCH64_BTI(c) nop nop nop --=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 (#101929): https://edk2.groups.io/g/devel/message/101929 Mute This Topic: https://groups.io/mt/97879286/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- From nobody Fri Apr 26 06:50:03 2024 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+101930+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+101930+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914911; cv=none; d=zohomail.com; s=zohoarc; b=kWtPnRuW0i+MM9U0DQBoWCn1qg00e3tt3mRo+vvCZySw55YJ7iumFHSI+wU9k4/FVG7MOSNdG/DPHkzUscStbKI/SuVzXIcyoWhag9YW8JTlSDZwJRF11T/IzevmaAblcyJ1ZU26uVTjFXAzqbQLAgDUA1dZkZrAZV0P9APoTuk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914911; 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=mc7Py0ZGyC3vl/j4H5L3hfvy+dmlUbua6WdxTB55htc=; b=K7vL1Vb0D59XYieQ1TPIjtqI62c5NlVfXXo83IETSZcB4awVIffXwnnBnHvo6gf8DkWfbV67LCnWGWgB4g2fm4h1Pq0ggsil6lom7OKdPr4LoOd0SRVAzCEMHi6v+87KU1wg4Cao3q4Yu7MFf9PJ5dX/rIMz8w573fll6jIhcUg= 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+101930+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 1679914911715243.86607274016183; Mon, 27 Mar 2023 04:01:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id RA2bYY1788612xkzQL4ahQIS; Mon, 27 Mar 2023 04:01:51 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.31890.1679914910783170318 for ; Mon, 27 Mar 2023 04:01:50 -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 4E749611B1; Mon, 27 Mar 2023 11:01:50 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38D4FC433A1; Mon, 27 Mar 2023 11:01:47 +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 Subject: [edk2-devel] [PATCH v2 06/17] MdePkg/BaseMemoryLibOptDxe AARCH64: Make asm files BTI compatible Date: Mon, 27 Mar 2023 13:01:01 +0200 Message-Id: <20230327110112.262503-7-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: i7ymwcmAktDPh9JNAf0hU9GGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914911; bh=DvFJTBXb7ZOBqhhnKd3X54fNnAZlst9rNnuZRe5zFPc=; h=Cc:Date:From:Reply-To:Subject:To; b=A7B6QGlke+duL/SP9IsH5o/UJdgwEcqq6swl/BPI60PHsP9uwU06pmRziqDfSUi/5yD lIA7We/KtQ+XvJ1WGCFQxaSPFiqyvAiWxLHC7UuZsxZD/4GLXmoDBlOoDwaxXJ0JAIoT3 wWACOl/t/U6sbl7AkMRk8NGq/loEekc86zs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914913214100017 Content-Type: text/plain; charset="utf-8" Add the BTI instructions and the associated note to make the AArch64 asm objects compatible with BTI enforcement. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- MdePkg/Library/BaseMemoryLibOptDxe/AArch64/CompareGuid.S | 1 + MdePkg/Library/BaseMemoryLibOptDxe/AArch64/CompareMem.S | 1 + MdePkg/Library/BaseMemoryLibOptDxe/AArch64/CopyMem.S | 1 + MdePkg/Library/BaseMemoryLibOptDxe/AArch64/ScanMem.S | 1 + MdePkg/Library/BaseMemoryLibOptDxe/AArch64/SetMem.S | 5 +++++ 5 files changed, 9 insertions(+) diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/CompareGuid.S b/Mde= Pkg/Library/BaseMemoryLibOptDxe/AArch64/CompareGuid.S index b7a566fdafacc8a6..7f058e94b3b7023a 100644 --- a/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/CompareGuid.S +++ b/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/CompareGuid.S @@ -8,6 +8,7 @@ .align 5 ASM_GLOBAL ASM_PFX(InternalMemCompareGuid) ASM_PFX(InternalMemCompareGuid): + AARCH64_BTI(c) mov x2, xzr ldp x3, x4, [x0] cbz x1, 0f diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/CompareMem.S b/MdeP= kg/Library/BaseMemoryLibOptDxe/AArch64/CompareMem.S index ffe4b7a0b058cc85..707e06b0505a19cd 100644 --- a/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/CompareMem.S +++ b/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/CompareMem.S @@ -32,6 +32,7 @@ .p2align 6 ASM_GLOBAL ASM_PFX(InternalMemCompareMem) ASM_PFX(InternalMemCompareMem): + AARCH64_BTI(c) eor tmp1, src1, src2 tst tmp1, #7 b.ne .Lmisaligned8 diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/CopyMem.S b/MdePkg/= Library/BaseMemoryLibOptDxe/AArch64/CopyMem.S index 9fad6d1f267c1bcf..59a6593d96cae907 100644 --- a/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/CopyMem.S +++ b/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/CopyMem.S @@ -178,6 +178,7 @@ L(copy_long): =20 ASM_GLOBAL ASM_PFX(InternalMemCopyMem) ASM_PFX(InternalMemCopyMem): + AARCH64_BTI(c) sub tmp2, dstin, src cmp count, 96 ccmp tmp2, count, 2, hi diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/ScanMem.S b/MdePkg/= Library/BaseMemoryLibOptDxe/AArch64/ScanMem.S index 8673b76eca857b8e..55aaf89f56b43fad 100644 --- a/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/ScanMem.S +++ b/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/ScanMem.S @@ -45,6 +45,7 @@ =20 ASM_GLOBAL ASM_PFX(InternalMemScanMem8) ASM_PFX(InternalMemScanMem8): + AARCH64_BTI(c) // Do not dereference srcin if no bytes to compare. cbz cntin, .Lzero_length // diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/SetMem.S b/MdePkg/L= ibrary/BaseMemoryLibOptDxe/AArch64/SetMem.S index f9748405592057f0..b5618bf09d8bae2f 100644 --- a/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/SetMem.S +++ b/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/SetMem.S @@ -29,29 +29,34 @@ =20 ASM_GLOBAL ASM_PFX(InternalMemSetMem16) ASM_PFX(InternalMemSetMem16): + AARCH64_BTI(c) dup v0.8H, valw lsl count, count, #1 b 0f =20 ASM_GLOBAL ASM_PFX(InternalMemSetMem32) ASM_PFX(InternalMemSetMem32): + AARCH64_BTI(c) dup v0.4S, valw lsl count, count, #2 b 0f =20 ASM_GLOBAL ASM_PFX(InternalMemSetMem64) ASM_PFX(InternalMemSetMem64): + AARCH64_BTI(c) dup v0.2D, val lsl count, count, #3 b 0f =20 ASM_GLOBAL ASM_PFX(InternalMemZeroMem) ASM_PFX(InternalMemZeroMem): + AARCH64_BTI(c) movi v0.16B, #0 b 0f =20 ASM_GLOBAL ASM_PFX(InternalMemSetMem) ASM_PFX(InternalMemSetMem): + AARCH64_BTI(c) dup v0.16B, valw 0: add dstend, dstin, count mov val, v0.D[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 (#101930): https://edk2.groups.io/g/devel/message/101930 Mute This Topic: https://groups.io/mt/97879287/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- From nobody Fri Apr 26 06:50:03 2024 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+101931+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+101931+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914914; cv=none; d=zohomail.com; s=zohoarc; b=hVCPhj8gdOLego8+FSbXHEx4ZNfucac/C5V02y5GIspJhhDwKqmCTVLePRN4hpq99C05S+chVwKagCvLOKWSm+abwfg62bKcfDKA0kmNWTQoydpvnAvP/ABxhKTizdiLlCxChTjg6nkztdimvGiqPn7bZgvyk3nLzDvCDjan+LM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914914; 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=JQHwd6Aoxrx9pTDu2bfFngeZK/XG+5w/ApPqWS0Q6oA=; b=GeCmuKXcar4RFs6AlVRrrOSDDOxIzr/NtXEd001pflZcJUzHTOtfLzNGzmn4/zfOnohA4vweSoY2iSRdXHwtQQtndru/xQTFk0+/mjV1ZAHq/F82BdRwNqn2nSLYOYj/FJaOeT3M20OSfk0eCBbBsnFxN4rg1zqhqxqdj/bwx9k= 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+101931+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 1679914914607237.86038935330635; Mon, 27 Mar 2023 04:01:54 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id dnwvYY1788612xbaw59grElH; Mon, 27 Mar 2023 04:01:54 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.31893.1679914913690319937 for ; Mon, 27 Mar 2023 04:01:53 -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 4106F611A9; Mon, 27 Mar 2023 11:01:53 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D18EC4339B; Mon, 27 Mar 2023 11:01:50 +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 Subject: [edk2-devel] [PATCH v2 07/17] MdePkg/BaseSynchronizationLib AARCH64: Make asm files BTI compatible Date: Mon, 27 Mar 2023 13:01:02 +0200 Message-Id: <20230327110112.262503-8-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: 7P6Ia1NZ4natgPQjbp12hXpSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914914; bh=8bDxpQRIRE+WKy5O5mdNpQTSHcyN9aCfrh3k+Xq8z+U=; h=Cc:Date:From:Reply-To:Subject:To; b=XPYlwrrKDC5SkBU7dVaCsn5WKuac+6e8KVtoJGBo1ZPWiPPFgaIhSHqOuWE4GiQHYhv NamZ9KhYYFBwh5rZk4l4uLsg69oucOQDMxbSBYSKX5J/SZooCluBTyh/HC7fID/dlpzRT FHQZeGpNqAnBiZX3vkE+qI3tor2eN3NpcUI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914915211100022 Content-Type: text/plain; charset="utf-8" Add the BTI instructions and the associated note to make the AArch64 asm objects compatible with BTI enforcement. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.= S b/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S index 1a0eb971a6c92d4c..dfcfc80d0cbeff5e 100644 --- a/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S +++ b/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S @@ -41,6 +41,7 @@ GCC_ASM_EXPORT(InternalSyncDecrement) // IN UINT16 ExchangeValue // ) ASM_PFX(InternalSyncCompareExchange16): + AARCH64_BTI(c) uxth w1, w1 uxth w2, w2 dmb sy @@ -84,6 +85,7 @@ InternalSyncCompareExchange16Fail: // IN UINT32 ExchangeValue // ) ASM_PFX(InternalSyncCompareExchange32): + AARCH64_BTI(c) dmb sy =20 InternalSyncCompareExchange32Again: @@ -124,6 +126,7 @@ InternalSyncCompareExchange32Fail: // IN UINT64 ExchangeValue // ) ASM_PFX(InternalSyncCompareExchange64): + AARCH64_BTI(c) dmb sy =20 InternalSyncCompareExchange64Again: @@ -159,6 +162,7 @@ InternalSyncCompareExchange64Fail: // IN volatile UINT32 *Value // ) ASM_PFX(InternalSyncIncrement): + AARCH64_BTI(c) dmb sy TryInternalSyncIncrement: ldxr w1, [x0] @@ -188,6 +192,7 @@ TryInternalSyncIncrement: // IN volatile UINT32 *Value // ) ASM_PFX(InternalSyncDecrement): + AARCH64_BTI(c) dmb sy TryInternalSyncDecrement: ldxr w1, [x0] --=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 (#101931): https://edk2.groups.io/g/devel/message/101931 Mute This Topic: https://groups.io/mt/97879288/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- From nobody Fri Apr 26 06:50:03 2024 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+101932+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+101932+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914919; cv=none; d=zohomail.com; s=zohoarc; b=lbe5COEaUiHn90oDQFiIxEnVYb2MVdo6kSSwv9+W04tHDwJm4vsXmS8AZ8PYKzSJ8UO/Ugki76vNngKCMFvOpNi5pruUmr9CiVWBHd5LheQKqPUuGBJ3RGbeBZowLpY6MP/wLFzVhd4NcxhrxmBeuGeJJIB1mdopgw5+oE1n1oA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914919; 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=VOnhgCaB9bnE7LDNuTKzArH9ERFtQHToEjiO28isMIY=; b=X6RbMWSo0exEOhkXZEDfd6TMP1X5isR6R16OWR94azrDVF8icSD0QhcXIhLXSdF3HcTtq0rUdQCZIJX/ZYQdgoeUd9g0g9PfPo2qzNfYXppRGL0JDubfOEcuJYDb3Abph2zstJxACLLrXrOrIdvCpi17VeOvluKTqpy6jh3BfLg= 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+101932+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 1679914919804500.1238048270535; Mon, 27 Mar 2023 04:01:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id xqAwYY1788612x0YXIqzArXm; Mon, 27 Mar 2023 04:01:59 -0700 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web10.31895.1679914918389507896 for ; Mon, 27 Mar 2023 04:01:58 -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 ams.source.kernel.org (Postfix) with ESMTPS id DC311B80D5F; Mon, 27 Mar 2023 11:01:56 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2105BC433A1; Mon, 27 Mar 2023 11:01:52 +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 Subject: [edk2-devel] [PATCH v2 08/17] MdePkg/BaseRngLib AARCH64: Make asm files BTI compatible Date: Mon, 27 Mar 2023 13:01:03 +0200 Message-Id: <20230327110112.262503-9-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: JWs78jbdcFDGK7zxZSLBCtL4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914919; bh=1N75jUpk26nokFKPapUMyQjbF4oh+D7Axle85daP43I=; h=Cc:Date:From:Reply-To:Subject:To; b=bHn3riCrWCKLHdOAOy+D4cXWRG6wmLx5ZRekQcS4kBMQAUIGOXfvjrqE2+Whj1xD+8Z qjOb2YA4wtIUzW2ew6Jb3FNoTqp8BIR1gGhtDkn7WaALtnxV2mR5K5EF86KL35HYEwyaq sTjEwyLCZGHIyflHKrXoasOms6Xj/or6WBc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914921218100001 Content-Type: text/plain; charset="utf-8" Add the BTI instructions and the associated note to make the AArch64 asm objects compatible with BTI enforcement. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- MdePkg/Library/BaseRngLib/AArch64/ArmReadIdIsar0.S | 3 +-- MdePkg/Library/BaseRngLib/AArch64/ArmRng.S | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MdePkg/Library/BaseRngLib/AArch64/ArmReadIdIsar0.S b/MdePkg/Li= brary/BaseRngLib/AArch64/ArmReadIdIsar0.S index 82a00d36221278e0..d30b63fe5c68c565 100644 --- a/MdePkg/Library/BaseRngLib/AArch64/ArmReadIdIsar0.S +++ b/MdePkg/Library/BaseRngLib/AArch64/ArmReadIdIsar0.S @@ -25,7 +25,6 @@ GCC_ASM_EXPORT(ArmReadIdIsar0) # ); # ASM_PFX(ArmReadIdIsar0): + AARCH64_BTI(c) mrs x0, id_aa64isar0_el1 // Read ID_AA64ISAR0 Register ret - - diff --git a/MdePkg/Library/BaseRngLib/AArch64/ArmRng.S b/MdePkg/Library/Ba= seRngLib/AArch64/ArmRng.S index 5159f467e3a6cd6e..27a847b996fd1d2a 100644 --- a/MdePkg/Library/BaseRngLib/AArch64/ArmRng.S +++ b/MdePkg/Library/BaseRngLib/AArch64/ArmRng.S @@ -31,6 +31,7 @@ GCC_ASM_EXPORT(ArmRndr) # ); # ASM_PFX(ArmRndr): + AARCH64_BTI(c) mrs x1, RNDR str x1, [x0] cset x0, ne // RNDR sets NZCV to 0b0100 on failure --=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 (#101932): https://edk2.groups.io/g/devel/message/101932 Mute This Topic: https://groups.io/mt/97879289/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- From nobody Fri Apr 26 06:50:03 2024 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+101933+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+101933+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914920; cv=none; d=zohomail.com; s=zohoarc; b=VT2vJ30Z4s1erf7Ri+89/JoWmDNqeGeHkCFwC2d2zjl1j+4pti5FTPx5MLWOOSKiDI/G2izHAuioUmSS7935n8MWttZ1rgC5oWPU6FJxDh51+RAi4uEhGm9Uim90Job3YV0SR+fBukrC/gwGXqcUbufTMH8zOtv9szMXVsdnajU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914920; 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=4aiYkxCPwaWQby7MnoBbfBTibXpqLuC82Zzt9rVtptk=; b=gO0KZ8RX106L26YSkMuQX0N221dvaWyX2cCiRaz5F8VVgcMpQ4iWR6RiqrhwDYv5g6m3OSzB7x1es/KazSotLbEhQM7+hsJieuMvhoaTLuqm/HlezI4/4QZEzvt4mY/+FMqTmLRQEGs11gg58Ym7f1rAnbEOphjymy+XU66UZMs= 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+101933+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 1679914920729136.60743453877762; Mon, 27 Mar 2023 04:02:00 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id lfAMYY1788612xBVo0ysk3I0; Mon, 27 Mar 2023 04:02:00 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.31896.1679914919595753197 for ; Mon, 27 Mar 2023 04:01:59 -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 2ACCE61043; Mon, 27 Mar 2023 11:01:59 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 145A0C433A0; Mon, 27 Mar 2023 11:01:55 +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 Subject: [edk2-devel] [PATCH v2 09/17] ArmPkg: Emit BTI opcodes when BTI codegen is enabled Date: Mon, 27 Mar 2023 13:01:04 +0200 Message-Id: <20230327110112.262503-10-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: odjnp0y2CSSN6GU7hDAkGD5Lx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914920; bh=1SyWNO7UeeWU/djgfbkcmkP5Kp5eFUGgunrJUPiO+t8=; h=Cc:Date:From:Reply-To:Subject:To; b=YoR3TcFHEz0k162NDIj/Vfhkx74scLCWIKswK4Kavk6wj53u3k47uwXWFA250qlO5rm ZHzyHKYEGOKiJXGjB5TyW+vO3BzKx28awOHu6ndLW7+NnkOCvKXQy8ry3+Mvqa1UqUklE LtOOnvNuiOwp/tzbsoeAPdX+OYc+E8LvfbY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914921243100003 Content-Type: text/plain; charset="utf-8" When building with -mbranch-protection=3Dbti, which affects the compiler codegen only, ensure that the assembler based codegen is aligned with this, by emitting the BTI C opcode at the start of each exported function. While most exported functions are not in fact ever called indirectly, whether or not this is the case is a property of the caller so annotating every exported function is a reasonable default. While at it, fix two occurrences in ArmPkg of exported functions that did not use the ASM_FUNC() macro. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- ArmPkg/Include/AsmMacroIoLibV8.h | 3 ++- ArmPkg/Library/ArmExceptionLib/AArch64/ExceptionSupport.S | 3 +-- ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/ArmPkg/Include/AsmMacroIoLibV8.h b/ArmPkg/Include/AsmMacroIoLi= bV8.h index 2c2b1cabd0537671..135aaeca5d0b986d 100644 --- a/ArmPkg/Include/AsmMacroIoLibV8.h +++ b/ArmPkg/Include/AsmMacroIoLibV8.h @@ -38,7 +38,8 @@ .global Name ; \ .section #Section, "ax" ; \ .type Name, %function ; \ - Name: + Name: ; \ + AARCH64_BTI(c) =20 #define ASM_FUNC(Name) _ASM_FUNC(ASM_PFX(Name), .text. ## Name) =20 diff --git a/ArmPkg/Library/ArmExceptionLib/AArch64/ExceptionSupport.S b/Ar= mPkg/Library/ArmExceptionLib/AArch64/ExceptionSupport.S index 9202952ee9c0d4e5..cd9437b6aab82889 100644 --- a/ArmPkg/Library/ArmExceptionLib/AArch64/ExceptionSupport.S +++ b/ArmPkg/Library/ArmExceptionLib/AArch64/ExceptionSupport.S @@ -94,7 +94,6 @@ =20 GCC_ASM_EXPORT(ExceptionHandlersEnd) GCC_ASM_EXPORT(CommonCExceptionHandler) -GCC_ASM_EXPORT(RegisterEl0Stack) =20 .text =20 @@ -387,6 +386,6 @@ ASM_PFX(CommonExceptionEntry): =20 eret =20 -ASM_PFX(RegisterEl0Stack): +ASM_FUNC(RegisterEl0Stack) msr sp_el0, x0 ret diff --git a/ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S b/ArmPkg/Library/Arm= SvcLib/AArch64/ArmSvc.S index 1a7c10cb793183e7..ab13914fd3e7a359 100644 --- a/ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S +++ b/ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S @@ -8,9 +8,7 @@ .text .align 3 =20 -GCC_ASM_EXPORT(ArmCallSvc) - -ASM_PFX(ArmCallSvc): +ASM_FUNC(ArmCallSvc) // Push frame pointer and return address on the stack stp x29, x30, [sp, #-32]! mov x29, sp --=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 (#101933): https://edk2.groups.io/g/devel/message/101933 Mute This Topic: https://groups.io/mt/97879290/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- From nobody Fri Apr 26 06:50:03 2024 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+101934+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+101934+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914925; cv=none; d=zohomail.com; s=zohoarc; b=NFR/zr0pAosT5eBTO/DHeudxvWfgrI4WtI5jjF0s9prQFLQ+0UZBFsxk3RSuGwOiguryXkSpEEE/MU/QWLkq8/Qtkchzp5AzBltJ95w9SEcPy25tOGzogXEUjK0GCZ7aIgnpGcetTmsRzBMGx0xs5LBqvuWhsaBxrhUCs//HFUg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914925; 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=lNUAfWeQzQSdTuRi1s0/bD9QE4Fw7gQqyjA9o7hrT6s=; b=SiDlO/XrSVR1TsNuccvheaItYc4lXtX/CG7k7ZrHsuRujLBjeb+cuRQQNEkEakbk5HfPWYb3oYj9a09169+2fAIncazXjCIDv/ImWj5fw8NmGVvFRMPi8J5tWMfuOoZyzDS035Lpb+H5ArJalTE7PA/Oc4nP1TggNjVoV+R9koQ= 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+101934+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 1679914925588241.35503953695434; Mon, 27 Mar 2023 04:02:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id XEMfYY1788612xPsc5dQst2P; Mon, 27 Mar 2023 04:02:05 -0700 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web10.31899.1679914924210000853 for ; Mon, 27 Mar 2023 04:02:04 -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 ams.source.kernel.org (Postfix) with ESMTPS id BD17EB80DA9; Mon, 27 Mar 2023 11:02:02 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0857AC4339C; Mon, 27 Mar 2023 11:01:58 +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 Subject: [edk2-devel] [PATCH v2 10/17] ArmPkg/GccLto AARCH64: Add BTI note to LTO helper library Date: Mon, 27 Mar 2023 13:01:05 +0200 Message-Id: <20230327110112.262503-11-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: hjBHAo97OQv4d5l3gM9KQ5qox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914925; bh=lNUAfWeQzQSdTuRi1s0/bD9QE4Fw7gQqyjA9o7hrT6s=; h=Cc:Date:From:Reply-To:Subject:To; b=Sw8SlJlFqQuOJXpgvre14pP/LYV+rEblDwDBRW39WTfhODVT+iLg0EFWTQlGJsbuRsN PaBgaoOTIGtETe6Ozy1+fswVIbTx+R/6lG7eOx09ylzNw9kKs6oqEWqKhHFujoh76slqu blycp5kR0Pw/kuvj3O0OPbxmmsYN8EkHE04= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914927270100002 Content-Type: text/plain; charset="utf-8" The GccLto helper library does not contain any code, as its only purpose is to pull in other libraries that implement intrinsics to which the linker's codegen pass may emit calls. So mark it as BTI compatible, so that the linker does not complain about unannotated objects. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- ArmPkg/Library/GccLto/liblto-aarch64.a | Bin 1016 -> 1128 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/ArmPkg/Library/GccLto/liblto-aarch64.a b/ArmPkg/Library/GccLto= /liblto-aarch64.a index 2ab00238f0dad882abf08a1fb9623c9cdea9f17b..6ca3932f1cf30e389ab4c9bdbb7= 7c7db729f1f14 100644 GIT binary patch delta 168 zcmeyt{(@tIhNA`(0~|PjSq=3D=3DG3>tqY22*!rV6PcEC8Uj_b12NO&gG}O#3KJKKPR?Ui hVl0?Ek=3DdTnWAa62^~n~@5}Xehfog!j1+0LH3joADAhrMi delta 90 zcmaFC@q>MWhWHOg1~_m4vm6*W7+5D8GU;yYX=3DR*j#AG(vfk|+322%uM!sLTY%O`8F gNN^s2>N1>oP;~M (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 167991492640093.09884268269946; Mon, 27 Mar 2023 04:02:06 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id KbhsYY1788612xlhJGG15Oll; Mon, 27 Mar 2023 04:02:05 -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.32022.1679914925268993792 for ; Mon, 27 Mar 2023 04:02:05 -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 CD9E9611AC; Mon, 27 Mar 2023 11:02:04 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1B7CC433A0; Mon, 27 Mar 2023 11:02:01 +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 Subject: [edk2-devel] [PATCH v2 11/17] ArmPkg, BaseTools AARCH64: Add BTI ELF note to .hii objects Date: Mon, 27 Mar 2023 13:01:06 +0200 Message-Id: <20230327110112.262503-12-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: D8QJM6RxFoFfyHFlCPK0IIESx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914925; bh=XpNoIpNgLkFnAF/zPQWFA7ETVqo1YGkXTETeMHOckDM=; h=Cc:Date:From:Reply-To:Subject:To; b=cUmgaPZ1cGV3zIPbmAo5IFJCYEZqwL1u3yPE+2PupSFsKak/QP3ECbNZdu31jIgwkzt tUb3eZ126gHOfKvrMbH+QaF6x5r3Zm616ThiZFDwPoT/7CGsnsQXqAfs06cdipW18i+0r p/2vWaRBlzBGp2v+/5B554PRGS3XeAYFLiM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914927299100003 Content-Type: text/plain; charset="utf-8" The ELF based toolchains use objcopy to create HII object files, which contain only a single .hii section. This means no GNU note is inserted that describes the object as compatible with BTI, even though the lack of executable code in such an object makes the distinction irrelevant. However, the linker will not add the note globally to the resulting ELF executable, and this breaks BTI compatibility. So let's insert a GNU BTI-compatible ELF note by hand when generating such object files. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- ArmPkg/Library/GnuNoteBti.bin | Bin 0 -> 32 bytes BaseTools/Conf/tools_def.template | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ArmPkg/Library/GnuNoteBti.bin b/ArmPkg/Library/GnuNoteBti.bin new file mode 100644 index 0000000000000000000000000000000000000000..339567b4e89943c610b44767dda= d5f631229ed3b GIT binary patch literal 32 dcmZQ!U| (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1679914929580272.605324079929; Mon, 27 Mar 2023 04:02:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qsriYY1788612xwdhoGWBcDl; Mon, 27 Mar 2023 04:02:09 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.31901.1679914928466998722 for ; Mon, 27 Mar 2023 04:02:08 -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 0B464611A9; Mon, 27 Mar 2023 11:02:08 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5A31C4339B; Mon, 27 Mar 2023 11:02:04 +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 Subject: [edk2-devel] [PATCH v2 12/17] ArmPlatformPkg/PrePeiCore: Make vector table object BTI compatible Date: Mon, 27 Mar 2023 13:01:07 +0200 Message-Id: <20230327110112.262503-13-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: 4xk9Cf0mQRk1kd17cFO2huz6x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914929; bh=AXKAuQsYeL/SJDl9Hw1p7pOZC6uaId63VVdowqANE+k=; h=Cc:Date:From:Reply-To:Subject:To; b=iVZO3A7JUOAZRIAhxFjNPJm3QjcCFQ/1afkeifZ7BugKRDG2qv7Pz4NuIp+j8xBKEkC OonzuQrMkRWy4d8nqsMWx4C8P74MRaXcbcg1udEOgGL96bimTWgp/qtCdsAv8m+XbPhH3 etix6Fms4mpx83xl1FwpJNH6Ts/NvN/j3f8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914931263100002 Content-Type: text/plain; charset="utf-8" The object file containing the vector table does not contain any callable functions, so it will not be implicitly annotated as BTI compatible on BTI builds. So add the annotation by hand, and use the 'empty' type so we get the GNU ELF note but not the actual BTI opcode. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- ArmPlatformPkg/PrePeiCore/AArch64/Exception.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ArmPlatformPkg/PrePeiCore/AArch64/Exception.S b/ArmPlatformPkg= /PrePeiCore/AArch64/Exception.S index 43e40f97c3eed5ff..5a84fefe3fb55216 100644 --- a/ArmPlatformPkg/PrePeiCore/AArch64/Exception.S +++ b/ArmPlatformPkg/PrePeiCore/AArch64/Exception.S @@ -112,3 +112,5 @@ _DefaultSError_LowerA32: TO_HANDLER =20 VECTOR_END(PeiVectorTable) + +AARCH64_BTI() --=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 (#101936): https://edk2.groups.io/g/devel/message/101936 Mute This Topic: https://groups.io/mt/97879295/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- From nobody Fri Apr 26 06:50:03 2024 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+101937+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+101937+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914936; cv=none; d=zohomail.com; s=zohoarc; b=hVDun8HINXEHPTqxQF1mj5YzK1OLrZDrH4kFhF8+kuWBidb3Y19X0eabU9zNTnTogWWR+AN4eTyuUzGWTu3HFsyMnz64hqcgQ3poLrwab/QFNpyy12jPiNTM+hsY96T/lwe7c/J3jmaB24xmYYpTQQ8/4QHvnZdAlC59uXoZqTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914936; 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=DCr9XjPlMJLP8NMSoJy5nju43IGeKmh4vt6I/vtZjwg=; b=Oh6x5aiqPYIOY/u3MjYsoOsoY6kN4auey2+2TGGBe+KjIw9i/iaJVbn4KsThW9iU3vuPkoynfeMciKE6eZeYLhCMMw1OEITDAqGIwtri3Qj4ozhXMdxqx2hs0DWfIOsnvgqD+6bPXvG1wYeu18/mN54en8zqUz5/ws959WJH6uw= 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+101937+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 1679914936909126.20475423604341; Mon, 27 Mar 2023 04:02:16 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FfDZYY1788612xPzUuzgtQOt; Mon, 27 Mar 2023 04:02:16 -0700 X-Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by mx.groups.io with SMTP id smtpd.web10.31904.1679914935350134566 for ; Mon, 27 Mar 2023 04:02:15 -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 sin.source.kernel.org (Postfix) with ESMTPS id 2FCA2CE0E4D; Mon, 27 Mar 2023 11:02:12 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAC88C433D2; Mon, 27 Mar 2023 11:02:07 +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 Subject: [edk2-devel] [PATCH v2 13/17] BaseTools/GenFw: Parse IBT/BTI support status from ELF note Date: Mon, 27 Mar 2023 13:01:08 +0200 Message-Id: <20230327110112.262503-14-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: 8NtIZoKAexJWCnYRgtZeTZoIx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914936; bh=gsPqMb1EtPbj49y6kCp6qGwlq3Wt+9zt0ByzXpnMpSM=; h=Cc:Date:From:Reply-To:Subject:To; b=vatB/fVgZQiB+KI2+Y1FY4Ds8PDgmyWMqMVanu9Mm4gfvuJX/9kEBBV1GiMe8pyF+hc knqnkC/zhYoMCxFnoyiYMuKlE9grWwgvAhRKSWWcf1UX3SkxSxrRjHRaE3hw3icPKBmzu Ya1bDUqlNcCIVheRiAk8iWy8zIb6KqkoCk0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914937396100001 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 --- 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 (#101937): https://edk2.groups.io/g/devel/message/101937 Mute This Topic: https://groups.io/mt/97879299/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- From nobody Fri Apr 26 06:50:03 2024 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+101938+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+101938+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914937; cv=none; d=zohomail.com; s=zohoarc; b=Wv6hx//kT5zH04cR4FCXEsIN46AFuSVgtrmN2Icg1DrzP/ZYCilJk26OH9SuXSmqYjRqKNxjolEibz3Bfeib5OOzKJPgjlPvLIGfnTKA0M35srU+H18f3pOjDGzMXmgzU8x3pUR2bJsMwaGj9JLY/xZwXKmSPnsckZMy4e4athY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914937; 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=HlwUU+WALs49xNljmTj4VH/e80VFNylpWbFsfaBMAP8=; b=EL34P4bax0Z4XwVfegkXjIt6F5pyf7cSGoivAVFtitKoJuIpgaeszPZ+3fBGs3sucxdz8XGhTBzys/2JgRfpdLkk8tPFuMyLmakUDO/c0GKLihgMI9p254fkSdVJL3WRHRcqdHxzy8gORZby8orm0248th+wzEyV3Kyu+UlFUNs= 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+101938+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 1679914937665857.4164324495559; Mon, 27 Mar 2023 04:02:17 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7xITYY1788612xvrGuYTryFJ; Mon, 27 Mar 2023 04:02:17 -0700 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web11.32027.1679914936261764428 for ; Mon, 27 Mar 2023 04:02:16 -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 ams.source.kernel.org (Postfix) with ESMTPS id B18EFB80DA3; Mon, 27 Mar 2023 11:02:14 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE846C433A1; Mon, 27 Mar 2023 11:02:10 +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 Subject: [edk2-devel] [PATCH v2 14/17] BaseTools/GenFw: Add DllCharacteristicsEx field to debug data Date: Mon, 27 Mar 2023 13:01:09 +0200 Message-Id: <20230327110112.262503-15-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: qPvhyIWYuS8ovhIBcK11Y6Spx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914937; bh=eIPEn+i6zojM8jqcv17AMTjmLHsuDLT5rp4gbVoDjjw=; h=Cc:Date:From:Reply-To:Subject:To; b=J+Z2uq8xaB8OIDZZ4WjGXHUDnOlEkKxNbxi9OudVg41JLtYCyomf7Cqvc6VCX7f1V8W kXORYoPxnflrojps/f2jZVUnEO2u555gwDR6kVt+Fk/HTUOUr9lFZBmBLB4+oxnx9Gznu ZXbDSCcCArwNsicfkeCS0PQ6xPbDZBY4AwU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914939443100008 Content-Type: text/plain; charset="utf-8" The PE/COFF spec describes an additional DllCharacteristics field implemented as a debug directory entry, which carries flags related to which control flow integrity (CFI) features are supported by the binary. So let's add this entry when doing ELF to PE/COFF conversion - we will add support for setting the flags in a subsequent patch. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- BaseTools/Source/C/GenFw/Elf64Convert.c | 54 +++++++++++++++= ----- BaseTools/Source/C/GenFw/GenFw.c | 3 +- BaseTools/Source/C/Include/IndustryStandard/PeImage.h | 13 ++++- 3 files changed, 55 insertions(+), 15 deletions(-) diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/G= enFw/Elf64Convert.c index 2a810e835d4a4a66..9c17c90b16602421 100644 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -992,6 +992,16 @@ ScanSections64 ( sizeof(EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY) + strlen(mInImageName) + 1; =20 + // + // Add more space in the .debug data region for the DllCharacteristicsEx + // field. + // + if (mDllCharacteristicsEx !=3D 0) { + mCoffOffset =3D DebugRvaAlign(mCoffOffset) + + sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY) + + sizeof (EFI_IMAGE_DEBUG_EX_DLLCHARACTERISTICS_ENTRY); + } + mCoffOffset =3D CoffAlign(mCoffOffset); if (SectionCount =3D=3D 0) { mDataOffset =3D mCoffOffset; @@ -2244,29 +2254,47 @@ WriteDebug64 ( VOID ) { - UINT32 Len; - EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr; - EFI_IMAGE_DATA_DIRECTORY *DataDir; - EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *Dir; - EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY *Nb10; + UINT32 Len; + EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr; + EFI_IMAGE_DATA_DIRECTORY *DataDir; + EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *Dir; + EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY *Nb10; + EFI_IMAGE_DEBUG_EX_DLLCHARACTERISTICS_ENTRY *DllEntry; =20 Len =3D strlen(mInImageName) + 1; =20 + NtHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + mNtHdrOffset); + DataDir =3D &NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRE= CTORY_ENTRY_DEBUG]; + DataDir->VirtualAddress =3D mDebugOffset; + DataDir->Size =3D sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); + Dir =3D (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY*)(mCoffFile + mDebugOffset); + + if (mDllCharacteristicsEx !=3D 0) { + DataDir->Size +=3D sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); + + Dir->Type =3D EFI_IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS; + Dir->SizeOfData =3D sizeof (EFI_IMAGE_DEBUG_EX_DLLCHARACTERISTICS_ENTR= Y); + Dir->FileOffset =3D mDebugOffset + DataDir->Size + + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY) + + DebugRvaAlign(Len); + Dir->RVA =3D Dir->FileOffset; + + DllEntry =3D (VOID *)(mCoffFile + Dir->FileOffset); + + DllEntry->DllCharacteristicsEx =3D mDllCharacteristicsEx; + + Dir++; + } + Dir->Type =3D EFI_IMAGE_DEBUG_TYPE_CODEVIEW; Dir->SizeOfData =3D sizeof(EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY) + Len; - Dir->RVA =3D mDebugOffset + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); - Dir->FileOffset =3D mDebugOffset + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTR= Y); + Dir->RVA =3D mDebugOffset + DataDir->Size; + Dir->FileOffset =3D mDebugOffset + DataDir->Size; =20 Nb10 =3D (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY*)(Dir + 1); Nb10->Signature =3D CODEVIEW_SIGNATURE_NB10; strcpy ((char *)(Nb10 + 1), mInImageName); - - - NtHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + mNtHdrOffset); - DataDir =3D &NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRE= CTORY_ENTRY_DEBUG]; - DataDir->VirtualAddress =3D mDebugOffset; - DataDir->Size =3D sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); } =20 STATIC diff --git a/BaseTools/Source/C/GenFw/GenFw.c b/BaseTools/Source/C/GenFw/Ge= nFw.c index 6f61f16788cd2a0a..d0e52ccc26431380 100644 --- a/BaseTools/Source/C/GenFw/GenFw.c +++ b/BaseTools/Source/C/GenFw/GenFw.c @@ -2932,7 +2932,8 @@ Routine Description: if (mIsConvertXip) { DebugEntry->FileOffset =3D DebugEntry->RVA; } - if (ZeroDebugFlag || DebugEntry->Type !=3D EFI_IMAGE_DEBUG_TYPE_CODE= VIEW) { + if ((ZeroDebugFlag || DebugEntry->Type !=3D EFI_IMAGE_DEBUG_TYPE_COD= EVIEW) && + (DebugEntry->Type !=3D EFI_IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTIC= S)) { memset (FileBuffer + DebugEntry->FileOffset, 0, DebugEntry->SizeOf= Data); memset (DebugEntry, 0, sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)); } diff --git a/BaseTools/Source/C/Include/IndustryStandard/PeImage.h b/BaseTo= ols/Source/C/Include/IndustryStandard/PeImage.h index 77ded3f611398278..5e9428ab98c7f68a 100644 --- a/BaseTools/Source/C/Include/IndustryStandard/PeImage.h +++ b/BaseTools/Source/C/Include/IndustryStandard/PeImage.h @@ -615,7 +615,8 @@ typedef struct { /// /// Debug Format /// -#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2 +#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2 +#define EFI_IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS 20 =20 typedef struct { UINT32 Characteristics; @@ -664,6 +665,16 @@ typedef struct { // } EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY; =20 +/// +/// Extended DLL Characteristics +/// +#define EFI_IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT 0x0001 +#define EFI_IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT 0x0040 + +typedef struct { + UINT16 DllCharacteristicsEx; +} EFI_IMAGE_DEBUG_EX_DLLCHARACTERISTICS_ENTRY; + // // .pdata entries for X64 // --=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 (#101938): https://edk2.groups.io/g/devel/message/101938 Mute This Topic: https://groups.io/mt/97879300/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- From nobody Fri Apr 26 06:50:03 2024 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+101939+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+101939+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914938; cv=none; d=zohomail.com; s=zohoarc; b=kjdMg0GbRumngm4skenZ21E2NnB8Jiggexw6/pDDXj8mzRwKYfoDODRzHcRKm5Vmap4QROWMAiVXvOnPwZJkDTGGDRtZYW70f9EeQDTyWradpvMWxhrFlmG1YQOc1cdgCC8RXOYRSyA8D0iFUU/a5yqr1vNqn7WB7OafSyP57vw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914938; 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=MAPtKXdwATlE4Rom1V+kUkc5iyGjPrJJzHr0Lw7NLN8=; b=jDP3Hyp4iWgWyxWqPbjotfCDpW9Jsd8SkQFqtcVSfU8jW2eoE5aACBlpjEzx19wbAPMrn6QOPvDg4pTB/DQP6tZxdTlVcx1ridv4/hlb8GtE/zFjL6jAD2GFNYC3vBVutwrVUwXZsotuxYx3/kuzUwAwazDbGa/uqm6E/7PJtxM= 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+101939+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 1679914938324333.99558015333287; Mon, 27 Mar 2023 04:02:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FrpEYY1788612xqShvRDgnEy; Mon, 27 Mar 2023 04:02:17 -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.32028.1679914937352321382 for ; Mon, 27 Mar 2023 04:02:17 -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 D88E961043; Mon, 27 Mar 2023 11:02:16 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C225FC4339B; Mon, 27 Mar 2023 11:02:13 +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 Subject: [edk2-devel] [PATCH v2 15/17] MdePkg: Update MemoryAttributesTable to v2.10 Date: Mon, 27 Mar 2023 13:01:10 +0200 Message-Id: <20230327110112.262503-16-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: 8Zxecp4RB3XEehNgcttnR8Yux1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914937; bh=hR2OagExn3WteRMt1VG/5qiVhkzYWmEt3lAx/NliEcQ=; h=Cc:Date:From:Reply-To:Subject:To; b=TLx31WkrYj1+PHA6r/BSRriUQBZ6Zfj3eF3am2hf7+wydJIZXa2BgMMM3i8KAjqcjOi u8+tJuRKsqe8aOqFH9+lSguzobzHKyEktNuavy78DUnQ7d1sJDYq2irqbtCwH+KZoqCv+ bSJet6f+U5IqAA4HXuRLJ88oK0j1T/YDB8g= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914939409100006 Content-Type: text/plain; charset="utf-8" UEFI v2.10 introduces a new flag to the memory attributes table to inform the OS whether or not runtime services code regions were emitted by the compiler with guard instructions for forward edge control flow integrity enforcement. So update our definition accordingly. Link: https://uefi.org/specs/UEFI/2.10/04_EFI_System_Table.html#efi-memory-= attributes-table Signed-off-by: Ard Biesheuvel Reviewed-by: Michael D Kinney Acked-by: Michael Kubacki Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- MdePkg/Include/Guid/MemoryAttributesTable.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MdePkg/Include/Guid/MemoryAttributesTable.h b/MdePkg/Include/G= uid/MemoryAttributesTable.h index 82f83a67b96d38c5..238c14ff92dfed31 100644 --- a/MdePkg/Include/Guid/MemoryAttributesTable.h +++ b/MdePkg/Include/Guid/MemoryAttributesTable.h @@ -17,11 +17,15 @@ typedef struct { UINT32 Version; UINT32 NumberOfEntries; UINT32 DescriptorSize; - UINT32 Reserved; + UINT32 Flags; // EFI_MEMORY_DESCRIPTOR Entry[1]; } EFI_MEMORY_ATTRIBUTES_TABLE; =20 -#define EFI_MEMORY_ATTRIBUTES_TABLE_VERSION 0x00000001 +#define EFI_MEMORY_ATTRIBUTES_TABLE_VERSION 0x00000002 + +#define EFI_MEMORY_ATTRIBUTES_FLAGS_RT_FORWARD_CONTROL_FLOW_GUARD 0x1 +// BIT0 implies that Runtime code includes the forward control flow guard +// instruction, such as X86 CET-IBT or ARM BTI. =20 extern EFI_GUID gEfiMemoryAttributesTableGuid; =20 --=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 (#101939): https://edk2.groups.io/g/devel/message/101939 Mute This Topic: https://groups.io/mt/97879302/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- From nobody Fri Apr 26 06:50:03 2024 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+101940+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+101940+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914941; cv=none; d=zohomail.com; s=zohoarc; b=RHlWKkKJrP3GgiJSuwxYDo+BtPkeZP5bDf/Rfh8BUjmTZJ5h912OEQeAhiYhKZsh2ehcO7e1GThHId2xK6eB4hzuD7KcPMBQurEmVqMPknSo+7plYhdyL1nhqkSx89P6twzX5dRmrNaFLa2w4qolKP72SjdznFDvKGCYHE3Yqp8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914941; 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=BpzNYG6WJHXAneJkiV9mRJrPxBlGPGTU9Bo0Gf+aVYM=; b=QAjjDTOPQVd1ioQF9bWjRPqcqqH267qTF5wEcF4OsMyqt5jOXW7NidaLPx3URE6HCpT18lWMJh8D6Zipd/qBPDnkgx5iQvFblD5BpTkxQrjEiJAEtBSh+O1Q6Awf3lgTnX003lAb2WpgwDI/vFB09k8XH7yaOf9/2Lgu24j0xrE= 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+101940+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 1679914941020436.7377870515338; Mon, 27 Mar 2023 04:02:21 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id NnmXYY1788612xXzHpdKC3rK; Mon, 27 Mar 2023 04:02:20 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.31906.1679914939933390791 for ; Mon, 27 Mar 2023 04:02:20 -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 6D978611AF; Mon, 27 Mar 2023 11:02:19 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5D94C433D2; Mon, 27 Mar 2023 11:02:16 +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 Subject: [edk2-devel] [PATCH v2 16/17] MdePkg/PeCoffLib: Capture DLL characteristics fieldis in image context Date: Mon, 27 Mar 2023 13:01:11 +0200 Message-Id: <20230327110112.262503-17-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: xwst81ZF24PpHEjwR4NCwCYax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914940; bh=f+ZA/Ue47uy7xsVA8otS/ElZb4O+fHnBcX/1kvKeLwQ=; h=Cc:Date:From:Reply-To:Subject:To; b=keiG1posC+gl74WVuVuiudk7THgQZ+67DXKw9H0YgfJ6ih3mAC0XvTiGP/oBVCzGRE9 dk+Tc4aMJ8/TDI6PI/wLAycB4x6Or6N8p8c9AwxhjGXSiy0xzHotr6HEeEjU1UBRYkmqv iz5lZ/u5VtABUYTY8UJYKtCO8zlrHO3Nn3Q= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914943543100015 Content-Type: text/plain; charset="utf-8" When loading a PE/COFF image, capture the DLL characteristics fields of the header into our image context structure so we can refer to them when mapping the image. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- MdePkg/Include/IndustryStandard/PeImage.h | 13 +++++- MdePkg/Include/Library/PeCoffLib.h | 6 +++ MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 46 +++++++++++++++----- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/MdePkg/Include/IndustryStandard/PeImage.h b/MdePkg/Include/Ind= ustryStandard/PeImage.h index dd4cc25483bc4bcf..a5b9b848ed391f98 100644 --- a/MdePkg/Include/IndustryStandard/PeImage.h +++ b/MdePkg/Include/IndustryStandard/PeImage.h @@ -625,7 +625,8 @@ typedef struct { UINT32 FileOffset; ///< The file pointer to the debug data. } EFI_IMAGE_DEBUG_DIRECTORY_ENTRY; =20 -#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2 ///< The Visual C++ debug info= rmation. +#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2 ///< The Visual C= ++ debug information. +#define EFI_IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS 20 =20 /// /// Debug Data Structure defined in Microsoft C++. @@ -669,6 +670,16 @@ typedef struct { // } EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY; =20 +/// +/// Extended DLL Characteristics +/// +#define EFI_IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT 0x0001 +#define EFI_IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT 0x0040 + +typedef struct { + UINT16 DllCharacteristicsEx; +} EFI_IMAGE_DEBUG_EX_DLLCHARACTERISTICS_ENTRY; + /// /// Resource format. /// diff --git a/MdePkg/Include/Library/PeCoffLib.h b/MdePkg/Include/Library/Pe= CoffLib.h index b45879453785c77d..d21c932076c072f6 100644 --- a/MdePkg/Include/Library/PeCoffLib.h +++ b/MdePkg/Include/Library/PeCoffLib.h @@ -171,6 +171,12 @@ typedef struct { /// UINT16 ImageType; /// + /// Set by PeCoffLoaderGetImageInfo() to the DLL flags stored in the PE/= COFF header and + /// in the DllCharacteristicsEx debug table. + /// + UINT16 DllCharacteristics; + UINT16 DllCharacteristicsEx; + /// /// Set by PeCoffLoaderGetImageInfo() to TRUE if the PE/COFF image does = not contain /// relocation information. /// diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/Bas= ePeCoffLib/BasePeCoff.c index 97a8aaf8c73d3e3c..4b71176a0c7c2ed0 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -308,10 +308,11 @@ PeCoffLoaderGetPeHeader ( // // Use PE32 offset // - ImageContext->ImageType =3D Hdr.Pe32->OptionalHeader.Subsyste= m; - ImageContext->ImageSize =3D (UINT64)Hdr.Pe32->OptionalHeader.= SizeOfImage; - ImageContext->SectionAlignment =3D Hdr.Pe32->OptionalHeader.SectionA= lignment; - ImageContext->SizeOfHeaders =3D Hdr.Pe32->OptionalHeader.SizeOfHe= aders; + ImageContext->ImageType =3D Hdr.Pe32->OptionalHeader.Subsys= tem; + ImageContext->ImageSize =3D (UINT64)Hdr.Pe32->OptionalHeade= r.SizeOfImage; + ImageContext->SectionAlignment =3D Hdr.Pe32->OptionalHeader.Sectio= nAlignment; + ImageContext->SizeOfHeaders =3D Hdr.Pe32->OptionalHeader.SizeOf= Headers; + ImageContext->DllCharacteristics =3D Hdr.Pe32->OptionalHeader.DllCha= racteristics; } else if (Hdr.Pe32->OptionalHeader.Magic =3D=3D EFI_IMAGE_NT_OPTIONAL= _HDR64_MAGIC) { // // 1. Check FileHeader.NumberOfRvaAndSizes filed. @@ -429,10 +430,11 @@ PeCoffLoaderGetPeHeader ( // // Use PE32+ offset // - ImageContext->ImageType =3D Hdr.Pe32Plus->OptionalHeader.Subs= ystem; - ImageContext->ImageSize =3D (UINT64)Hdr.Pe32Plus->OptionalHea= der.SizeOfImage; - ImageContext->SectionAlignment =3D Hdr.Pe32Plus->OptionalHeader.Sect= ionAlignment; - ImageContext->SizeOfHeaders =3D Hdr.Pe32Plus->OptionalHeader.Size= OfHeaders; + ImageContext->ImageType =3D Hdr.Pe32Plus->OptionalHeader.Su= bsystem; + ImageContext->ImageSize =3D (UINT64)Hdr.Pe32Plus->OptionalH= eader.SizeOfImage; + ImageContext->SectionAlignment =3D Hdr.Pe32Plus->OptionalHeader.Se= ctionAlignment; + ImageContext->SizeOfHeaders =3D Hdr.Pe32Plus->OptionalHeader.Si= zeOfHeaders; + ImageContext->DllCharacteristics =3D Hdr.Pe32Plus->OptionalHeader.Dl= lCharacteristics; } else { ImageContext->ImageError =3D IMAGE_ERROR_INVALID_MACHINE_TYPE; return RETURN_UNSUPPORTED; @@ -545,8 +547,9 @@ PeCoffLoaderGetPeHeader ( Retrieves information about a PE/COFF image. =20 Computes the PeCoffHeaderOffset, IsTeImage, ImageType, ImageAddress, Ima= geSize, - DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders= , and - DebugDirectoryEntryRva fields of the ImageContext structure. + DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, + DllCharacteristics, DllCharacteristicsEx and DebugDirectoryEntryRva fiel= ds of + the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER. If the PE/COFF image accessed through the ImageRead service in the Image= Context structure is not a supported PE/COFF image type, then return RETURN_UNSU= PPORTED. @@ -752,7 +755,28 @@ PeCoffLoaderGetImageInfo ( ImageContext->ImageSize +=3D DebugEntry.SizeOfData; } =20 - return RETURN_SUCCESS; + continue; + } + + if (DebugEntry.Type =3D=3D EFI_IMAGE_DEBUG_TYPE_EX_DLLCHARACTERI= STICS) { + Size =3D sizeof (EFI_IMAGE_DEBUG_EX_DLLCHARACTERISTICS_ENT= RY); + ReadSize =3D sizeof (EFI_IMAGE_DEBUG_EX_DLLCHARACTERISTICS_ENT= RY); + Status =3D ImageContext->ImageRead ( + ImageContext->Handle, + DebugEntry.FileOffset, + &Size, + &ImageContext->DllCharacteristicsEx + ); + if (RETURN_ERROR (Status) || (Size !=3D ReadSize)) { + ImageContext->ImageError =3D IMAGE_ERROR_IMAGE_READ; + if (Size !=3D ReadSize) { + Status =3D RETURN_UNSUPPORTED; + } + + return Status; + } + + continue; } } } --=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 (#101940): https://edk2.groups.io/g/devel/message/101940 Mute This Topic: https://groups.io/mt/97879303/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- From nobody Fri Apr 26 06:50:03 2024 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+101941+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+101941+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1679914944; cv=none; d=zohomail.com; s=zohoarc; b=gO0unXjePm6IztHwCy1uOb9CxonuUxsi/cMs5UXUdHTQrKFXiB4Iu7PTQXB9qVt0ptxcRFFZq2rtHogUz1A8jKZG2h+GLSuAw6/x/MZO+aLHjddIQSeKwOovcIBahDyo5wJZZq3AGHNijfZiagxBDHDSw8EIldkTc4yGCTFU7IE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679914944; 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=SHVfQYh4OBkHcQq5QZelEutJ4/YHCVMkeKUeaoBlDuc=; b=iHLduTemaTInZjrxIH6mEuzqiHSPU62yZfbdgBzLxoXwSXMl9enWgW+j8sa3wi+A0AgO8FWwsp3rfGFYNi9FKZjMiqN4VQV/xz5sX8SPYaWsmVU8255BZznzaI6is8/j6h2Yw/AY9/PpGTqzVviBubf9Kjf23udG3Yq3k6dDW40= 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+101941+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 1679914944063428.69652519504393; Mon, 27 Mar 2023 04:02:24 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id DZAcYY1788612x5Jz2F55CfI; Mon, 27 Mar 2023 04:02:23 -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.32029.1679914943208577625 for ; Mon, 27 Mar 2023 04:02:23 -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 C0824611B2; Mon, 27 Mar 2023 11:02:22 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA4CDC433D2; Mon, 27 Mar 2023 11:02:19 +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 Subject: [edk2-devel] [PATCH v2 17/17] MdeModulePkg: Enable forward edge CFI in mem attributes table Date: Mon, 27 Mar 2023 13:01:12 +0200 Message-Id: <20230327110112.262503-18-ardb@kernel.org> In-Reply-To: <20230327110112.262503-1-ardb@kernel.org> References: <20230327110112.262503-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: bSfhUcRezKLjojTiopPYKC1ux1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679914943; bh=dcZWrJ46eTct7Odum0NSca3whsd3cawfqnFHgbAuT/0=; h=Cc:Date:From:Reply-To:Subject:To; b=ruS3MPwsbMd3skweQZYfXojExCCcq8EzTLIqeSgzZ2zbD24P47UN1x+ONz2f4gn9H4/ Vd/+fkX5ALmo05lN8n2K6Hq+ElovrbyRvfhrbWtSTdp6tmAPzgDhp+r4jfTL/EXYCIvCe rOR7oZ7TNNvleUdZUDswiZmsTIx/twbA5mI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679914945651100018 Content-Type: text/plain; charset="utf-8" The memory attributes table has been extended with a flag that indicates whether or not the OS is permitted to map the EFI runtime code regions with strict enforcement for IBT/BTI landing pad instructions. Given that the PE/COFF spec now defines a DllCharacteristicsEx flag that indicates whether or not a loaded image is compatible with this, we can wire this up to the flag in the memory attributes table, and set it if all loaded runtime image are compatible with it. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/DxeMain.h | 2 ++ MdeModulePkg/Core/Dxe/Image/Image.c | 10 ++++++++++ MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMai= n.h index 815a6b4bd844a452..43daa037be441150 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -280,6 +280,8 @@ extern EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformat= ion[EfiMaxMemoryType + 1] extern BOOLEAN gDispatcherRunning; extern EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate; =20 +extern BOOLEAN gMemoryAttributesTableForwardCfi; + extern EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoadModuleAtFixAddress= ConfigurationTable; extern BOOLEAN gLoadFixedAddressCodeMe= moryReady; // diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Im= age/Image.c index 8704ebea9a7c88c0..9dbfb2a1fad22ced 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -1399,6 +1399,16 @@ CoreLoadImageCommon ( CoreNewDebugImageInfoEntry (EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL, &Image->= Info, Image->Handle); } =20 + // + // Check whether we are loading a runtime image that lacks support for + // IBT/BTI landing pads. + // + if ((Image->ImageContext.ImageCodeMemoryType =3D=3D EfiRuntimeServicesCo= de) && + ((Image->ImageContext.DllCharacteristicsEx & EFI_IMAGE_DLLCHARACTERI= STICS_EX_FORWARD_CFI_COMPAT) =3D=3D 0)) + { + gMemoryAttributesTableForwardCfi =3D FALSE; + } + // // Reinstall loaded image protocol to fire any notifications // diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModule= Pkg/Core/Dxe/Misc/MemoryAttributesTable.c index e079213711875f89..fd127ee167e1ac9a 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c @@ -89,6 +89,7 @@ BOOLEAN mMemoryAttributesTableEnable= =3D TRUE; BOOLEAN mMemoryAttributesTableEndOfDxe =3D FALSE; EFI_MEMORY_ATTRIBUTES_TABLE *mMemoryAttributesTable =3D NULL; BOOLEAN mMemoryAttributesTableReadyToBoot =3D FALSE; +BOOLEAN gMemoryAttributesTableForwardCfi =3D TRUE; =20 /** Install MemoryAttributesTable. @@ -182,7 +183,12 @@ InstallMemoryAttributesTable ( MemoryAttributesTable->Version =3D EFI_MEMORY_ATTRIBUTES_TABLE_V= ERSION; MemoryAttributesTable->NumberOfEntries =3D RuntimeEntryCount; MemoryAttributesTable->DescriptorSize =3D (UINT32)DescriptorSize; - MemoryAttributesTable->Reserved =3D 0; + if (gMemoryAttributesTableForwardCfi) { + MemoryAttributesTable->Flags =3D EFI_MEMORY_ATTRIBUTES_FLAGS_RT_FORWAR= D_CONTROL_FLOW_GUARD; + } else { + MemoryAttributesTable->Flags =3D 0; + } + DEBUG ((DEBUG_VERBOSE, "MemoryAttributesTable:\n")); DEBUG ((DEBUG_VERBOSE, " Version - 0x%08x\n", MemoryAttrib= utesTable->Version)); DEBUG ((DEBUG_VERBOSE, " NumberOfEntries - 0x%08x\n", MemoryAttrib= utesTable->NumberOfEntries)); --=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 (#101941): https://edk2.groups.io/g/devel/message/101941 Mute This Topic: https://groups.io/mt/97879305/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-