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.88]) by mx.groups.io with SMTP id smtpd.web10.6361.1670604102996591403 for ; Fri, 09 Dec 2022 08:41:43 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=I5xdh6r7; 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.88, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kOreEhH5WVMgiMdtK5LlzDE0spJpQ0qA4Bq5SVteYG5BzExSQHMjiovqwiYOFkB5+ux7Q/GTGTashKDjT6ByL0dWODMYVXN96tBkQ8wcURHdC5VSbrJH/8LZtRQ18qiMNSfRKMYpxXIk8NwSg2MioklEVNMMu9biL/goBe8vvL+X6fBbzT9jge81W2esyceL0dUzzoTL0UzpzS0IyUhYzdP46N15R8Qadr1IbEJx9Mbke3EFl90QOqsVjN2Fmdv2q39OUmpUabYB+tSIwGnsMnpjWgqxzfVHIiex7xjbWlxUCqA153KuIj9uV/6dqg0vZKV6mvtb+Lm+C4waqpr5jA== 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=yYn+aDYcoImR9FaXSsqSI6KkEXcaKH1EC1tI++ScYJ8=; b=iZqz8WzLlsO3Fabqc6N9Kp6CO9+Jge8mmtf32AiPj8G1bY/rMTcPIxdTe5fps9CeO2t7c8brlXdRB+FEt8mrEibKP3CNLSAsdLYdvpQM6KLcRcrotcbdnm6mau5+K4Fvjc5MtTiZA8gdPK0xjUiftAwKqLXd7aySQ6NJ6e+4ePvJpVBEOLWlBfx/tKOFubSVF1Ru0ykckug8PhvR0w1uxnGyys5i4Szo+0RUIMTb+cCRQVfWCekANVSQH2obLJh8hVFthdlyvlr5Kuc9eO+6Vv3+EiC1BPsTf7MYSmBHWxCI0J8rru/AABy7IW6gT7o3LoxFuan/Pa7LB9C1Ug60ZQ== 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=yYn+aDYcoImR9FaXSsqSI6KkEXcaKH1EC1tI++ScYJ8=; b=I5xdh6r7VmnC3mBe45DUB07T3D1mcGzuTILGtFyonqYXKZyuojNcIgo2mBiBSHHFBf2C/HwSVMeNw4U6Q6zcOhit50SSGIKKjfmB86aA55cv/pQE0wKWPC4k+D7D5fiM8tAoonmIzjOjO1zRZV8m41kwyAxuQeXY6tNYneihj1E= 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 CH3PR12MB7762.namprd12.prod.outlook.com (2603:10b6:610:151::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.18; Fri, 9 Dec 2022 16:41:41 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::8200:4042:8db4:63d7]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::8200:4042:8db4:63d7%4]) with mapi id 15.20.5880.017; Fri, 9 Dec 2022 16:41:41 +0000 Message-ID: Date: Fri, 9 Dec 2022 10:41:39 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [edk2-devel] [PATCH] OvmfPkg/PlatformPei: Validate SEC's GHCB page To: devel@edk2.groups.io, acdunlap@google.com References: From: "Lendacky, Thomas" In-Reply-To: X-ClientProxiedBy: SA9PR13CA0052.namprd13.prod.outlook.com (2603:10b6:806:22::27) 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_|CH3PR12MB7762:EE_ X-MS-Office365-Filtering-Correlation-Id: ed347982-1bd1-4722-0d46-08dada043faa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3/kFWQqZ0c9QR1QF9EXgZ7WlFz3iGrnD08YKMt8d0rgvTO6mWdSgx6NMAH8kzrHq7t1vCRVRr+Fx4tnbv4YOiS3V0D/51y3WfumrgPdkmZxVtkBFamb4+f30IdgRzIVS/qizW5hXWIcd1LK/w4RtuuT0qW+rR7wQgbSYgh/SiaOb3GVmxA9bIOIwUpZn44ibW8+8fXRuwzLKYW1DkT3Ogr8oB5bxF6GKTw8JGlASs73rpzj/mnNvkZreOKpwYT3UfEAM7Dv4ziQO72MWVrWHjZzZyZo+xvgmmZ09skVCQTsm8lALdG2lLJNeVcDN++exapd///FYNigbZBqDsE+D/aWklZULiDs1jmn9s4tk1rg97KBK96j6mueT3X4utipVDbckbOrzz/pd9TuYRG4LTMR2v4luRqGY+DZTZJeq6d3WuiDAk+mJiwvyAJAePBxqv/mkDhE62M3T5sV8ZbRlBHfPq25uQt9wAEBuzAoFofDhwvVGptBagsYPQIm4KU2RqGGX5L/2O//DM4ZOUMGtay7jdEsnAdBt2+M+PBBJCsWqmgtygfWOSLAsVMZzid0FqRa7VO6ZmRCJZ6CY02Ipk5DssiFdNzbXiv93FnJGARZrLGFa/ncNX4rhafQw1N+Her5LG2Jj071PkPXy95r60WYl9Riv7ReWUFeFncpMUsRDJENzW+1R5FlCGmnppTMB4/N3h12/kGC2MJnURMWkFxXysfeRDgPsgrtIYGQ2t74= 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:(13230022)(4636009)(39860400002)(136003)(346002)(396003)(366004)(376002)(451199015)(31686004)(5660300002)(2906002)(15650500001)(41300700001)(6512007)(478600001)(26005)(186003)(83380400001)(66476007)(66946007)(36756003)(8936002)(8676002)(66556008)(31696002)(316002)(2616005)(6486002)(6506007)(38100700002)(86362001)(53546011)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?YzBURUR2UlhLQmxXNDlETDV0SXN1RWV5L3Uwdk03TW1CUkV0dVhlOVVZTE9i?= =?utf-8?B?M3NSVkhtTElhNG1MRHlnbmQyOThyckxkZVR6NVBIbnZwYk9mMHJlbldEQlBU?= =?utf-8?B?OEthMDJUMGFxcEJybjlhdzFpMFNuWjFpb21LZGg3bW90YmYzZWhtYzEyella?= =?utf-8?B?OTgyRit3ODl5OENpZTQvcmNNamVvN2hrMDRHS1RnN1VKWllPYzRmVGdTRUY3?= =?utf-8?B?dFRYTmdOYi8zb3FmUWszeSswMTlka08wcGd0NlAzTEQwSmZ1RUNSNEptTm5s?= =?utf-8?B?am9TYXFHek1EeXdOOXpGdUZvUjEzdGRMK1JsNTlIWUQxOStpZDd4R2YxdDFH?= =?utf-8?B?N0RRb0VDNFBOUjBuSXlBR1NzVjYzb1VlQWx3QXUyNXhUcTRua0JjeitVUUVG?= =?utf-8?B?aDJpZXJkSG5iS0lxeTNZdHM2TSt2aFlWTXN1YmgrT1pmd3lMeXA5cEp2eDA0?= =?utf-8?B?aVMxLzF4cE9UcGdmQ0U0UmZ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0MrOUVtWndnZHJOQzV2aUVYNnRVYjZUaFJoeUM4N1VuZHFYY1Qz?= =?utf-8?B?bzZ5NE9Yd0t6TjNCZnZEQWcxTTQ4TDZBamtMMkxrckQrcjRhVEx1Wnc2cEZj?= =?utf-8?B?L0QxZmFOOXNCRXVlMzlYeHY4NEtqT21MdUkzUUZzMFhSZndwRVpCWTJDenNn?= =?utf-8?B?MzRoOVRZUStTNFZ2S3pRV3paNVZZTllaL2N3Ukt1TWhxem5BOXd4N052V1J4?= =?utf-8?B?MmpWQWxHVGw4dXRRKy8yYkdTZmdIUVN3MmRjTDFtNlJReTZhc2Vtc21NeDNt?= =?utf-8?B?bXZHUnlINUpQek5yYjVBalNmeFp4aUJqbjZQSGdZa3c0cnhuZFpTRU9FSEY1?= =?utf-8?B?ZkdpMkl1NDRpVkJpQXdjNk16cndnQVZMK3NkMlBVS2J3cUNxTjEvc2txNXpE?= =?utf-8?B?QUF0WGxITmdZRkJBV3BpT2s1NDh6bDc1MVpuSGNaQ0gxemFTUkZWdHE0ZkVm?= =?utf-8?B?RExnRCtiODd5NEdsV3NxdWFCazNlRW1DdUZQNjYyMkpWMFRNNWNZQVlOWEVX?= =?utf-8?B?MmRjUDlaZE8zTHFLKzVPMEtEMGNOMEppQ2tqeHQ4MVg4dXl0RytLY0xLaHQ5?= =?utf-8?B?STJ3bTBiSy8yL2dibW8xaDhsTGhwcm5xbVBwaXFpVFFKNE84UUZDNW85dUI3?= =?utf-8?B?YW1FOGNVQ2piUjl4TnQrZFBXeW5LRjdhK3IxcmxSejUrRkNKdWM2WDFFakdy?= =?utf-8?Q?8uuApRgccAhl+Nv30g0nkUs/o?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed347982-1bd1-4722-0d46-08dada043faa X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2022 16:41:41.0898 (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: e+lVkkhoajEnrXOf2LP6C+Fgeqm626ECq3j1RVcoNh0c90eEO46AIcItf0ENK+lZJ0COAFvDitdHmx7FiCjPdA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7762 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit In the future, please include the reviewers on cc: that are identified in the Maintainers.txt file (use ./BaseTools/Scripts/GetMaintainer.py), I almost missed this patch. On 12/8/22 17:43, Adam Dunlap via groups.io wrote: > When running under SEV-ES, a page of shared memory is allocated for the > GHCB during the SEC phase at address 0x809000. This page of memory is > eventually passed to the OS as EfiConventionalMemory. When running > SEV-SNP, this page is not PVALIDATE'd in the RMP table, meaning that if > the guest OS tries to access the page, it will think that the host has > voilated the security guarantees and will likely crash. > > This patch validates this page immediately after EDK2 switches to using > the GHCB page allocated for the PEI phase. > > This was tested by writing a UEFI application that reads to and writes > from one bytes of each page of memory and checks to see if a #VC > exception is generated indicating that the page was not validated. > > Signed-off-by: Adam Dunlap This should include a Fixes: tag. > --- > OvmfPkg/PlatformPei/AmdSev.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c > index e1b9fd9b7f..c465732068 100644 > --- a/OvmfPkg/PlatformPei/AmdSev.c > +++ b/OvmfPkg/PlatformPei/AmdSev.c > @@ -206,6 +206,7 @@ AmdSevEsInitialize ( > { > UINT8 *GhcbBase; > PHYSICAL_ADDRESS GhcbBasePa; > + PHYSICAL_ADDRESS PrevGhcbPa; > UINTN GhcbPageCount; > UINT8 *GhcbBackupBase; > UINT8 *GhcbBackupPages; > @@ -293,8 +294,24 @@ AmdSevEsInitialize ( > GhcbRegister (GhcbBasePa); > } > > + PrevGhcbPa = AsmReadMsr64 (MSR_SEV_ES_GHCB); In general, I don't think this is necessary. There is only one path into this function and no matter what, the SEC GHCB address must be used. > + > AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa); > > + // > + // Now that the PEI GHCB is set up, the SEC GHCB page is no longer necessary > + // to keep shared. Later, it is exposed to the OS as EfiConventionalMemory, so > + // it needs to be marked private. The size of the region is hardcoded in > + // OvmfPkg/ResetVector/ResetVector.nasmb in the definition of > + // SNP_SEC_MEM_BASE_DESC_2. > + // > + ASSERT (PrevGhcbPa == FixedPcdGet32(PcdOvmfSecGhcbBase)); Again, I don't think this is necessary. > + > + ASSERT_RETURN_ERROR(MemEncryptSevSetPageEncMask( I find this hard to read. Please be consistent with what is currently done in the file/function and rename the DecryptStatus variable to just Status and do: Status = MemEncryptSevSetPageEncMask ( 0, ... ASSERT_RETURN_ERROR (Status); (And notice the space between the function name and the opening "(") > + 0 /*Cr3 -- use system Cr3*/, Coding standards should have the comma after the 0 and the comment aligned out to the longest parameter and using //. See other examples in the file. > + PrevGhcbPa, Please use FixedPcdGet32(PcdOvmfSecGhcbBase) here. > + 1 /*Number of pages*/)); The closing ");" must be on a line of its own. Thanks, Tom > + > // > // The SEV support will clear the C-bit from non-RAM areas. The early GDT > // lives in a non-RAM area, so when an exception occurs (like a #VC) the GDT