From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.4431.1685431178920318589 for ; Tue, 30 May 2023 00:19:39 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=a9dfphLm; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685431178; x=1716967178; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=w6niQduwhfYI90BYyOorqOq2EINzp5xgZsS8hCS77rw=; b=a9dfphLmIMFAtC0wFKwOU8Xc2uQbutzYJL/ER22ajLyqrTs46SpQYojw x/zQXTfJ+U3hkRtX6FnJ4T7F/geldBqUODoTDcNTCZeDOToyJ5gAXudfy vYWk9GeFqQftb03eBbL/9hVA4qrCNf8nf6UH4Utf7FJfsj3fBbLi7MCk3 j1f9ZnRqipb1HktoABG1uTUWVsyhXx7Z8GuuWKFIoiUxHAujHVY7z2iYN CTCJiCdkC504SpMkAtZO2MnL8laEVSqx44tR4Qw0AEpVNWGvS0ukDJoct MnIevhmMdwOfIJycEZXALB++I1U0908/5eDzZVPDqo5nMifdDsOk5F8TV A==; X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="335186516" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="335186516" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2023 00:19:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="656730338" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="656730338" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga003.jf.intel.com with ESMTP; 30 May 2023 00:19:24 -0700 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 30 May 2023 00:19:24 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Tue, 30 May 2023 00:19:24 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.172) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Tue, 30 May 2023 00:19:22 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kz2DPPeXTJrD2gKPG7W1iYnBYqaRUaMch4BS7pUXzOBLp6HNUktAFNjSFfTvF+aPLgWsQSIUyv2Mz3TyrLipYaQLpRoB44IyreSsCEvLQGlhShEWEQmKCbPAVTdo4DCSBcOj/AlywoaH6zS2qug9ixkx1CM/L/IBAiLYo07tGiOg/haYqQ7sL/xTCm1MIeyFgRpczuCp3h91yhnBZ0XcjQaj8x6KszxSYXgwmRsOeJ5ppK441EhfJ84gwOP7LWqb/kE/cygQZ8Pb/id8BPdhnZDz//mD7xwnJ7OitMD2T57Qshv9hz1Xa2xVgjcHjeq5+32M3yeEhi0UcFK54pqhOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sd/vLkrYxPU6XP2LsM6v62iFFozpVVuF5ZbvveyIQuc=; b=DXLOuSTIEURx4YHgj9Y3FJPg/hQR+KS+6MZCw3gF9+4/x1TgH+LMFhgun+JdPAWozsPuEmnd0W0iXGY43w2kIT1nyxCgpGWHlGL43pBK9zSGEIwdlWsxhK0MmdlqmtuZwwRjwa5tavRnEOkKbwemMCYAFeExU8PWMKsBM/dUyh0n79TSJD7c6y9AIooSggtVjB1oi2xEeBPWApDPuH2U5ZZ+P+RWk9owwZ6UPK9tm90a1+z2M+EicyrN0ezC8tjHlylCXJulKgcLTqkaVc8YmpLSWzyQHA9yps3nM+Kp6pzImv05yiss0NfY/aLUbn/Chwxibu6ND0osLg+UNadn4w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by SA2PR11MB5035.namprd11.prod.outlook.com (2603:10b6:806:116::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 07:19:14 +0000 Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d%5]) with mapi id 15.20.6433.018; Tue, 30 May 2023 07:19:14 +0000 From: "Ni, Ray" To: Ard Biesheuvel , "devel@edk2.groups.io" , "Tan, Dun" CC: "Yao, Jiewen" , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , "Bi, Dandan" , "Gao, Liming" , "Kinney, Michael D" , Leif Lindholm , Sunil V L , "Warkentin, Andrei" Subject: Re: [RFC PATCH 09/10] MdeModulePkg/DxeIpl: Use memory attribute PPI to remap the stack NX Thread-Topic: [RFC PATCH 09/10] MdeModulePkg/DxeIpl: Use memory attribute PPI to remap the stack NX Thread-Index: AQHZjxWqFRCsFExerEudWMuzKoyfPq9yb5cQ Date: Tue, 30 May 2023 07:19:13 +0000 Message-ID: References: <20230525143041.1172989-1-ardb@kernel.org> <20230525143041.1172989-10-ardb@kernel.org> In-Reply-To: <20230525143041.1172989-10-ardb@kernel.org> Accept-Language: en-US X-Mentions: dun.tan@intel.com X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|SA2PR11MB5035:EE_ x-ms-office365-filtering-correlation-id: ade71a5d-68da-49fd-3ecf-08db60de2bfc x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ou21RfQZ4YAAmieV4eaYZjiwRUtgu2nmw4rxRb5xr8q/v8xbsjwkRa3RQBymCGxWuUsbHhvTmY/Embp4ULKIyJoBc2OVbZo5z3nS07Aq3Qw637jzltdGDlVXOzHCHdR/Jb5Oi8ZvzrfktE5hHOA34c5FccRa/4VbBTjTlX6snt9wfR2bXlA7b7vff2hk9fC5gVEbJPuVHmFQ4xff8SVTj8CkqVV4CbJ3hvKgy31B5foYhSsUGIa4XnjECIhRNBCSjDHxI9VHmaDMh/LAXEbsLZf86Rz4o8GsWLQrLaInhb6gSTJz7THp5cT5Jajnah9Nazt8nEdoFSA0Pi2Yw+TsdsMN13Dht1oHr1VI6vye1djmkb+mE8OVShqiwckiysaI0MKbYt8ecvw5f+3TIuc7qzd2G4RkRs++7+w82jItRsf726mtlcX9vw7U34Eq41FSsen9/JFWmXuyXJ6SjEQAvC1Sti4DxFSvSPFXa83saNnDzlsjqzaCEvbI4g4IUUea+z+svpHctAnckSkMggLYmUTtt/I8iVPd4IjAwOxohyv3ETsCzKmpJrbg9FyMrI7uia3Hm+kn9zKuk65BYgLlBQo1Cdi1b4b4IVVAGsnznhWKDAo/Z5uUNAlV5Vnx3wUF x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN6PR11MB8244.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(396003)(346002)(376002)(39860400002)(366004)(136003)(451199021)(478600001)(66446008)(64756008)(76116006)(66946007)(66556008)(66476007)(110136005)(54906003)(6636002)(4326008)(316002)(86362001)(33656002)(83380400001)(9686003)(6506007)(53546011)(26005)(186003)(107886003)(41300700001)(8676002)(8936002)(2906002)(52536014)(7696005)(71200400001)(5660300002)(55016003)(38100700002)(38070700005)(122000001)(82960400001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?BkXjwN3JOP9G+MCqeiyVilWkvJhLpXlGhLetz3K5gIFCE8G2/4S7GKf7vIvr?= =?us-ascii?Q?YSB+f1HYcAbcLoc7imgXDwVJLUbmGH6slnqUKmM1UkPSbGPz5tpif5PiMjQa?= =?us-ascii?Q?rgyycQMwA1Y50hR+82Kt8lBnQrEpXB+AE73baRlKcF3rk4V0W26wrQjk6pbz?= =?us-ascii?Q?r5sIrcZjNSIOzHAyR7+FydlS+DzyJvbPWoLAAJ59eYqiFzcLMF0jwpeb6DQg?= =?us-ascii?Q?QQ+Et3pmjUhUbFiNz/sqFZtzZONR0MvKN6TMCOZNj5GOw6zkujhd/G2nJ6ra?= =?us-ascii?Q?p4gejCta1tVNXnUxV8mSb3eh/IepOl6lrCXBhjXN6eSTfEnVgcPTE1okr3aa?= =?us-ascii?Q?ktnak6hEl5VgvcXWPIfWVsTGVmkcKspjCAYTFMSUqa8UgQKPaa4BCEfqfGW7?= =?us-ascii?Q?4tlRW3galoSgfpe4pr7RUlttZT4VIG710y+CqejWyUyuPB/sgtqbKu/UIgL/?= =?us-ascii?Q?x3Nj5Y7OjDOUcjy0QHIrTA1oSqsx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RdaQPvVtMUW4XGzDZKHs3FTrYE1jzROjTF+7cmlfiyiibiphxWku?= =?us-ascii?Q?idt8+I4brjzOwco6vyI4mAaDhrYejyu0CpAZlmAgHRWdKjTcX4XwKMc7Codp?= =?us-ascii?Q?BjLJgs6stJj81rrtwWVo2DXBi9YP9/Y7NKTFm8IRI+0UYiXftMViDTl8ISku?= =?us-ascii?Q?qDf3BWZ2Ekjf/J7/ETk=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ade71a5d-68da-49fd-3ecf-08db60de2bfc X-MS-Exchange-CrossTenant-originalarrivaltime: 30 May 2023 07:19:13.9708 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: nXGgL4/h9ml8spRmbeDaxafOurnR35HRCtCowyOkCzjFZ8FG7vmvanh0gPVcurGzz2XWNLfNkvT87v6kB5VaHg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR11MB5035 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Looks good. @Tan, Dun, can you please evaluate if using MemoryAttribute PPI, what opens= will there be for X64 DxeIpl? > -----Original Message----- > From: Ard Biesheuvel > Sent: Thursday, May 25, 2023 10:31 PM > To: devel@edk2.groups.io > Cc: Ard Biesheuvel ; Ni, Ray ; Yao, Ji= ewen > ; Gerd Hoffmann ; Taylor Beebe > ; Oliver Smith-Denny ; Bi, Dandan > ; Gao, Liming ; Kinney, > Michael D ; Leif Lindholm > ; Sunil V L ; Warken= tin, > Andrei > Subject: [RFC PATCH 09/10] MdeModulePkg/DxeIpl: Use memory attribute PPI = to > remap the stack NX >=20 > If the associated PCD is set to TRUE, use the memory attribute PPI to > remap the stack non-executable. This provides a generic method for doing > so, which will be used by ARM and AArch64 as well once they move to the > generic DxeIpl handoff implementation. >=20 > Signed-off-by: Ard Biesheuvel > --- > MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c | 29 ++++++++++++++++++-- > MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 5 +++- > 2 files changed, 30 insertions(+), 4 deletions(-) >=20 > diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c > b/MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c > index a0f85ebea56e6cba..22caabb02840ba88 100644 > --- a/MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c > +++ b/MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c > @@ -2,12 +2,15 @@ > Generic version of arch-specific functionality for DxeLoad. >=20 >=20 >=20 > Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
>=20 > +Copyright (c) 2023, Google, LLC. All rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > **/ >=20 >=20 >=20 > #include "DxeIpl.h" >=20 >=20 >=20 > +#include >=20 > + >=20 > /** >=20 > Transfers control to DxeCore. >=20 >=20 >=20 > @@ -25,9 +28,10 @@ HandOffToDxeCore ( > IN EFI_PEI_HOB_POINTERS HobList >=20 > ) >=20 > { >=20 > - VOID *BaseOfStack; >=20 > - VOID *TopOfStack; >=20 > - EFI_STATUS Status; >=20 > + VOID *BaseOfStack; >=20 > + VOID *TopOfStack; >=20 > + EFI_STATUS Status; >=20 > + EDKII_MEMORY_ATTRIBUTE_PPI *MemoryPpi; >=20 >=20 >=20 > // >=20 > // Allocate 128KB for the Stack >=20 > @@ -35,6 +39,25 @@ HandOffToDxeCore ( > BaseOfStack =3D AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE)); >=20 > ASSERT (BaseOfStack !=3D NULL); >=20 >=20 >=20 > + if (PcdGetBool (PcdSetNxForStack)) { >=20 > + Status =3D PeiServicesLocatePpi ( >=20 > + &gEdkiiMemoryAttributePpiGuid, >=20 > + 0, >=20 > + NULL, >=20 > + (VOID **)&MemoryPpi >=20 > + ); >=20 > + ASSERT_EFI_ERROR (Status); >=20 > + >=20 > + Status =3D MemoryPpi->SetPermissions ( >=20 > + MemoryPpi, >=20 > + (UINTN)BaseOfStack, >=20 > + STACK_SIZE, >=20 > + EFI_MEMORY_XP, >=20 > + 0 >=20 > + ); >=20 > + ASSERT_EFI_ERROR (Status); >=20 > + } >=20 > + >=20 > // >=20 > // Compute the top of the stack we were allocated. Pre-allocate a UINT= N >=20 > // for safety. >=20 > diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf > b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf > index 60c998be6c1bad01..7126a96d8378d1f8 100644 > --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf > +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf > @@ -91,6 +91,7 @@ [Ppis] > gEfiPeiMemoryDiscoveredPpiGuid ## SOMETIMES_CONSUMES >=20 > gEdkiiPeiBootInCapsuleOnDiskModePpiGuid ## SOMETIMES_CONSUMES >=20 > gEdkiiPeiCapsuleOnDiskPpiGuid ## SOMETIMES_CONSUMES # Consu= med > on firmware update boot path >=20 > + gEdkiiMemoryAttributePpiGuid ## SOMETIMES_CONSUMES >=20 >=20 >=20 > [Guids] >=20 > ## SOMETIMES_CONSUMES ## Variable:L"MemoryTypeInformation" >=20 > @@ -117,10 +118,12 @@ [Pcd.IA32,Pcd.X64] > gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize = ## CONSUMES >=20 >=20 >=20 > [Pcd.IA32,Pcd.X64,Pcd.ARM,Pcd.AARCH64] >=20 > - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## > SOMETIMES_CONSUMES >=20 > gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## > SOMETIMES_CONSUMES >=20 > gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## > SOMETIMES_CONSUMES >=20 >=20 >=20 > +[Pcd] >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## > SOMETIMES_CONSUMES >=20 > + >=20 > [Depex] >=20 > gEfiPeiLoadFilePpiGuid AND gEfiPeiMasterBootModePpiGuid >=20 >=20 >=20 > -- > 2.39.2