From nobody Mon Feb 9 10:48:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62221+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62221+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1594195871; cv=none; d=zohomail.com; s=zohoarc; b=HBNezE9U/BGfxDtnuV7OL3sXsZnva8rHDM2B6OgpMJAznKcbzBHIE4KxsFrlwYDfKYveajNPtqUpgq1QWhZCPUTGYzv3fUWzWvlCMf5qJ6bb6w6ZFyJBbgFi0RWmen8gItQyebp9PcI70i/gfOkRm1QNnEaKZYoObMB5BZNcNwI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594195871; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=KzhhQoKYG0ZYfw8QcwKXM90BRCqMFbnuXPS2TBYLlXY=; b=CNBnr4qJP2bMh76QX+Q+YE0TDs4zUU095/mky265IQTSRqt9gRIiN87OoCYlY6RaQQK1Oijljyzu9dTE5mZwOvmzw6npaXpvW0TbBBlqih7A0LWHYDIGk6ixgQ65fEaXPjp62WHvFn1BZRZUAZ6xQU3UdQfeBWe/D7LFR09qin0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62221+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594195871375657.6048104306763; Wed, 8 Jul 2020 01:11:11 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id OEQmYY1788612x4iZ0RD38jU; Wed, 08 Jul 2020 01:11:10 -0700 X-Received: from mga14.intel.com (mga14.intel.com []) by mx.groups.io with SMTP id smtpd.web10.6162.1594195868464323810 for ; Wed, 08 Jul 2020 01:11:10 -0700 IronPort-SDR: M6rS+3bOwiRgUOIwusqVhwDDq4VjtMHRpugA74nPSi4HL15+l+wwUJatiMV/gAqkxXePaKll51 eIdw6qlbV13g== X-IronPort-AV: E=McAfee;i="6000,8403,9675"; a="146826596" X-IronPort-AV: E=Sophos;i="5.75,327,1589266800"; d="scan'208";a="146826596" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2020 01:11:10 -0700 IronPort-SDR: dLdnt8ZDV0UkDm/vYKopVvRqvkyVYjsZ7iCl3jAvCSzfuYJNkG36fr9LYbtcHl4tlTi89DAyTA r8p9l5rHzDyw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,327,1589266800"; d="scan'208";a="483347237" X-Received: from guominji-mobl.ccr.corp.intel.com ([10.238.4.95]) by fmsmga006.fm.intel.com with ESMTP; 08 Jul 2020 01:11:08 -0700 From: "Guomin Jiang" To: devel@edk2.groups.io Cc: Michael Kubacki , Eric Dong , Ray Ni , Laszlo Ersek , Rahul Kumar Subject: [edk2-devel] [PATCH v4 3/9] UefiCpuPkg/CpuMpPei: Add GDT and IDT migration support (CVE-2019-11098) Date: Wed, 8 Jul 2020 16:10:53 +0800 Message-Id: <20200708081059.691-4-guomin.jiang@intel.com> In-Reply-To: <20200708081059.691-1-guomin.jiang@intel.com> References: <20200708081059.691-1-guomin.jiang@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,guomin.jiang@intel.com X-Gm-Message-State: Ec2vUF72wwNkJkbKbaGfwkMnx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594195870; bh=/2zwD9vsoYOixyVKcWeJY8t7JJQ7oGIqfXEAi97W1vk=; h=Cc:Date:From:Reply-To:Subject:To; b=Y49sPgR0xaAUya0RTtAMNvmFDRxQakmf1bRf/Iv8eVWzgwI6nbL9t/P2NCmoRlhIgXi AHTg+6YfEGRzI9p8o8OILQkkVutXux1iANwHpy5prCSHSF1ncqnuXob4yR4FHZcsuR/le DtMFhXeyqCksfZEDtJMtURlPZj6OmZxMYXU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Michael Kubacki REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D1614 Moves the GDT and IDT to permanent memory in a memory discovered callback. This is done to ensure the GDT and IDT authenticated in pre-memory is not fetched from outside a verified location after the permanent memory transition. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Signed-off-by: Michael Kubacki Reviewed-by: Laszlo Ersek --- UefiCpuPkg/CpuMpPei/CpuMpPei.inf | 1 + UefiCpuPkg/CpuMpPei/CpuMpPei.h | 12 +++++++++++ UefiCpuPkg/CpuMpPei/CpuMpPei.c | 37 ++++++++++++++++++++++++++++++++ UefiCpuPkg/CpuMpPei/CpuPaging.c | 12 +++++++++-- 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf b/UefiCpuPkg/CpuMpPei/CpuMpPe= i.inf index caead3ce34d4..f4d11b861f77 100644 --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.inf @@ -63,6 +63,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList ##= SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize ##= SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize ##= SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdMigrateTemporaryRamFirmwareVolumes ##= CONSUMES =20 [Depex] TRUE diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.h b/UefiCpuPkg/CpuMpPei/CpuMpPei.h index 7d5c527d6006..309478cbe14c 100644 --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.h +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.h @@ -397,6 +397,18 @@ SecPlatformInformation2 ( OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2 ); =20 +/** + Migrates the Global Descriptor Table (GDT) to permanent memory. + + @retval EFI_SUCCESS The GDT was migrated successfully. + @retval EFI_OUT_OF_RESOURCES The GDT could not be migrated due to lac= k of available memory. + +**/ +EFI_STATUS +MigrateGdt ( + VOID + ); + /** Initializes MP and exceptions handlers. =20 diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c index 07ccbe7c6a91..d07540cf7471 100644 --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c @@ -429,6 +429,43 @@ GetGdtr ( AsmReadGdtr ((IA32_DESCRIPTOR *)Buffer); } =20 +/** + Migrates the Global Descriptor Table (GDT) to permanent memory. + + @retval EFI_SUCCESS The GDT was migrated successfully. + @retval EFI_OUT_OF_RESOURCES The GDT could not be migrated due to lac= k of available memory. + +**/ +EFI_STATUS +MigrateGdt ( + VOID + ) +{ + EFI_STATUS Status; + UINTN GdtBufferSize; + IA32_DESCRIPTOR Gdtr; + VOID *GdtBuffer; + + AsmReadGdtr ((IA32_DESCRIPTOR *) &Gdtr); + GdtBufferSize =3D sizeof (IA32_SEGMENT_DESCRIPTOR) -1 + Gdtr.Limit + 1; + + Status =3D PeiServicesAllocatePool ( + GdtBufferSize, + &GdtBuffer + ); + ASSERT (GdtBuffer !=3D NULL); + if (EFI_ERROR (Status)) { + return EFI_OUT_OF_RESOURCES; + } + + GdtBuffer =3D ALIGN_POINTER (GdtBuffer, sizeof (IA32_SEGMENT_DESCRIPTOR)= ); + CopyMem (GdtBuffer, (VOID *) Gdtr.Base, Gdtr.Limit + 1); + Gdtr.Base =3D (UINTN) GdtBuffer; + AsmWriteGdtr (&Gdtr); + + return EFI_SUCCESS; +} + /** Initializes CPU exceptions handlers for the sake of stack switch require= ment. =20 diff --git a/UefiCpuPkg/CpuMpPei/CpuPaging.c b/UefiCpuPkg/CpuMpPei/CpuPagin= g.c index a462e7ee1e38..3bf0574b34c6 100644 --- a/UefiCpuPkg/CpuMpPei/CpuPaging.c +++ b/UefiCpuPkg/CpuMpPei/CpuPaging.c @@ -602,8 +602,16 @@ MemoryDiscoveredPpiNotifyCallback ( IN VOID *Ppi ) { - EFI_STATUS Status; - BOOLEAN InitStackGuard; + EFI_STATUS Status; + BOOLEAN InitStackGuard; + BOOLEAN InterruptState; + + if (PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes)) { + InterruptState =3D SaveAndDisableInterrupts (); + Status =3D MigrateGdt (); + ASSERT_EFI_ERROR (Status); + SetInterruptState (InterruptState); + } =20 // // Paging must be setup first. Otherwise the exception TSS setup during = MP --=20 2.25.1.windows.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 (#62221): https://edk2.groups.io/g/devel/message/62221 Mute This Topic: https://groups.io/mt/75372251/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-