From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 227D6AC16B3 for ; Wed, 15 Nov 2023 17:54:41 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=rbsDxcJ0tp3lG/k94R5gGy/o38RW8ZFtHdzEt0Os5PQ=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1700070880; v=1; b=lOaJ3/6cAHyitvGfu1EzAOafiQz5WZzjnKb4y9mtPEo/45kMokVtm41J0Db7Rq6Hian/J2Rq wJndxxlrZYLqmaz+dWNJLrK+i+KKAsa1qHdf8sU/RCPTX1nNrqBudDL7hJVh/TZJFeoVH6D3wcA PlK8TuE77BXFKH2IW9pU9xXM= X-Received: by 127.0.0.2 with SMTP id SWe2YY7687511xtMNbWhZivM; Wed, 15 Nov 2023 09:54:40 -0800 X-Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.73]) by mx.groups.io with SMTP id smtpd.web11.20097.1700070880026201420 for ; Wed, 15 Nov 2023 09:54:40 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lIhtUTlbdARcnKhrBeyETHXqrt7Et/Ra9Qg5uhl+uP0GfjaVXz5T9ya89QxQpvynjIkPOlTDHt0CrUWRESHRnKexTkzqJfv83KRximlo2Zu7TXwuudR7rka/yczQoqGryPxfpcz7iXPBMi+L7tztT+bE958mjHr6HNfaoZ1OY0IBK41XZPhFqrU0CqDTPtFTvXpV0lnWcvkOY7AT4rSD8ltXDaabMLVl1QTQo5DvoLdagJTeUkjBP8vaT19mG2hl5R7IBLQMXn2rQIDgKKg4z7s1XMJu4krBIC2EsbNptSMLElRfDbkOHCxch5iPscbZyzivalNZcdtS/POgSsmY/g== 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=1WKnmPHBKLZs0JLE4LDIOJm5+PaoeAQrJHCMN4kXfXk=; b=KKehakm8GSnb/3X7K6PQIfO9aFvc8g8DGfm+dyzTJi0rz0BR9LecKkUUu1kvC9/3uBPqWu61qYoXAFU9eJyqNK3jW40cX3mWUDDN9p/8OlYtRaC0JmACVi6SPCGivHrygy5PO4w7sUAlKVPLg+qKJvaVxQiWq6sbdQlI93OHF/4UI8r2M6le8J789OudaHe8tnxpIzJtJRw9KvhaBRxsbJShsr+7PekBABmi732V1XeLSC8IlNGr8ibGhqDREDpP1IveSIwnTyhrgbnn2XdMsxCaFgV+IogAPAgipoV9eGX1V30GJcyL0hi5Vl0X4qB1ypGsnsW/fD59jN4bEhwACg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) X-Received: from CH2PR10CA0026.namprd10.prod.outlook.com (2603:10b6:610:4c::36) by DM6PR12MB4187.namprd12.prod.outlook.com (2603:10b6:5:212::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.20; Wed, 15 Nov 2023 17:54:36 +0000 X-Received: from DS2PEPF0000343F.namprd02.prod.outlook.com (2603:10b6:610:4c:cafe::d4) by CH2PR10CA0026.outlook.office365.com (2603:10b6:610:4c::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.17 via Frontend Transport; Wed, 15 Nov 2023 17:54:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by DS2PEPF0000343F.mail.protection.outlook.com (10.167.18.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7002.20 via Frontend Transport; Wed, 15 Nov 2023 17:54:36 +0000 X-Received: from localhost (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Wed, 15 Nov 2023 11:54:35 -0600 From: "Roth, Michael via groups.io" To: CC: Gerd Hoffmann , Ray Ni , Erdem Aktas , Jiewen Yao , Min Xu , Tom Lendacky Subject: [edk2-devel] [PATCH v2] OvmfPkg/MemEncryptSevLib: Fix address overflow during PVALIDATE Date: Wed, 15 Nov 2023 11:51:53 -0600 Message-ID: <20231115175153.813213-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF0000343F:EE_|DM6PR12MB4187:EE_ X-MS-Office365-Filtering-Correlation-Id: 4f87a4bc-0f82-4077-9217-08dbe603eea4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: fKy+x1k9hDE6qhOl/Krl3Nvc0g3mnCI+7nnCnwrfsaBe3xzMogIgexlzMZREw27+OYBrvcydV2D3NdPGyvTk9u7XhlgRY8Oa1upJXCej9agXVtM2Ulq5U2L1fk3+w37JeYsrUByHcUbn4HqKYR1wgIPhv1pvtmT5e1T2FncnWvPacW4ICN6eZ8+hzj34+Ce8c2MuZv5ZDj2WycBc4Wp+8C6Du7JtJd0Y9GCNfLNxO0aETNKpV2y2EyrDhlr61+1kJew582IE0SWP3nqZqPfvEQnXKQN4hQ8w99JKib2CFXSg/RlYldaUWTSrf6D9iKSZowx5sMDNC9XbrvK/xeqyuVejcc9gPTe3X8NaVV5+JW3Nt8Zr8uRNllu+RIIrUz+3BHhmyMUx2oDrC6b3dCw8k6C+PEkGg0KnZHPbfdy7GTfrQRIv1xTk+MuLjZf63ZRrvUSP+KTnIMJBwYiF0pSF/XFMkOQV52XoyUxIqoTVsYgWI9TANIc9fwVuxr07biAjMB9I6qAEuPmnW9RzYg5rqmEZXvjwpxSAk9H+JYJHsurHC1UMfwIw1LcN5gL23mftzRqjQ3ZAND+EUYfUaB6sjFVzTY10bOy8bm5iLe2db74A7Cisil8c7S+CEBAnl5ZXnwN9dQhZ2inSa0iiB1uQOKpf/qsrtN4i2KTdYUvikYvDlwyfcEkRUo/5gz+OYRIExs7TS/75nnsBVeRkmM3kAD/E22afJqR/H9+nlzPDTT3dBwmpn6i7WI1ZosUC9djqWMUpMNACDHBkHVFvPW/blw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2023 17:54:36.4860 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4f87a4bc-0f82-4077-9217-08dbe603eea4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF0000343F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4187 Precedence: Bulk 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,Michael.Roth@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 1E3BYEwM16vsQPHgytWEYbeFx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="lOaJ3/6c"; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io The struct used for GHCB-based page-state change requests uses a 40-bit bit-field for the GFN, which is shifted by PAGE_SHIFT to generate a 64-bit address. However, anything beyond 40-bits simply gets shifted off when doing this, which will cause issues when dealing with 1TB+ addresses. Fix this by casting the 40-bit GFN values to 64-bit ones prior to shifting it by PAGE_SHIFT. Fixes: ade62c18f474 ("OvmfPkg/MemEncryptSevLib: add support to validate sys= tem RAM") Signed-off-by: Michael Roth --- v2: - use EFI_PHYSICAL_ADDRESS instead of UINT64 (Gerd) .../BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInt= ernal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeIntern= al.c index 85eb41585b..46c6682760 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c @@ -78,13 +78,14 @@ PvalidateRange ( IN BOOLEAN Validate ) { - UINTN Address, RmpPageSize, Ret, i; + UINTN RmpPageSize, Ret, i; + EFI_PHYSICAL_ADDRESS Address; =20 for ( ; StartIndex <=3D EndIndex; StartIndex++) { // // Get the address and the page size from the Info. // - Address =3D Info->Entry[StartIndex].GuestFrameNumber << EFI_PAGE_S= HIFT; + Address =3D ((EFI_PHYSICAL_ADDRESS)Info->Entry[StartIndex].GuestFr= ameNumber) << EFI_PAGE_SHIFT; RmpPageSize =3D Info->Entry[StartIndex].PageSize; =20 Ret =3D AsmPvalidate (RmpPageSize, Validate, Address); --=20 2.25.1 -=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 (#111285): https://edk2.groups.io/g/devel/message/111285 Mute This Topic: https://groups.io/mt/102610323/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-