From: "Aaron Li" <aaron.li@intel.com>
To: devel@edk2.groups.io
Cc: Ray Ni <ray.ni@intel.com>,
Rangasai V Chaganty <rangasai.v.chaganty@intel.com>,
Siyuan Fu <siyuan.fu@intel.com>
Subject: [PATCH v1 1/1] IntelSiliconPkg/ShadowMicrocodePei: Add microcode header verification.
Date: Wed, 3 Feb 2021 15:05:54 +0800 [thread overview]
Message-ID: <20210203070554.1981-1-aaron.li@intel.com> (raw)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3196
Microcode header should be checked before calling
IsMicrocodePatchNeedLoad(). This is to make sure garbage value after
remove microcode from FV would not cause stack overflow in
IsMicrocodePatchNeedLoad().
Signed-off-by: Aaron Li <aaron.li@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rangasai V Chaganty <rangasai.v.chaganty@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
---
Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c | 30 +++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c
index 1494397a8e36..98a7aed69757 100644
--- a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c
+++ b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c
@@ -402,6 +402,7 @@ ShadowMicrocode (
UINTN MaxPatchNumber;
CPU_MICROCODE_HEADER *MicrocodeEntryPoint;
UINTN PatchCount;
+ UINTN DataSize;
UINTN TotalSize;
UINTN TotalLoadSize;
@@ -446,7 +447,34 @@ ShadowMicrocode (
for (Index = 0; Index < EntryNum; Index++) {
if (FitEntry[Index].Type == FIT_TYPE_01_MICROCODE) {
MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (UINTN) FitEntry[Index].Address;
- TotalSize = (MicrocodeEntryPoint->DataSize == 0) ? 2048 : MicrocodeEntryPoint->TotalSize;
+
+ if (*(UINT32 *) MicrocodeEntryPoint == 0xFFFFFFFF) {
+ //
+ // An empty slot for reserved microcode update, skip to check next entry.
+ //
+ continue;
+ }
+
+ if (MicrocodeEntryPoint->HeaderVersion != 0x1) {
+ //
+ // Not a valid microcode header, skip to check next entry.
+ //
+ continue;
+ }
+
+ DataSize = MicrocodeEntryPoint->DataSize;
+ TotalSize = (DataSize == 0) ? 2048 : MicrocodeEntryPoint->TotalSize;
+ if ( (UINTN)MicrocodeEntryPoint > (MAX_ADDRESS - TotalSize) ||
+ (DataSize & 0x3) != 0 ||
+ (TotalSize & (SIZE_1KB - 1)) != 0 ||
+ TotalSize < DataSize
+ ) {
+ //
+ // Not a valid microcode header, skip to check next entry.
+ //
+ continue;
+ }
+
if (IsMicrocodePatchNeedLoad (CpuIdCount, MicrocodeCpuId, MicrocodeEntryPoint)) {
PatchInfoBuffer[PatchCount].Address = (UINTN) MicrocodeEntryPoint;
PatchInfoBuffer[PatchCount].Size = TotalSize;
--
2.29.2.windows.2
next reply other threads:[~2021-02-03 7:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-03 7:05 Aaron Li [this message]
2021-02-04 5:40 ` [PATCH v1 1/1] IntelSiliconPkg/ShadowMicrocodePei: Add microcode header verification Siyuan, Fu
2021-02-04 5:44 ` Ni, Ray
2021-02-05 4:51 ` Ni, Ray
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210203070554.1981-1-aaron.li@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox