]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: Sec: force reinit of BaseExtractGuidedSectionLib handler table
authorLaszlo Ersek <lersek@redhat.com>
Mon, 30 Nov 2015 18:41:14 +0000 (18:41 +0000)
committerlersek <lersek@Edk2>
Mon, 30 Nov 2015 18:41:14 +0000 (18:41 +0000)
BaseExtractGuidedSectionLib uses a table at the static physical address
PcdGuidedExtractHandlerTableAddress, and modules that are linked against
BaseExtractGuidedSectionLib are expected to work together on that table.
Namely, some modules can register handlers for GUIDed sections, some other
modules can decode such sections with the pre-registered handlers. The
table carries persistent information between these modules.

BaseExtractGuidedSectionLib checks a table signature whenever it is used
(by whichever module that is linked against it), and at the first use
(identified by a signature mismatch) it initializes the table.

One of the module types that BaseExtractGuidedSectionLib can be used with
is SEC, if the SEC module in question runs with the platform's RAM already
available.

In such cases the question emerges whether the initial contents of the RAM
(ie. contents that predate the very first signature check) can be trusted.
Normally RAM starts out with all zeroes (leading to a signature mismatch
on the first check); however a malicious runtime OS can populate the area
with some payload, then force a warm platform reset or an S3
suspend-and-resume. In such cases the signature check in the SEC module
might not fire, and ExtractGuidedSectionDecode() might run code injected
by the runtime OS, as part of SEC (ie. with high privileges).

Therefore we clear the handler table in SEC.

See also git commit ad43bc6b2e (SVN rev 15433) -- this patch secures the
(d) and (e) code paths examined in that commit. Furthermore, a
non-malicious runtime OS will observe no change in behavior; see case (c)
in said commit.

Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
[michael.d.kinney@intel.com: prevent VS20xx loop intrinsic with volatile]
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19035 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/Sec/SecMain.c
OvmfPkg/Sec/SecMain.inf

index 4f87059e1755f463b805be924cca732c5180bd8b..0cf127af8486cd5077164846e137ee8a9854c742 100644 (file)
@@ -698,6 +698,19 @@ SecCoreStartupWithStack (
   SEC_IDT_TABLE               IdtTableInStack;\r
   IA32_DESCRIPTOR             IdtDescriptor;\r
   UINT32                      Index;\r
+  volatile UINT8              *Table;\r
+\r
+  //\r
+  // To ensure SMM can't be compromised on S3 resume, we must force re-init of\r
+  // the BaseExtractGuidedSectionLib. Since this is before library contructors\r
+  // are called, we must use a loop rather than SetMem.\r
+  //\r
+  Table = (UINT8*)(UINTN)FixedPcdGet64 (PcdGuidedExtractHandlerTableAddress);\r
+  for (Index = 0;\r
+       Index < FixedPcdGet32 (PcdGuidedExtractHandlerTableSize);\r
+       ++Index) {\r
+    Table[Index] = 0;\r
+  }\r
 \r
   ProcessLibraryConstructorList (NULL, NULL);\r
 \r
index 2f78f3c851ad9c928d4e1e93c0314272f539ec0d..415731ce546b51d5e637d1e160ec7b5bdfbc654b 100644 (file)
@@ -68,3 +68,5 @@
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase\r
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase\r
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize\r
+  gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress\r
+  gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize\r