public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] UefiCpuPkg/CpuDxe: fix SetMemoryAttributes issue in 32-bit mode
@ 2018-01-16  2:47 Jian J Wang
  2018-01-16  4:58 ` Ni, Ruiyu
  0 siblings, 1 reply; 2+ messages in thread
From: Jian J Wang @ 2018-01-16  2:47 UTC (permalink / raw)
  To: edk2-devel; +Cc: Eric Dong, Laszlo Ersek, Ruiyu Ni

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 <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
---
 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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] UefiCpuPkg/CpuDxe: fix SetMemoryAttributes issue in 32-bit mode
  2018-01-16  2:47 [PATCH] UefiCpuPkg/CpuDxe: fix SetMemoryAttributes issue in 32-bit mode Jian J Wang
@ 2018-01-16  4:58 ` Ni, Ruiyu
  0 siblings, 0 replies; 2+ messages in thread
From: Ni, Ruiyu @ 2018-01-16  4:58 UTC (permalink / raw)
  To: Jian J Wang, edk2-devel; +Cc: Eric Dong, Laszlo Ersek

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 <eric.dong@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
> ---
>   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 <ruiyu.ni@intel.com>
-- 
Thanks,
Ray


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-16  4:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-16  2:47 [PATCH] UefiCpuPkg/CpuDxe: fix SetMemoryAttributes issue in 32-bit mode Jian J Wang
2018-01-16  4:58 ` Ni, Ruiyu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox