[Rebase & FF] Adding MM communication buffer validation - #1846
Conversation
❌ QEMU Validation FailedSource Dependencies
Results
Workflow run: https://github.com/microsoft/mu_basecore/actions/runs/31751859644 This comment was automatically generated by the Mu QEMU PR Validation workflow. |
6d3b895 to
48dff23
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release/202511 #1846 +/- ##
================================================
Coverage ? 0.50%
================================================
Files ? 30
Lines ? 5579
Branches ? 31
================================================
Hits ? 28
Misses ? 5551
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The platform validation is failed due to override hash failure. |
| // BufferSize = CommunicateHeader->MessageLength + | ||
| // sizeof (CommunicateHeader->HeaderGuid) + | ||
| // sizeof (CommunicateHeader->MessageLength); | ||
| Status = SafeUintnAdd ( |
There was a problem hiding this comment.
Given CommunicateHeader->MessageLength is UINT64:
typedef struct {
///
/// Allows for disambiguation of the message format.
///
EFI_GUID HeaderGuid;
///
/// Describes the size of Data (in bytes) and does not include the size of the header.
///
// MU_CHANGE: BZ3398 Make MessageLength the same size in EFI_MM_COMMUNICATE_HEADER for both IA32 and X64.
UINT64 MessageLength;
///
/// Designates an array of bytes that is MessageLength in size.
///
UINT8 Data[1];
} EFI_MM_COMMUNICATE_HEADER;
And BufferSize is UINT64:
typedef struct {
///
/// Indicator GUID for MM core that the communication buffer is compliant with this v3 header.
/// Must be gEfiMmCommunicateHeaderV3Guid.
///
EFI_GUID HeaderGuid;
///
/// Describes the size of the entire buffer (in bytes) available for communication, including this communication header.
///
UINT64 BufferSize;
///
/// Reserved for future use.
///
UINT64 Reserved;
///
/// Allows for disambiguation of the message format.
///
EFI_GUID MessageGuid;
///
/// Describes the size of MessageData (in bytes) and does not include the size of the header.
///
UINT64 MessageSize;
///
/// Designates an array of bytes that is MessageSize in size.
///
UINT8 MessageData[];
} EFI_MM_COMMUNICATE_HEADER_V3;Was there a reason not to use SafeUint64Add() (and in some similar places)?
There was a problem hiding this comment.
I think this is rooted from the original PI spec defining MessageLength to be UINTN. And then a few other interfaces are cascaded with UINTN as the in/out argument type.
We can update the functions used here, and also update the local variables, but we will likely sprinkle a few (other) pointer castings here and there.
There was a problem hiding this comment.
The larger issue that comes to mind is truncation on a 32-bit machine where UINTN is 32-bit (which I don't think is a likely practical target except in the PEI modules). In any case, I think it should be as consistent as possible for the current types while making these types of validation correctness changes.
There was a problem hiding this comment.
Agree with the concern. Part of the issue arise from the common communication routine between v1 and v3. If we separate them, some of the issues will be resolved, where v1 keeps using uintn while v3 uses only u64.
But I think for the case of these DXE phased modules, we have been using 64 bit as far as I am aware, so the UINTN and UINT64 are equivalent. The ARM modules are all UINT64 at this point.
So the only issue is in StandaloneMmIplPei, which does use 2 separate routines for v1 and v3 communicate. I will update the types there to match the native usage.
…ions This change adds the SafeIntLib to communication input routine to validate the incoming MM communication message length before using. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
…ions This change adds the SafeIntLib to communication input routine to validate the incoming MM communication buffer length before using. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
This change adds the SafeIntLib to communication input routine to validate the incoming MM communication buffer length before using. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
…ic operations This change adds the SafeIntLib to communication input routine to validate the incoming MM communication buffer length before using. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
This change adds the SafeIntLib to communication input routine to validate the incoming MM communication buffer length before using. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
This change validates the returned MM communication content against the caller supplied buffer size before copying. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
Description
This change adds a few validation before using the derived buffer size from message length.
However, note that the buffer size is not used directly due to a check after that. Thus the MM communication agent or the core in MM will not consume the value directly. But this would cause the MM handler to potentially receive a huge message in length.
How This Was Tested
This is tested on QEMU ARM Virt platform and booted to Windows desktop.
Integration Instructions
N/A