edk2/MdeModulePkg
Hao Wu 72d299c376 MdeModulePkg/SmmCorePerfLib: [CVE-2017-5753] Fix bounds check bypass
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1194

Speculative execution is used by processor to avoid having to wait for
data to arrive from memory, or for previous operations to finish, the
processor may speculate as to what will be executed.

If the speculation is incorrect, the speculatively executed instructions
might leave hints such as which memory locations have been brought into
cache. Malicious actors can use the bounds check bypass method (code
gadgets with controlled external inputs) to infer data values that have
been used in speculative operations to reveal secrets which should not
otherwise be accessed.

This commit will focus on the SMI handler(s) registered within the
SmmCorePerformanceLib and insert AsmLfence API to mitigate the bounds
check bypass issue.

For SMI handler SmmPerformanceHandlerEx():

Under "case SMM_PERF_FUNCTION_GET_GAUGE_DATA :",
'SmmPerfCommData->LogEntryKey' can be a potential cross boundary access of
the 'CommBuffer' (controlled external inputs) during speculative
execution. This cross boundary access is then assign to parameter
'LogEntryKey'. And the value of 'LogEntryKey' can be inferred by code:

  CopyMem (
    (UINT8 *) &GaugeDataEx[Index],
    (UINT8 *) &GaugeEntryExArray[LogEntryKey++],
    sizeof (GAUGE_DATA_ENTRY_EX)
    );

One can observe which part of the content within 'GaugeEntryExArray' was
brought into cache to possibly reveal the value of 'LogEntryKey'.

Hence, this commit adds a AsmLfence() after the boundary/range checks of
'CommBuffer' to prevent the speculative execution.

And there is 1 similar case for SMI handler SmmPerformanceHandler() as
well. This commit also handles it.

A more detailed explanation of the purpose of commit is under the
'Bounds check bypass mitigation' section of the below link:
https://software.intel.com/security-software-guidance/insights/host-firmware-speculative-execution-side-channel-mitigation

And the document at:
https://software.intel.com/security-software-guidance/api-app/sites/default/files/337879-analyzing-potential-bounds-Check-bypass-vulnerabilities.pdf

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
2018-11-21 09:33:32 +08:00
..
Application MdeModulePkg/UiApp/BootMaint: Add check when to call FreePool function 2016-10-19 20:25:56 +08:00
Bus MdeModulePkg/UsbBotPei: Fix undefined behavior in signed left shift 2017-05-16 09:22:13 +08:00
Core MdeModulePkg/DxeCore: UEFI mem attrib table update. 2018-07-26 23:09:13 +08:00
Include MdeModulePkg: Update IP4 stack drivers for classless address unicast check. 2017-05-17 10:33:49 +08:00
Library MdeModulePkg/SmmCorePerfLib: [CVE-2017-5753] Fix bounds check bypass 2018-11-21 09:33:32 +08:00
Logo MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
Universal MdeModulePkg/Variable: [CVE-2017-5753] Fix bounds check bypass 2018-11-21 09:32:46 +08:00
Contributions.txt */Contributions.txt: Update example email address 2015-02-03 17:29:14 +00:00
License.txt Update copyright format 2012-04-24 06:49:39 +00:00
MdeModulePkg.dec MdeModulePkg: Update PcdSmbiosVersion to 0x0301 for SMBIOS spec 3.1.0 2017-04-25 16:05:16 +08:00
MdeModulePkg.dsc MdeModulePkg: Add new driver to publish EDKII_PI_SMM_COMMUNICATION_REGION_TABLE. 2016-07-06 16:19:42 +08:00
MdeModulePkg.uni MdeModulePkg: Add PCD description to MdeModulePkg.uni 2015-12-22 08:41:32 +00:00
MdeModulePkgExtra.uni MdeModulePkg: INF/DEC file updates to EDK II packages 2014-08-28 06:55:48 +00:00