summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJian J Wang <jian.j.wang@intel.com>2018-07-13 12:46:58 +0800
committerStar Zeng <star.zeng@intel.com>2018-07-27 19:28:01 +0800
commit42c941b33d8af12b6a059c858951d0b4d34c1e15 (patch)
tree6434f9bb4836ebfba9e3e31a256c49ef4844e418
parent5636d21767076ff95bf43b237ac13888a1f8a439 (diff)
downloadedk2-42c941b33d8af12b6a059c858951d0b4d34c1e15.tar.gz
edk2-42c941b33d8af12b6a059c858951d0b4d34c1e15.tar.bz2
edk2-42c941b33d8af12b6a059c858951d0b4d34c1e15.zip
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). 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> (cherry picked from commit b72f4873726b679fb4681ac26abfae227aaa13f1)
-rw-r--r--UefiCpuPkg/CpuDxe/CpuPageTable.c9
1 files changed, 8 insertions, 1 deletions
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());
}
/**