Update MsWheaEarlyStorageGetMaxSize() and MsWheaESGetMaxDataCount() to Check ES Region Size PCD

Description

As MsWheaEarlyStorageLib is written, PcdMsWheaReportEarlyStorageCapacity
must include the offset of the MS WHEA early storage region. This
expectation is unintuitive and can lead to configuration errors and
underflow in MsWheaEarlyStorageGetMaxSize(). Instead of changing the
PCD to not include the offset (and consequentially force existing
platforms to update) this change checks that the PCD is at least as
large as the offset and ASSERTs if not. This change also updates
MsWheaESGetMaxDataCount() to avoid underflow if the ES region is smaller
than the header size.

- [x] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [ ] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [x] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

How This Was Tested

Running the MsWheaEarlyUnitTestApp on Q35

Integration Instructions

N/A
This commit is contained in:
Taylor Beebe 2023-04-26 17:29:47 -07:00 коммит произвёл Ken Lautner
Родитель 644d3aa0a4
Коммит ce2593289e
1 изменённых файлов: 21 добавлений и 2 удалений

Просмотреть файл

@ -201,7 +201,17 @@ MsWheaEarlyStorageGetMaxSize (
VOID
)
{
return (UINT8)((PcdGet32 (PcdMsWheaReportEarlyStorageCapacity) - (MS_WHEA_EARLY_STORAGE_OFFSET)) & 0xFF);
UINT32 Capacity;
Capacity = PcdGet32 (PcdMsWheaReportEarlyStorageCapacity);
// The offset of the whea storage must be included in the capacity. If the capacity
// is less than the offset, ASSERT and return 0.
if (Capacity < MS_WHEA_EARLY_STORAGE_OFFSET) {
ASSERT (Capacity >= MS_WHEA_EARLY_STORAGE_OFFSET);
return 0;
}
return (UINT8)((Capacity - (MS_WHEA_EARLY_STORAGE_OFFSET)) & 0xFF);
}
/**
@ -317,7 +327,16 @@ MsWheaESGetMaxDataCount (
VOID
)
{
return (UINT8)((MsWheaEarlyStorageGetMaxSize () - (MS_WHEA_EARLY_STORAGE_DATA_OFFSET)) & 0xFF);
UINT8 MaxSize;
MaxSize = MsWheaEarlyStorageGetMaxSize ();
// Avoid subtraction underflow
if (MaxSize < MS_WHEA_EARLY_STORAGE_DATA_OFFSET) {
return 0;
}
return (UINT8)((MaxSize - (MS_WHEA_EARLY_STORAGE_DATA_OFFSET)) & 0xFF);
}
/**