From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5BAC1221F93CA for ; Mon, 15 Jan 2018 20:53:02 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jan 2018 20:58:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,366,1511856000"; d="scan'208";a="195958220" Received: from ray-dev.ccr.corp.intel.com (HELO [10.239.9.19]) ([10.239.9.19]) by fmsmga006.fm.intel.com with ESMTP; 15 Jan 2018 20:58:20 -0800 To: Jian J Wang , edk2-devel@lists.01.org Cc: Eric Dong , Laszlo Ersek References: <20180116024726.12892-1-jian.j.wang@intel.com> From: "Ni, Ruiyu" Message-ID: Date: Tue, 16 Jan 2018 12:58:19 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <20180116024726.12892-1-jian.j.wang@intel.com> Subject: Re: [PATCH] UefiCpuPkg/CpuDxe: fix SetMemoryAttributes issue in 32-bit mode X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Jan 2018 04:53:03 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 1/16/2018 10:47 AM, Jian J Wang wrote: > In 32-bit mode, the BIOS will not create page table for memory beyond > 4GB and therefore it cannot handle the attributes change request for > those memory. But current CpuDxe doesn't check this situation and still > try to complete the request, which will cause attributes of incorrect > memory address to be changed due to type cast from 64-bit to 32-bit. > > This patch fixes this issue by checking the end address of input > memory block and returning EFI_UNSUPPORTED if it's out of range. > > Cc: Eric Dong > Cc: Laszlo Ersek > Cc: Ruiyu Ni > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jian J Wang > --- > UefiCpuPkg/CpuDxe/CpuPageTable.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c b/UefiCpuPkg/CpuDxe/CpuPageTable.c > index a9c9bc9d5e..3ad55f65c5 100644 > --- a/UefiCpuPkg/CpuDxe/CpuPageTable.c > +++ b/UefiCpuPkg/CpuDxe/CpuPageTable.c > @@ -699,6 +699,10 @@ ConvertMemoryPageAttributes ( > DEBUG ((DEBUG_ERROR, "Non-PAE Paging!\n")); > return EFI_UNSUPPORTED; > } > + if ((BaseAddress + Length) > BASE_4GB) { > + DEBUG ((DEBUG_ERROR, "Beyond 4GB memory in 32-bit mode!\n")); > + return EFI_UNSUPPORTED; > + } > break; > case IMAGE_FILE_MACHINE_X64: > ASSERT (CurrentPagingContext.ContextData.X64.PageTableBase != 0); > Reviewed-by: Ruiyu Ni -- Thanks, Ray