Skip to content

Commit 7d35109

Browse files
authored
Bump MessageLength to buffer size for supervisor communications (#650)
## Description The `MessageLength` has been tied to input buffer size in the recent movement of removing core private data. This makes the caller having to change to compensate this because the buffer size was meant to indicate the total buffer size the MM core can use for the return. Given this supervised MM environment has fixed buffer size, already pre-unblocked, it could be treated that the message length will always be covering the entire prepared buffer region. The test is also reverted to verify the corresponding change. - [x] Impacts functionality? - [x] Impacts security? - [ ] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? ## How This Was Tested This was tested on QEMU Q35 and passed the updated test app. ## Integration Instructions N/A
1 parent cb61dae commit 7d35109

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

MmSupervisorPkg/Drivers/MmPeiLaunchers/Common/MmIplCommon.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ SmmCommunicationCommunicateWorker (
144144
CopyMem (CommunicateHeader, CommBuffer, TempCommSize);
145145
}
146146

147+
// When communicating to supervisor, we always bump up the message length to the size of the buffer, so that supervisor can access the entire buffer
148+
if (TalkToSupervisor) {
149+
CommunicateHeader->MessageLength = TempCommSize - OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
150+
}
151+
147152
// MU_CHANGE Ends: MM_SUPV
148153

149154
//

MmSupervisorPkg/Test/MmSupvRequestUnitTestApp/MmSupvRequestUnitTestApp.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ VerifyMemPolicy (
185185
This helper function preps the shared CommBuffer for use by the test step.
186186
187187
@param[out] CommBuffer Returns a pointer to the CommBuffer for the test step to use.
188-
@param[in] AdditionalSize Additional size needed in the CommBuffer for test-specific data.
189188
190189
@retval EFI_SUCCESS CommBuffer initialized and ready to use.
191190
@retval EFI_ABORTED Some error occurred.
@@ -194,8 +193,7 @@ VerifyMemPolicy (
194193
STATIC
195194
EFI_STATUS
196195
MmSupvRequestGetCommBuffer (
197-
OUT MM_SUPERVISOR_REQUEST_HEADER **CommBuffer,
198-
IN UINT64 AdditionalSize
196+
OUT MM_SUPERVISOR_REQUEST_HEADER **CommBuffer
199197
)
200198
{
201199
EFI_MM_COMMUNICATE_HEADER *CommHeader;
@@ -208,7 +206,7 @@ MmSupvRequestGetCommBuffer (
208206

209207
// First, let's zero the comm buffer. Couldn't hurt.
210208
CommHeader = (EFI_MM_COMMUNICATE_HEADER *)mMmSupvCommonCommBufferAddress;
211-
CommBufferSize = AdditionalSize + sizeof (MM_SUPERVISOR_REQUEST_HEADER) + OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data);
209+
CommBufferSize = sizeof (MM_SUPERVISOR_REQUEST_HEADER) + OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data);
212210
if (CommBufferSize > mMmSupvCommonCommBufferSize) {
213211
DEBUG ((DEBUG_ERROR, "[%a] - Communication buffer is too small!\n", __func__));
214212
return EFI_ABORTED;
@@ -218,7 +216,7 @@ MmSupvRequestGetCommBuffer (
218216

219217
// MM Communication Parameters
220218
CopyGuid (&CommHeader->HeaderGuid, &gMmSupervisorRequestHandlerGuid);
221-
CommHeader->MessageLength = sizeof (MM_SUPERVISOR_REQUEST_HEADER) + AdditionalSize;
219+
CommHeader->MessageLength = sizeof (MM_SUPERVISOR_REQUEST_HEADER);
222220

223221
// Return a pointer to the CommBuffer for the test to modify.
224222
*CommBuffer = (MM_SUPERVISOR_REQUEST_HEADER *)CommHeader->Data;
@@ -283,7 +281,7 @@ FetchSecurityPolicyFromSupv (
283281
SecurityPolicy = NULL;
284282

285283
// Grab the CommBuffer and fill it in for this test
286-
Status = MmSupvRequestGetCommBuffer (&CommBuffer, mMmSupvCommonCommBufferSize - sizeof (MM_SUPERVISOR_REQUEST_HEADER) - OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data));
284+
Status = MmSupvRequestGetCommBuffer (&CommBuffer);
287285
if (EFI_ERROR (Status)) {
288286
return NULL;
289287
}
@@ -646,7 +644,7 @@ RequestVersionInfo (
646644
MM_SUPERVISOR_VERSION_INFO_BUFFER *VersionInfo;
647645

648646
// Grab the CommBuffer and fill it in for this test
649-
Status = MmSupvRequestGetCommBuffer (&CommBuffer, sizeof (MM_SUPERVISOR_VERSION_INFO_BUFFER));
647+
Status = MmSupvRequestGetCommBuffer (&CommBuffer);
650648
UT_ASSERT_NOT_EFI_ERROR (Status);
651649

652650
CommBuffer->Signature = MM_SUPERVISOR_REQUEST_SIG;
@@ -698,7 +696,7 @@ RequestUnblockRegion (
698696
}
699697

700698
// Grab the CommBuffer and fill it in for this test
701-
Status = MmSupvRequestGetCommBuffer (&CommBuffer, sizeof (MM_SUPERVISOR_UNBLOCK_MEMORY_PARAMS));
699+
Status = MmSupvRequestGetCommBuffer (&CommBuffer);
702700
UT_ASSERT_NOT_EFI_ERROR (Status);
703701

704702
CommBuffer->Signature = MM_SUPERVISOR_REQUEST_SIG;
@@ -886,7 +884,7 @@ RequestUpdateCommBuffer (
886884
MM_SUPERVISOR_COMM_UPDATE_BUFFER *UpdateCommBuffer;
887885

888886
// Grab the CommBuffer and fill it in for this test
889-
Status = MmSupvRequestGetCommBuffer (&CommBuffer, sizeof (MM_SUPERVISOR_COMM_UPDATE_BUFFER));
887+
Status = MmSupvRequestGetCommBuffer (&CommBuffer);
890888
UT_ASSERT_NOT_EFI_ERROR (Status);
891889

892890
CommBuffer->Signature = MM_SUPERVISOR_REQUEST_SIG;

0 commit comments

Comments
 (0)