From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.43]) by mx.groups.io with SMTP id smtpd.web11.2897.1685559841737913286 for ; Wed, 31 May 2023 12:04:02 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=TSrVxFTw; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.92.43, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VQW0ZIrD9v+MNmkqusbTKAlnbxZikCjV0x0r084HE5I3QqIv8UKsAVGhUoXQNL24na/91Gqi2qKEAS9gCm7Pt5T8P6qgI8uiR/JXFJ8ORYEKgcfpQsnT8NK6CBd7li3CWH5yrGW8SOL680BY+KUnQ0vhU3ZxLRQ90q+KqKlL3uTFeopDGJBQGyGmU6sdceCnpeJatXdbmsw7+m/rVvyA1Le/6SQQJ03lUpwsW1vlxUA2A3wN8zj2E4z+5dbBJ9X3Hk5SXO4fnLDAy7tTWbhMW81c8J6Wq1cnD0OyAYcimxfsWSRQqGxim+YvtrkxfpEzQcjpJx7YeUG3+TZlehENMA== 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=+4NQYgt8Ab8JdxlQl8xBuTBRc+dAM1hY/gj5oecwA+o=; b=IDY/AuvSUwQkDpSDrja+L6E/oKLk1sUU6ETp//udOhrB+c5AfI2dKC3s0cpwbCVimeLM5Rcy7ywEURsbwXF+Zu+kpqq9EuBAh2PFfJgpE1onwm98B+pFuneXlJyIB66jS+HK2fqzz3v5uZooyFfhTl8NzM+FWAE2H8RUU1L+jJHLlFZXHa5ejIrvviUiFuxfNUyPFPK0xuywW+w6p5WMF3KnBmjyGTgLX+ThkGYITB99l7mNF/B1gxY7SLA6+GahPh3BY8nNCuhZaKRHqqPhHuBZrwfaPoSarLh/PgZ6DjphhC9Ti4JEGG/TlsJQ6RYtVuPnsqEekdLEyfMUq7EGlw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+4NQYgt8Ab8JdxlQl8xBuTBRc+dAM1hY/gj5oecwA+o=; b=TSrVxFTw5gr0x1oQ8bLVjZBcNpyfgaUNQiILzr0uwhlmgY6uVR0H3Hl1tLpLYxqlYRvwfDFh3FZkdtacT5XEU4SW9gKdDQsowXC8/Al9uzM86+jI0a1dOK2e0cNMl5KOSHgnZzu3Qs75khBbdgoFT5sMtiJoyl/+0BWSr7qIOFg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) by IA1PR12MB8357.namprd12.prod.outlook.com (2603:10b6:208:3ff::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Wed, 31 May 2023 19:03:59 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::61f6:a95e:c41e:bb25]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::61f6:a95e:c41e:bb25%3]) with mapi id 15.20.6455.020; Wed, 31 May 2023 19:03:59 +0000 Message-ID: <405e7f96-c06b-b905-0be9-16003f75ffb7@amd.com> Date: Wed, 31 May 2023 14:03:56 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [edk2-devel] [RFC PATCH 09/10] MdeModulePkg/DxeIpl: Use memory attribute PPI to remap the stack NX To: devel@edk2.groups.io, ray.ni@intel.com, "Tan, Dun" , Ard Biesheuvel , Abner Chang Cc: "Yao, Jiewen" , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , "Bi, Dandan" , "Gao, Liming" , "Kinney, Michael D" , Leif Lindholm , Sunil V L , "Warkentin, Andrei" References: <20230525143041.1172989-1-ardb@kernel.org> <20230525143041.1172989-10-ardb@kernel.org> From: "Lendacky, Thomas" In-Reply-To: X-ClientProxiedBy: DS7PR03CA0095.namprd03.prod.outlook.com (2603:10b6:5:3b7::10) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) Return-Path: Thomas.Lendacky@amd.com MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5229:EE_|IA1PR12MB8357:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f246b56-c7e0-4c33-9cea-08db6209ca1b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vhK3c6WoHlgf4lOeptYd8d95+8QqCaoRFiT8WC1p/f8Jb3XfASn4hWt63pyM8i1ZIZQXLbTNtenFNyqqwFXeXmWydA4shdiskgYywhOdmBAOxiIHfrw59j6nceyAjQ+Izs1gcuYC1Ao/fQ3EtUAgLcyvzHJjHvA/Utd4CGFG4cKW03vb6FXFRJqVdaQaSd0/HFkhCfw0YG4Pc9ItlU3evWfEZox222e8vj+gHuxSbF7ZMvKLExXWp87lhnQfzkoq3PKkriWQ9tJdlXW4MGQHv1aBr4j7tQYZaJNlKR1IuUuLuQfrUcDhPCbISxEZBAfwd22sKW+xqDBL1W4tu1DstdsukYPVr+b92tSX6Ep8q9twgL/CvXaSEo9gCwJjUACaO3Y8aZnt+ZWgnRPm2VkfsfQBbfysid9Ftt630pcjCW9q+592iC2Zn0Y8QVxdsow+6CzxzVyOVlvooGNIg3Z1YkLhFJvVkn0l4kILQqbqDp4uWRUVlu6F1wzC6l+SnGibsDzgXHGEPXaVVYcj1VyArqTkl1swsQKkmkwxHvR8zMHkMvz2w2w8ogPkHlqS7Xs7B7D5wVNIZFlmTRSmHEB/wBQogu2Pmh92VLpzK3Nr6I1jIEIttKmTKU6UP39tVDUS58lfuEAkuxhCqayIQIzR4Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR12MB5229.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(366004)(346002)(396003)(136003)(376002)(451199021)(38100700002)(31686004)(41300700001)(316002)(6512007)(6666004)(31696002)(4326008)(6636002)(8676002)(6486002)(2906002)(8936002)(86362001)(7416002)(66556008)(66946007)(2616005)(53546011)(66476007)(36756003)(54906003)(110136005)(6506007)(26005)(83380400001)(966005)(478600001)(66899021)(5660300002)(186003)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MUNGdXVmWE5QSGkvRDErT1J6RUgyYkhScFBTRFN3QU80cWxuMm9ZRWZVVEhP?= =?utf-8?B?UXd2TTZtUmY3ZUdWWGs2TUlzSWplOXExUkp3TmVGYnQ4Y2dUR2JjMVhhS0lO?= =?utf-8?B?cG5UUEhNK1JYUUd6RERkWDl4cHNNdCtJeFdjZkhaMWNTMTNWVUZReEpnZ1h2?= =?utf-8?B?OXlVenIxSER6NWlIRVdkQk5PcitJakRwL05jSTU1dnZadHJGR1RIRFZDSGM2?= =?utf-8?B?S1NJSSs0MlR1TlBubktlQ1FsL2FKSWNGc1dva1NFQU91VHl6Q1RtVXN5VkEr?= =?utf-8?B?QS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senpza1lvdndobjZDME94?= =?utf-8?Q?myyH7cCTobGvQIU4qhiWFHVpf?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9f246b56-c7e0-4c33-9cea-08db6209ca1b X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2023 19:03:59.0078 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SSuwTuEv2nNkLAySM92Y0tCh8YaTmjG471byblThqBiQwuMwc2JqxCKJ/TroBoOlcW+ofHlKfON3HvuCdEGidA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8357 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/30/23 20:29, Ni, Ray via groups.io wrote: > +@Abner Chang and @Tom Lendacky > >> -----Original Message----- >> From: Tan, Dun >> Sent: Tuesday, May 30, 2023 6:25 PM >> To: Ni, Ray ; Ard Biesheuvel ; >> devel@edk2.groups.io >> 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 >> >> Ray, >> I think using MemoryAttribute PPI also looks good for X64 DxeIpl. >> The only question that comes to my mind is the AMD sev feature. Since the >> MemoryAttribute can't handle the AMD sev feature requirements(remapping >> ghcb range from non-1:1 mapping to 1:1-mapping), we may need to find an >> appropriate place to remap the Ghcb range. I'm not sure I follow. How and where would the PPI be used? And what is meant by "remapping the ghcb range from non-1:1 mapping to 1:1 mapping? Thanks, Tom >> >> Thanks, >> Dun >> >> -----Original Message----- >> From: Ni, Ray >> Sent: Tuesday, May 30, 2023 3:19 PM >> 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 >> >> 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, >>> Jiewen ; Gerd Hoffmann ; >>> Taylor Beebe ; Oliver Smith-Denny >>> ; Bi, Dandan ; Gao, Liming >>> ; Kinney, Michael D >>> ; Leif Lindholm >>> ; Sunil V L ; >>> Warkentin, Andrei >>> Subject: [RFC PATCH 09/10] MdeModulePkg/DxeIpl: Use memory attribute >>> PPI to remap the stack NX >>> >>> 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. >>> >>> Signed-off-by: Ard Biesheuvel >>> --- >>> MdeModulePkg/Core/DxeIplPeim/DxeHandoff.c | 29 >> ++++++++++++++++++-- >>> MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 5 +++- >>> 2 files changed, 30 insertions(+), 4 deletions(-) >>> >>> 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. >>> >>> >>> >>> Copyright (c) 2006 - 2018, Intel Corporation. All rights >>> reserved.
>>> >>> +Copyright (c) 2023, Google, LLC. All rights reserved.
>>> >>> SPDX-License-Identifier: BSD-2-Clause-Patent >>> >>> >>> >>> **/ >>> >>> >>> >>> #include "DxeIpl.h" >>> >>> >>> >>> +#include >>> >>> + >>> >>> /** >>> >>> Transfers control to DxeCore. >>> >>> >>> >>> @@ -25,9 +28,10 @@ HandOffToDxeCore ( >>> IN EFI_PEI_HOB_POINTERS HobList >>> >>> ) >>> >>> { >>> >>> - VOID *BaseOfStack; >>> >>> - VOID *TopOfStack; >>> >>> - EFI_STATUS Status; >>> >>> + VOID *BaseOfStack; >>> >>> + VOID *TopOfStack; >>> >>> + EFI_STATUS Status; >>> >>> + EDKII_MEMORY_ATTRIBUTE_PPI *MemoryPpi; >>> >>> >>> >>> // >>> >>> // Allocate 128KB for the Stack >>> >>> @@ -35,6 +39,25 @@ HandOffToDxeCore ( >>> BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE)); >>> >>> ASSERT (BaseOfStack != NULL); >>> >>> >>> >>> + if (PcdGetBool (PcdSetNxForStack)) { >>> >>> + Status = PeiServicesLocatePpi ( >>> >>> + &gEdkiiMemoryAttributePpiGuid, >>> >>> + 0, >>> >>> + NULL, >>> >>> + (VOID **)&MemoryPpi >>> >>> + ); >>> >>> + ASSERT_EFI_ERROR (Status); >>> >>> + >>> >>> + Status = MemoryPpi->SetPermissions ( >>> >>> + MemoryPpi, >>> >>> + (UINTN)BaseOfStack, >>> >>> + STACK_SIZE, >>> >>> + EFI_MEMORY_XP, >>> >>> + 0 >>> >>> + ); >>> >>> + ASSERT_EFI_ERROR (Status); >>> >>> + } >>> >>> + >>> >>> // >>> >>> // Compute the top of the stack we were allocated. Pre-allocate a >>> UINTN >>> >>> // for safety. >>> >>> 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 >>> >>> gEdkiiPeiBootInCapsuleOnDiskModePpiGuid ## SOMETIMES_CONSUMES >>> >>> gEdkiiPeiCapsuleOnDiskPpiGuid ## SOMETIMES_CONSUMES # >> Consumed >>> on firmware update boot path >>> >>> + gEdkiiMemoryAttributePpiGuid ## SOMETIMES_CONSUMES >>> >>> >>> >>> [Guids] >>> >>> ## SOMETIMES_CONSUMES ## Variable:L"MemoryTypeInformation" >>> >>> @@ -117,10 +118,12 @@ [Pcd.IA32,Pcd.X64] >>> gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize ## >> CONSUMES >>> >>> >>> >>> [Pcd.IA32,Pcd.X64,Pcd.ARM,Pcd.AARCH64] >>> >>> - gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## >>> SOMETIMES_CONSUMES >>> >>> gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## >>> SOMETIMES_CONSUMES >>> >>> gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## >>> SOMETIMES_CONSUMES >>> >>> >>> >>> +[Pcd] >>> >>> + gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## >>> SOMETIMES_CONSUMES >>> >>> + >>> >>> [Depex] >>> >>> gEfiPeiLoadFilePpiGuid AND gEfiPeiMasterBootModePpiGuid >>> >>> >>> >>> -- >>> 2.39.2 > > > > > >