edk2/MdeModulePkg/Library
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
..
AuthVariableLibNull MdeModulePkg: Add AuthVariableLib LibraryClass 2015-07-01 03:04:18 +00:00
BaseIpmiLibNull MdeModulePkg: Add BaseIpmiLib Null Library Instance. 2015-12-23 12:25:52 +00:00
BasePlatformHookLibNull MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
BaseResetSystemLibNull MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
BaseSerialPortLib16550 MdeModulePkg BaseSerialPortLib16550:Implement Get(Set)Control/SetAttributes 2015-11-30 03:17:04 +00:00
BaseSortLib MdeModulePkg: Add the missing module UNI files. 2015-08-28 02:46:46 +00:00
CpuExceptionHandlerLibNull MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
CustomizedDisplayLib Refine code to keep code alignment 2015-06-09 08:13:23 +00:00
DebugAgentLibNull MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
DxeCapsuleLibNull MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
DxeCoreMemoryAllocationLib MdeModulePkg: Fix typo. 2015-03-13 08:13:16 +00:00
DxeCorePerformanceLib MdeModulePkg: Use StrnCpyS instead of StrCpyS to indicate the copy length from the source. 2015-07-07 03:01:07 +00:00
DxeCrc32GuidedSectionExtractLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
DxeDebugPrintErrorLevelLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
DxeDpcLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
DxeHttpLib MdeModulePkg: Clean code to follow C Coding style. 2015-12-21 07:19:40 +00:00
DxeIpIoLib MdeModulePkg: Discard received broadcast message in DxeIpIoLib. 2017-05-17 10:38:26 +08:00
DxeIpmiLibIpmiProtocol MdeModulePkg: Add DxeIpmiLibIpmiProtocol Library Instance. 2015-12-23 12:26:45 +00:00
DxeNetLib MdeModulePkg: Update NetLib interface to support classless addressing. 2017-05-17 10:19:49 +08:00
DxePerformanceLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
DxePrintLibPrint2Protocol MdeModulePkg/DxePrintLibPrint2Protocol: make mStatusString array CONST 2015-07-16 06:50:45 +00:00
DxeReportStatusCodeLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
DxeSecurityManagementLib MdeModulePkg: SecurityManagementLib to handle LoadFile DevicePath 2015-07-02 04:27:32 +00:00
DxeSmmPerformanceLib MdeModulePkg DxeSmmPerformanceLib: Add missing UefiLib in *.inf at de2459d 2016-07-07 15:08:30 +08:00
DxeTcpIoLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
DxeUdpIoLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
LockBoxNullLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
LzmaCustomDecompressLib MdeModulePkg: Add two library instances 2015-04-03 02:50:57 +00:00
OemHookStatusCodeLibNull MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
PciHostBridgeLibNull MdeModulePkg/PciHostBridgeLib: Correct the function header comments 2016-03-04 10:48:45 +08:00
PeiCrc32GuidedSectionExtractLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
PeiDebugPrintHobLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
PeiDxeDebugLibReportStatusCode MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode: Use safe string functions to refine code. 2015-07-01 08:14:36 +00:00
PeiIpmiLibIpmiPpi MdeModulePkg: Add PeiIpmiLibIpmiPpi Library Instance. 2015-12-23 12:26:18 +00:00
PeiPerformanceLib MdeModulePkg: Refine code to use Strn**S safe functions instead of Str**S ones in some cases. 2015-07-08 01:08:09 +00:00
PeiRecoveryLibNull MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
PeiReportStatusCodeLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
PeiS3LibNull MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
PiDxeS3BootScriptLib MdeModulePkg PiDxeS3BootScriptLib: Use a specific name for mSmst 2016-07-06 16:48:50 +08:00
PiSmmCoreMemoryAllocationLib MdeModulePkg PiSmmCore: Remove a hidden assumption of SMRAM reservation 2015-07-26 07:38:12 +00:00
PiSmmCoreSmmServicesTableLib MdeModulePkg: Add InSmm() API in PiSmmCoreSmmServicesTableLib instance 2014-11-05 12:09:22 +00:00
PlatformBootManagerLibNull MdeModulePkg: Fix INF to point to correct UNI file. 2015-05-21 06:50:07 +00:00
PlatformHookLibSerialPortPpi MdeModulePkg: Update library class name of PlatformHookLibSerialPortPpi.inf 2015-02-10 07:33:19 +00:00
PlatformVarCleanupLib MdeModulePkg: Add PlatformVarCleanupLib library 2015-08-25 03:11:06 +00:00
RuntimeDxeReportStatusCodeLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
SmmCorePerformanceLib MdeModulePkg/SmmCorePerfLib: [CVE-2017-5753] Fix bounds check bypass 2018-11-21 09:33:32 +08:00
SmmCorePlatformHookLibNull MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
SmmIpmiLibSmmIpmiProtocol MdeModulePkg: Add SmmIpmiLibSmmIpmiProtocol Library Instance. 2015-12-23 12:27:16 +00:00
SmmLockBoxLib MdeModulePkg SmmLockBoxSmmLib: Add DESTRUCTOR SmmLockBoxSmmDestructor 2016-07-06 16:43:13 +08:00
SmmPerformanceLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
SmmReportStatusCodeLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
TpmMeasurementLibNull MdeModulePkg: Move TpmMeasurementLib LibraryClass from SecurityPkg 2015-07-01 03:01:34 +00:00
UefiBootManagerLib MdeModulePkg: Replace UnicodeStrToAsciiStr/AsciiStrToUnicodeStr 2016-07-07 13:25:07 +08:00
UefiHiiLib MdeModulePkg:Fix the bug the incorrect change of StrCpyS function 2015-09-17 07:37:44 +00:00
UefiHiiServicesLib MdeModulePkg: Convert non DOS format files to DOS format and remove unused module UNI files. 2014-09-03 08:39:12 +00:00
UefiSortLib MdeModulePkg: Add the missing module UNI files. 2015-08-28 02:46:46 +00:00
VarCheckHiiLib MdeModulePkg: Replace UnicodeStrToAsciiStr/AsciiStrToUnicodeStr 2016-07-07 13:25:07 +08:00
VarCheckLib MdeModulePkg VarCheckLib: R18611 was thoughtless for property set 2015-11-16 07:18:36 +00:00
VarCheckPcdLib MdeModulePkg: Add VarCheckPcdLib NULL class library 2015-08-25 03:10:32 +00:00
VarCheckUefiLib MdeModulePkg: Revert 54707a6bc7 2016-05-19 09:12:28 +08:00