]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuDxe: fix incorrect check of SMM mode
authorJian J Wang <jian.j.wang@intel.com>
Fri, 13 Jul 2018 04:46:58 +0000 (12:46 +0800)
committerEric Dong <eric.dong@intel.com>
Fri, 20 Jul 2018 02:34:11 +0000 (10:34 +0800)
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).

There's indiscriminate uses of Context.X64 and Context.Ia32 in code which
is not a good coding practice and will cause potential issue. In addition,
the related structure type definition is not packed and has also potential
issue. This will not be covered by this patch but be tracked by a bug below.

  https://bugzilla.tianocore.org/show_bug.cgi?id=1039

This is an issue caused by check-in at

  2a1408d1d739ead00c96397549be7a9fc53c9c6e

Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
UefiCpuPkg/CpuDxe/CpuPageTable.c

index 850eed60e7bc53c83759801e39eae8c3ff95af12..df021798c00988e2668b0ae1cb9b4a9b43e528e8 100644 (file)
@@ -136,7 +136,14 @@ IsInSmm (
     mSmmBase2->InSmm (mSmmBase2, &InSmm);\r
   }\r
 \r
-  return InSmm;\r
+  //\r
+  // mSmmBase2->InSmm() can only detect if the caller is running in SMRAM\r
+  // or from SMM driver. It cannot tell if the caller is running in SMM mode.\r
+  // Check page table base address to guarantee that because SMM mode willl\r
+  // load its own page table.\r
+  //\r
+  return (InSmm &&\r
+          mPagingContext.ContextData.X64.PageTableBase != (UINT64)AsmReadCr3());\r
 }\r
 \r
 /**\r