Changeset 58459 in vbox for trunk/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal/LockBox
- Timestamp:
- Oct 28, 2015 8:17:18 PM (9 years ago)
- Location:
- trunk/src/VBox/Devices/EFI/Firmware
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/Firmware
-
Property svn:mergeinfo
set to (toggle deleted branches)
/vendor/edk2/current 103735-103757
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.c
r48674 r58459 1 1 /** @file 2 3 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR> 2 LockBox SMM driver. 3 4 Caution: This module requires additional review when modified. 5 This driver will have external input - communicate buffer in SMM mode. 6 This external input must be validated carefully to avoid security issue like 7 buffer overflow, integer overflow. 8 9 SmmLockBoxHandler(), SmmLockBoxRestore(), SmmLockBoxUpdate(), SmmLockBoxSave() 10 will receive untrusted input and do basic validation. 11 12 Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR> 4 13 5 14 This program and the accompanying materials … … 22 31 #include <Library/BaseMemoryLib.h> 23 32 #include <Library/DebugLib.h> 33 #include <Library/SmmMemLib.h> 24 34 #include <Library/LockBoxLib.h> 35 25 36 #include <Protocol/SmmReadyToLock.h> 26 37 #include <Protocol/SmmCommunication.h> 27 #include <Protocol/SmmAccess2.h>28 38 #include <Protocol/LockBox.h> 29 39 #include <Guid/SmmLockBox.h> … … 31 41 BOOLEAN mLocked = FALSE; 32 42 33 EFI_SMRAM_DESCRIPTOR *mSmramRanges;34 UINTN mSmramRangeCount;35 36 /**37 This function check if the address is in SMRAM.38 39 @param Buffer the buffer address to be checked.40 @param Length the buffer length to be checked.41 42 @retval TRUE this address is in SMRAM.43 @retval FALSE this address is NOT in SMRAM.44 **/45 BOOLEAN46 IsAddressInSmram (47 IN EFI_PHYSICAL_ADDRESS Buffer,48 IN UINT64 Length49 )50 {51 UINTN Index;52 53 for (Index = 0; Index < mSmramRangeCount; Index ++) {54 if (((Buffer >= mSmramRanges[Index].CpuStart) && (Buffer < mSmramRanges[Index].CpuStart + mSmramRanges[Index].PhysicalSize)) ||55 ((mSmramRanges[Index].CpuStart >= Buffer) && (mSmramRanges[Index].CpuStart < Buffer + Length))) {56 return TRUE;57 }58 }59 60 return FALSE;61 }62 63 43 /** 64 44 Dispatch function for SMM lock box save. 45 46 Caution: This function may receive untrusted input. 47 Restore buffer and length are external input, so this function will validate 48 it is in SMRAM. 65 49 66 50 @param LockBoxParameterSave parameter of lock box save … … 72 56 { 73 57 EFI_STATUS Status; 58 EFI_SMM_LOCK_BOX_PARAMETER_SAVE TempLockBoxParameterSave; 74 59 75 60 // … … 82 67 } 83 68 69 CopyMem (&TempLockBoxParameterSave, LockBoxParameterSave, sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SAVE)); 70 71 // 72 // Sanity check 73 // 74 if (!SmmIsBufferOutsideSmmValid ((UINTN)TempLockBoxParameterSave.Buffer, (UINTN)TempLockBoxParameterSave.Length)) { 75 DEBUG ((EFI_D_ERROR, "SmmLockBox Save address in SMRAM or buffer overflow!\n")); 76 LockBoxParameterSave->Header.ReturnStatus = (UINT64)EFI_ACCESS_DENIED; 77 return ; 78 } 79 84 80 // 85 81 // Save data 86 82 // 87 83 Status = SaveLockBox ( 88 & LockBoxParameterSave->Guid,89 (VOID *)(UINTN) LockBoxParameterSave->Buffer,90 (UINTN) LockBoxParameterSave->Length84 &TempLockBoxParameterSave.Guid, 85 (VOID *)(UINTN)TempLockBoxParameterSave.Buffer, 86 (UINTN)TempLockBoxParameterSave.Length 91 87 ); 92 88 LockBoxParameterSave->Header.ReturnStatus = (UINT64)Status; … … 105 101 { 106 102 EFI_STATUS Status; 103 EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES TempLockBoxParameterSetAttributes; 107 104 108 105 // … … 115 112 } 116 113 114 CopyMem (&TempLockBoxParameterSetAttributes, LockBoxParameterSetAttributes, sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES)); 115 117 116 // 118 117 // Update data 119 118 // 120 119 Status = SetLockBoxAttributes ( 121 & LockBoxParameterSetAttributes->Guid,122 LockBoxParameterSetAttributes->Attributes120 &TempLockBoxParameterSetAttributes.Guid, 121 TempLockBoxParameterSetAttributes.Attributes 123 122 ); 124 123 LockBoxParameterSetAttributes->Header.ReturnStatus = (UINT64)Status; … … 129 128 Dispatch function for SMM lock box update. 130 129 130 Caution: This function may receive untrusted input. 131 Restore buffer and length are external input, so this function will validate 132 it is in SMRAM. 133 131 134 @param LockBoxParameterUpdate parameter of lock box update 132 135 **/ … … 137 140 { 138 141 EFI_STATUS Status; 142 EFI_SMM_LOCK_BOX_PARAMETER_UPDATE TempLockBoxParameterUpdate; 139 143 140 144 // … … 147 151 } 148 152 153 CopyMem (&TempLockBoxParameterUpdate, LockBoxParameterUpdate, sizeof (EFI_SMM_LOCK_BOX_PARAMETER_UPDATE)); 154 155 // 156 // Sanity check 157 // 158 if (!SmmIsBufferOutsideSmmValid ((UINTN)TempLockBoxParameterUpdate.Buffer, (UINTN)TempLockBoxParameterUpdate.Length)) { 159 DEBUG ((EFI_D_ERROR, "SmmLockBox Update address in SMRAM or buffer overflow!\n")); 160 LockBoxParameterUpdate->Header.ReturnStatus = (UINT64)EFI_ACCESS_DENIED; 161 return ; 162 } 163 149 164 // 150 165 // Update data 151 166 // 152 167 Status = UpdateLockBox ( 153 & LockBoxParameterUpdate->Guid,154 (UINTN) LockBoxParameterUpdate->Offset,155 (VOID *)(UINTN) LockBoxParameterUpdate->Buffer,156 (UINTN) LockBoxParameterUpdate->Length168 &TempLockBoxParameterUpdate.Guid, 169 (UINTN)TempLockBoxParameterUpdate.Offset, 170 (VOID *)(UINTN)TempLockBoxParameterUpdate.Buffer, 171 (UINTN)TempLockBoxParameterUpdate.Length 157 172 ); 158 173 LockBoxParameterUpdate->Header.ReturnStatus = (UINT64)Status; … … 163 178 Dispatch function for SMM lock box restore. 164 179 180 Caution: This function may receive untrusted input. 181 Restore buffer and length are external input, so this function will validate 182 it is in SMRAM. 183 165 184 @param LockBoxParameterRestore parameter of lock box restore 166 185 **/ … … 171 190 { 172 191 EFI_STATUS Status; 173 174 // 175 // Sanity check 176 // 177 if (IsAddressInSmram (LockBoxParameterRestore->Buffer, LockBoxParameterRestore->Length)) { 178 DEBUG ((EFI_D_ERROR, "SmmLockBox Restore address in SMRAM!\n")); 192 EFI_SMM_LOCK_BOX_PARAMETER_RESTORE TempLockBoxParameterRestore; 193 194 CopyMem (&TempLockBoxParameterRestore, LockBoxParameterRestore, sizeof (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE)); 195 196 // 197 // Sanity check 198 // 199 if (!SmmIsBufferOutsideSmmValid ((UINTN)TempLockBoxParameterRestore.Buffer, (UINTN)TempLockBoxParameterRestore.Length)) { 200 DEBUG ((EFI_D_ERROR, "SmmLockBox Restore address in SMRAM or buffer overflow!\n")); 179 201 LockBoxParameterRestore->Header.ReturnStatus = (UINT64)EFI_ACCESS_DENIED; 180 202 return ; … … 184 206 // Restore data 185 207 // 186 if (( LockBoxParameterRestore->Length == 0) && (LockBoxParameterRestore->Buffer == 0)) {208 if ((TempLockBoxParameterRestore.Length == 0) && (TempLockBoxParameterRestore.Buffer == 0)) { 187 209 Status = RestoreLockBox ( 188 & LockBoxParameterRestore->Guid,210 &TempLockBoxParameterRestore.Guid, 189 211 NULL, 190 212 NULL … … 192 214 } else { 193 215 Status = RestoreLockBox ( 194 & LockBoxParameterRestore->Guid,195 (VOID *)(UINTN) LockBoxParameterRestore->Buffer,196 (UINTN *)& LockBoxParameterRestore->Length216 &TempLockBoxParameterRestore.Guid, 217 (VOID *)(UINTN)TempLockBoxParameterRestore.Buffer, 218 (UINTN *)&TempLockBoxParameterRestore.Length 197 219 ); 198 220 } … … 220 242 /** 221 243 Dispatch function for a Software SMI handler. 244 245 Caution: This function may receive untrusted input. 246 Communicate buffer and buffer size are external input, so this function will do basic validation. 222 247 223 248 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister(). … … 241 266 { 242 267 EFI_SMM_LOCK_BOX_PARAMETER_HEADER *LockBoxParameterHeader; 268 UINTN TempCommBufferSize; 243 269 244 270 DEBUG ((EFI_D_ERROR, "SmmLockBox SmmLockBoxHandler Enter\n")); 271 272 // 273 // If input is invalid, stop processing this SMI 274 // 275 if (CommBuffer == NULL || CommBufferSize == NULL) { 276 return EFI_SUCCESS; 277 } 278 279 TempCommBufferSize = *CommBufferSize; 280 281 // 282 // Sanity check 283 // 284 if (TempCommBufferSize < sizeof(EFI_SMM_LOCK_BOX_PARAMETER_HEADER)) { 285 DEBUG ((EFI_D_ERROR, "SmmLockBox Command Buffer Size invalid!\n")); 286 return EFI_SUCCESS; 287 } 288 if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) { 289 DEBUG ((EFI_D_ERROR, "SmmLockBox Command Buffer in SMRAM or overflow!\n")); 290 return EFI_SUCCESS; 291 } 245 292 246 293 LockBoxParameterHeader = (EFI_SMM_LOCK_BOX_PARAMETER_HEADER *)((UINTN)CommBuffer); … … 254 301 switch (LockBoxParameterHeader->Command) { 255 302 case EFI_SMM_LOCK_BOX_COMMAND_SAVE: 303 if (TempCommBufferSize < sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)) { 304 DEBUG ((EFI_D_ERROR, "SmmLockBox Command Buffer Size for SAVE invalid!\n")); 305 break; 306 } 256 307 SmmLockBoxSave ((EFI_SMM_LOCK_BOX_PARAMETER_SAVE *)(UINTN)LockBoxParameterHeader); 257 308 break; 258 309 case EFI_SMM_LOCK_BOX_COMMAND_UPDATE: 310 if (TempCommBufferSize < sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE)) { 311 DEBUG ((EFI_D_ERROR, "SmmLockBox Command Buffer Size for UPDATE invalid!\n")); 312 break; 313 } 259 314 SmmLockBoxUpdate ((EFI_SMM_LOCK_BOX_PARAMETER_UPDATE *)(UINTN)LockBoxParameterHeader); 260 315 break; 261 316 case EFI_SMM_LOCK_BOX_COMMAND_RESTORE: 317 if (TempCommBufferSize < sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE)) { 318 DEBUG ((EFI_D_ERROR, "SmmLockBox Command Buffer Size for RESTORE invalid!\n")); 319 break; 320 } 262 321 SmmLockBoxRestore ((EFI_SMM_LOCK_BOX_PARAMETER_RESTORE *)(UINTN)LockBoxParameterHeader); 263 322 break; 264 323 case EFI_SMM_LOCK_BOX_COMMAND_SET_ATTRIBUTES: 324 if (TempCommBufferSize < sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES)) { 325 DEBUG ((EFI_D_ERROR, "SmmLockBox Command Buffer Size for SET_ATTRIBUTES invalid!\n")); 326 break; 327 } 265 328 SmmLockBoxSetAttributes ((EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES *)(UINTN)LockBoxParameterHeader); 266 329 break; 267 330 case EFI_SMM_LOCK_BOX_COMMAND_RESTORE_ALL_IN_PLACE: 331 if (TempCommBufferSize < sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)) { 332 DEBUG ((EFI_D_ERROR, "SmmLockBox Command Buffer Size for RESTORE_ALL_IN_PLACE invalid!\n")); 333 break; 334 } 268 335 SmmLockBoxRestoreAllInPlace ((EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE *)(UINTN)LockBoxParameterHeader); 269 336 break; 270 337 default: 338 DEBUG ((EFI_D_ERROR, "SmmLockBox Command invalid!\n")); 271 339 break; 272 340 } … … 321 389 EFI_HANDLE DispatchHandle; 322 390 VOID *Registration; 323 EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;324 UINTN Size;325 326 //327 // Get SMRAM information328 //329 Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess);330 ASSERT_EFI_ERROR (Status);331 332 Size = 0;333 Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);334 ASSERT (Status == EFI_BUFFER_TOO_SMALL);335 336 Status = gSmst->SmmAllocatePool (337 EfiRuntimeServicesData,338 Size,339 (VOID **)&mSmramRanges340 );341 ASSERT_EFI_ERROR (Status);342 343 Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmramRanges);344 ASSERT_EFI_ERROR (Status);345 346 mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);347 391 348 392 // -
trunk/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
r48674 r58459 1 1 ## @file 2 # Component description file forLockBox SMM driver.2 # LockBox SMM driver. 3 3 # 4 # Copyright (c) 2010, Intel Corporation. All rights reserved.<BR> 4 # Caution: This module requires additional review when modified. 5 # This driver will have external input - communicate buffer in SMM mode. 6 # This external input must be validated carefully to avoid security issue like 7 # buffer overflow, integer overflow. 8 # 9 # Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR> 5 10 # 6 11 # This program and the accompanying materials … … 18 23 INF_VERSION = 0x00010005 19 24 BASE_NAME = SmmLockBox 25 MODULE_UNI_FILE = SmmLockBox.uni 20 26 FILE_GUID = 33FB3535-F15E-4c17-B303-5EB94595ECB6 21 27 MODULE_TYPE = DXE_SMM_DRIVER … … 40 46 UefiDriverEntryPoint 41 47 UefiBootServicesTableLib 42 UefiRuntimeServicesTableLib43 48 SmmServicesTableLib 44 49 BaseLib … … 46 51 DebugLib 47 52 LockBoxLib 53 SmmMemLib 48 54 49 55 [Guids] 50 gEfiSmmLockBoxCommunicationGuid ## PRODUCED56 gEfiSmmLockBoxCommunicationGuid ## PRODUCES ## GUID # SmiHandlerRegister 51 57 52 58 [Protocols] 53 gEfiSmmReadyToLockProtocolGuid ## CONSUMED 54 gEfiSmmAccess2ProtocolGuid ## CONSUMED 55 gEfiLockBoxProtocolGuid ## PRODUCED 59 gEfiSmmReadyToLockProtocolGuid ## NOTIFY 60 gEfiLockBoxProtocolGuid ## PRODUCES 56 61 57 62 [Depex] 58 gEfiSmmSwDispatch2ProtocolGuid63 TRUE 59 64 65 [UserExtensions.TianoCore."ExtraFiles"] 66 SmmLockBoxExtra.uni
Note:
See TracChangeset
for help on using the changeset viewer.