From nobody Tue Nov 26 01:45:59 2024 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+61950+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+61950+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1593666953; cv=none; d=zohomail.com; s=zohoarc; b=SyjITIpxDk7hdne5VJ/NMrWXegN4xEPgyxB928Lu0xSFGv24P3vbQH/+02wShlJKdz2GQD8FGjsE0bS1+y8eByES0yPu8LhO/iNC0wd62XmbBne2Nv83HBzRYmSGe1ckeS5sYy3wBu0cAKcm8vH6GAAMzq4+bCEVnGWdWn/W0L4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593666953; 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=OwdWtjTaA2w+UPOcekOTvf+8SZG/9DNCU7W6hOgP5M4=; b=elUxH5olPrqbG1DseToKm+inV1s0RuQwyCZrmAeBw9Na/WWaHpShNOdKvV7SELQaoKE8k9C1L6YeOOsSQfvq6PAs4G2z95xLyCI/oqrV17SaCPXhZS8NLiU5PD5iFIUOPeP3KJZD/7gMVUBUaYdj4EHCDIazjdV+jZPDTJUSe+E= 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+61950+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 1593666953364915.8815658164536; Wed, 1 Jul 2020 22:15:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZJloYY1788612xruQgY3Y4i1; Wed, 01 Jul 2020 22:15:53 -0700 X-Received: from mga06.intel.com (mga06.intel.com []) by mx.groups.io with SMTP id smtpd.web10.360.1593666932487247443 for ; Wed, 01 Jul 2020 22:15:52 -0700 IronPort-SDR: 7h/YKPXjT/+Uc5B00DvbFtUYZhYwSZN+azVgjFJu/LuNrDbz39dwqrzYq7hcpQQ3XW7RJn0MIa 3ZBapKkrPjVA== X-IronPort-AV: E=McAfee;i="6000,8403,9669"; a="208319104" X-IronPort-AV: E=Sophos;i="5.75,302,1589266800"; d="scan'208";a="208319104" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2020 22:15:52 -0700 IronPort-SDR: KSnH+3FrmL4V9Pq2xfUd6u81Zagm/TcMb8eAtFOvGXrZ3JO2XRubux6E6wFrV5D+mcRgX/YA8j pJiu3DCcaMoA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,302,1589266800"; d="scan'208";a="455385080" X-Received: from guominji-mobl.ccr.corp.intel.com ([10.238.4.95]) by orsmga005.jf.intel.com with ESMTP; 01 Jul 2020 22:15:50 -0700 From: "Guomin Jiang" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Laszlo Ersek , Rahul Kumar Subject: [edk2-devel] [PATCH v2 9/9] UefiCpuPkg/CpuMpPei: Enable paging and set NP flag to avoid TOCTOU (CVE-2019-11098) Date: Thu, 2 Jul 2020 13:15:25 +0800 Message-Id: <20200702051525.1102-10-guomin.jiang@intel.com> In-Reply-To: <20200702051525.1102-1-guomin.jiang@intel.com> References: <20200702051525.1102-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: q7ZNcVzfSXgKpm8ktlbEOMecx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1593666953; bh=FFvmnyJj56SV9HeaCuFHxJ45Q7HDgSBEaYHX0Ult8bY=; h=Cc:Date:From:Reply-To:Subject:To; b=J7HpKL4Lg/wC4nYHutSHNIb52sohyjnkS5FPynapDnmwsHvZiBcLaJFuFH/PC7c77/E MSs4NPhL3vQvqdhTaOpcDMVx9sQCUhQDRCWJcdyte1PwDB2hJLSDBJHB9BQAqmJrXNDgX svGY2L3RA5VA8hd3cHlKdhRcLaWcXpB2AQs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D1614 To avoid the TOCTOU, enable paging and set Not Present flag so when access any code in the flash range, it will trigger #NP exception. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Signed-off-by: Guomin Jiang --- UefiCpuPkg/CpuMpPei/CpuMpPei.inf | 3 +++ UefiCpuPkg/CpuMpPei/CpuPaging.c | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf b/UefiCpuPkg/CpuMpPei/CpuMpPe= i.inf index caead3ce34d4..fd50b55f06cb 100644 --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.inf @@ -46,6 +46,9 @@ [LibraryClasses] BaseMemoryLib CpuLib =20 +[Guids] + gEdkiiMigratedFvInfoGuid ## = SOMETIMES_CONSUMES ## HOB + [Ppis] gEfiPeiMpServicesPpiGuid ## PRODUCES gEfiSecPlatformInformationPpiGuid ## SOMETIMES_CONSUMES diff --git a/UefiCpuPkg/CpuMpPei/CpuPaging.c b/UefiCpuPkg/CpuMpPei/CpuPagin= g.c index d0cbebf70bbf..af4069b42cdb 100644 --- a/UefiCpuPkg/CpuMpPei/CpuPaging.c +++ b/UefiCpuPkg/CpuMpPei/CpuPaging.c @@ -12,6 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include =20 #include "CpuMpPei.h" =20 @@ -605,6 +606,8 @@ MemoryDiscoveredPpiNotifyCallback ( EFI_STATUS Status; BOOLEAN InitStackGuard; BOOLEAN InterruptState; + EDKII_MIGRATED_FV_INFO *MigratedFvInfo; + EFI_PEI_HOB_POINTERS Hob; =20 InterruptState =3D SaveAndDisableInterrupts (); Status =3D MigrateGdt (); @@ -617,9 +620,9 @@ MemoryDiscoveredPpiNotifyCallback ( // the task switch (for the sake of stack switch). // InitStackGuard =3D FALSE; - if (IsIa32PaeSupported () && PcdGetBool (PcdCpuStackGuard)) { + if (IsIa32PaeSupported ()) { EnablePaging (); - InitStackGuard =3D TRUE; + InitStackGuard =3D PcdGetBool (PcdCpuStackGuard); } =20 Status =3D InitializeCpuMpWorker ((CONST EFI_PEI_SERVICES **)PeiServices= ); @@ -629,6 +632,16 @@ MemoryDiscoveredPpiNotifyCallback ( SetupStackGuardPage (); } =20 + Hob.Raw =3D GetFirstGuidHob (&gEdkiiMigratedFvInfoGuid); + while (Hob.Raw !=3D NULL) { + MigratedFvInfo =3D GET_GUID_HOB_DATA (Hob); + ConvertMemoryPageAttributes (MigratedFvInfo->FvOrgBase, MigratedFvInfo= ->FvLength, 0); + + Hob.Raw =3D GET_NEXT_HOB (Hob); + Hob.Raw =3D GetNextGuidHob (&gEdkiiMigratedFvInfoGuid, Hob.Raw); + } + CpuFlushTlb (); + return Status; } =20 --=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 (#61950): https://edk2.groups.io/g/devel/message/61950 Mute This Topic: https://groups.io/mt/75252669/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-