From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Permerror (SPF Permanent Error: Void lookup limit of 2 exceeded) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 26DFA221F93B9 for ; Mon, 15 Jan 2018 18:42:10 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jan 2018 18:47:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,366,1511856000"; d="scan'208";a="11196692" Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.192.51]) by fmsmga002.fm.intel.com with ESMTP; 15 Jan 2018 18:47:28 -0800 From: Jian J Wang To: edk2-devel@lists.01.org Cc: Eric Dong , Laszlo Ersek , Ruiyu Ni Date: Tue, 16 Jan 2018 10:47:26 +0800 Message-Id: <20180116024726.12892-1-jian.j.wang@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 Subject: [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 02:42:11 -0000 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); -- 2.15.1.windows.2