From nobody Thu Mar 28 10:16:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+50061+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+50061+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1573046017; cv=none; d=zoho.com; s=zohoarc; b=KObS8ZeZX7rD+6YQRlm8lz03sR96kTGXq/Xkxmoa1PsBL+GuVg9iRjoDpkP/uRJmL1A+AYHi3NzQoBCrL6m2FUJyaLaeX8+QLluWeVxGkv5JeL0wyJOu+ioUzizY0lp2Xuh5GX7XD7GD5r0S3eiUGtzYMf8pNXSxFDlc/hm3Sq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573046017; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=u8Lo0eLIN+gs8M0ZZLo3rzUmMrvgoUoQHlSZR+SUMY0=; b=cigSLwXii7Kdf4fKH9moGORo5luqog+URbR1mriIpSGCpWqm+xqJm2qDs6YJR7yEC5TaPSQGUh3mh5TB1pG6zHgc19PeCo4OIcpAOJ2+4I/00JDReFRtYmAlzCp4NAI9PeBeyPXSIY5Ys9penfM3c6yRnJI3MxuTCDsnji8wrFo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+50061+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 1573046017329718.0235122110162; Wed, 6 Nov 2019 05:13:37 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaaaYY1788612xaaaaaaaaaa; Wed, 06 Nov 2019 05:13:36 -0800 X-Received: from mga07.intel.com (mga07.intel.com []) by mx.groups.io with SMTP id smtpd.web11.8258.1573046015437825197 for ; Wed, 06 Nov 2019 05:13:36 -0800 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 orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Nov 2019 05:13:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,274,1569308400"; d="scan'208";a="377043494" X-Received: from shwdeopenpsi777.ccr.corp.intel.com ([10.239.158.59]) by orsmga005.jf.intel.com with ESMTP; 06 Nov 2019 05:13:35 -0800 From: "Wang, Jian J" To: devel@edk2.groups.io Cc: Dandan Bi , Liming Gao , Ray Ni , Hao A Wu , Sean Brogan Subject: [edk2-devel] [PATCH 1/2] MdeModulePkg/DxeIplPeim: reserve page 0 for NULL pointer detection Date: Wed, 6 Nov 2019 21:13:32 +0800 Message-Id: <20191106131333.4684-2-jian.j.wang@intel.com> In-Reply-To: <20191106131333.4684-1-jian.j.wang@intel.com> References: <20191106131333.4684-1-jian.j.wang@intel.com> 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,jian.j.wang@intel.com X-Gm-Message-State: aaaaaaaaaaaaaaaaaaaaaaaax1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1573046016; bh=p0mQiWN3G4vGJXCrWYN6ufHw5SPggV4jNbGpluw60I0=; h=Cc:Date:From:Reply-To:Subject:To; b=IwZ/VoPUvH3zognNz6n1APIj+qHvGoyu44EYR0SGwHcJjxqeFiN0NDuTSFn1x3wzDCu AInyRlogJh0cm8jYu14DOKa8jvtZwITojiBrYgWtkxb3szKO9ZTDAC2E9tzsvmX1wnXEi 3h4Iy5ycUPW0wHD6jpH3Hhi3FCrOCb4uwKw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When a boot loader examines the memory map, it can see that location 0 is available memory. If it chooses to use that memory, and PcdNullPointerDetectionPropertyMask is enabled, use of memory in page 0 will cause an exception. This does occur when running the memtest86 program. Leaving page 0 available is for legacy support purpose. Since we have deprecated the support of legacy, the solution is just reserving it so that it cannot be allocated for other uses. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1885 Cc: Dandan Bi Cc: Liming Gao Cc: Ray Ni Cc: Hao A Wu Cc: Sean Brogan Signed-off-by: Jian J Wang Reviewed-by: Ray Ni --- MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c | 4 ++++ MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c b/MdeModulePkg= /Core/DxeIplPeim/Ia32/DxeLoadFunc.c index 172d7cd1c6..6e8ca824d4 100644 --- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c @@ -246,8 +246,12 @@ HandOffToDxeCore ( EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi; BOOLEAN BuildPageTablesIa32Pae; =20 + // + // Clear page 0 and mark it as allocated if NULL pointer detection is en= abled. + // if (IsNullDetectionEnabled ()) { ClearFirst4KPage (HobList.Raw); + BuildMemoryAllocationHob (0, EFI_PAGES_TO_SIZE (1), EfiBootServicesDat= a); } =20 Status =3D PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PA= GES (STACK_SIZE), &BaseOfStack); diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c b/MdeModulePkg/= Core/DxeIplPeim/X64/DxeLoadFunc.c index 2867610bff..f465eb1d8a 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c @@ -36,8 +36,12 @@ HandOffToDxeCore ( EFI_VECTOR_HANDOFF_INFO *VectorInfo; EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi; =20 + // + // Clear page 0 and mark it as allocated if NULL pointer detection is en= abled. + // if (IsNullDetectionEnabled ()) { ClearFirst4KPage (HobList.Raw); + BuildMemoryAllocationHob (0, EFI_PAGES_TO_SIZE (1), EfiBootServicesDat= a); } =20 // --=20 2.17.1.windows.2 -=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 (#50061): https://edk2.groups.io/g/devel/message/50061 Mute This Topic: https://groups.io/mt/44036060/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- From nobody Thu Mar 28 10:16:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+50062+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+50062+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1573046018; cv=none; d=zoho.com; s=zohoarc; b=oKhnOv/++30CLVYz9YXUTDaRrjr+70TCXTNwBJuKMiOVfz3a8PsEa3P6zbTQs2KNNpHLu0xoO0glvSh/puLWZPBwougTnAalKz9gjXNe3rF3iyIwk5I6W5+X+xKzcd3bdjjU2UNqZlpxp0tzWF/I+A7ydNOfUrPS053ipoqxV3s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573046018; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=KJvIXGb3F2FPUkrUeKTCJexnj+oBpCEHEShvTfK0tG8=; b=bThD90EUM1mcJQ86uJupfBx8n3clePUQ/viNHqwPuB7ixXdW8n9Oo2+BPs1xAh2AlqcS0g5IjvPI5OUtufzhs6Oj3V1CC868RN/TxnUSgCU0t1/cXSjtXfAhpDqskGyLykhpk4WoSh8fYeczpfRbN+5fOxS80QxPLV/LNK8pX2g= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+50062+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 1573046018548698.5364761058096; Wed, 6 Nov 2019 05:13:38 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaaaYY1788612xaaaaaaaaaa; Wed, 06 Nov 2019 05:13:38 -0800 X-Received: from mga07.intel.com (mga07.intel.com []) by mx.groups.io with SMTP id smtpd.web11.8258.1573046015437825197 for ; Wed, 06 Nov 2019 05:13:37 -0800 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 orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Nov 2019 05:13:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,274,1569308400"; d="scan'208";a="377043506" X-Received: from shwdeopenpsi777.ccr.corp.intel.com ([10.239.158.59]) by orsmga005.jf.intel.com with ESMTP; 06 Nov 2019 05:13:36 -0800 From: "Wang, Jian J" To: devel@edk2.groups.io Cc: Dandan Bi , Liming Gao , Ray Ni , Hao A Wu , Sean Brogan Subject: [edk2-devel] [PATCH 2/2] MdeModulePkg/Core/Dxe: free page 0 after disabling NULL pointer detection Date: Wed, 6 Nov 2019 21:13:33 +0800 Message-Id: <20191106131333.4684-3-jian.j.wang@intel.com> In-Reply-To: <20191106131333.4684-1-jian.j.wang@intel.com> References: <20191106131333.4684-1-jian.j.wang@intel.com> 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,jian.j.wang@intel.com X-Gm-Message-State: aaaaaaaaaaaaaaaaaaaaaaaax1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1573046018; bh=9cImyaiZTFZFtHS7pTBF16M8nkUwiA+LGJZu/9Z/8tc=; h=Cc:Date:From:Reply-To:Subject:To; b=a5hOopLDVqJukAkUhAwt5hdn/Fisx86F//s22GJGyBCep5OvtXKYyw50tTxV6THrMM2 5DWfoZDG2R3IKnrhWNfWnVZarIX5hivxenXZl2FQ93Fjk88gRQh14PXIlqiY3c01hOWGc RmKSaazxkP1vSfcuUDW9pBy86xnWwR18kxQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" To solve access issue reported by BZ1885, page 0 will be allocated to avoid misuses if NULL pointer detection is enabled. It should be better to be freed after EndOfDxe if BIT7 of PcdNullPointerDetectionPropertyMask is set, because NULL pointer detection is no longer available after EndOfDxe and there will be no access conflict. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1885 Cc: Dandan Bi Cc: Liming Gao Cc: Ray Ni Cc: Hao A Wu Cc: Sean Brogan Signed-off-by: Jian J Wang Reviewed-by: Ray Ni --- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/C= ore/Dxe/Misc/MemoryProtection.c index 7a24bd0781..47edf86dfb 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -1094,6 +1094,11 @@ DisableNullDetectionAtTheEndOfDxe ( ); ASSERT_EFI_ERROR (Status); =20 + // + // Page 0 might have be allocated to avoid misuses. Free it here anyway. + // + CoreFreePages (0, 1); + CoreCloseEvent (Event); DEBUG ((DEBUG_INFO, "DisableNullDetectionAtTheEndOfDxe(): end\r\n")); =20 --=20 2.17.1.windows.2 -=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 (#50062): https://edk2.groups.io/g/devel/message/50062 Mute This Topic: https://groups.io/mt/44036075/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-