Reviewed-by: Eric Dong <[email protected]>

> -----Original Message-----
> From: Wang, Jian J
> Sent: Friday, July 13, 2018 1:54 PM
> To: [email protected]
> Cc: Dong, Eric <[email protected]>; Laszlo Ersek <[email protected]>;
> Yao, Jiewen <[email protected]>; Zeng, Star <[email protected]>
> Subject: [PATCH] UefiCpuPkg/CpuDxe: fix incorrect check of SMM mode
> 
> Current IsInSmm() method makes use of gEfiSmmBase2ProtocolGuid.InSmm()
> to check if current processor is in SMM mode or not. But this is not correct
> because gEfiSmmBase2ProtocolGuid.InSmm() can only detect if the caller is
> running in SMRAM or from SMM driver. It cannot guarantee if the caller is
> running in SMM mode. Because SMM mode will load its own page table,
> adding an extra check of saved DXE page table base address against current
> CR3 register value can help to get the correct answer for sure (in SMM mode
> or not in SMM mode).
> 
> This is an issue caused by check-in at
> 
>   d106cf71eabaacff63c14626a4a87346b93074dd
> 
> Cc: Eric Dong <[email protected]>
> Cc: Laszlo Ersek <[email protected]>
> Cc: Jiewen Yao <[email protected]>
> Cc: Star Zeng <[email protected]>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Jian J Wang <[email protected]>
> ---
>  UefiCpuPkg/CpuDxe/CpuPageTable.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c
> b/UefiCpuPkg/CpuDxe/CpuPageTable.c
> index 850eed60e7..df021798c0 100644
> --- a/UefiCpuPkg/CpuDxe/CpuPageTable.c
> +++ b/UefiCpuPkg/CpuDxe/CpuPageTable.c
> @@ -136,7 +136,14 @@ IsInSmm (
>      mSmmBase2->InSmm (mSmmBase2, &InSmm);
>    }
> 
> -  return InSmm;
> +  //
> +  // mSmmBase2->InSmm() can only detect if the caller is running in
> + SMRAM  // or from SMM driver. It cannot tell if the caller is running in
> SMM mode.
> +  // Check page table base address to guarantee that because SMM mode
> + willl  // load its own page table.
> +  //
> +  return (InSmm &&
> +          mPagingContext.ContextData.X64.PageTableBase !=
> + (UINT64)AsmReadCr3());
>  }
> 
>  /**
> --
> 2.16.2.windows.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to