Changeset 91535 in vbox for trunk/src/VBox/Main/src-server/UefiVariableStoreImpl.cpp
- Timestamp:
- Oct 4, 2021 9:15:19 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/UefiVariableStoreImpl.cpp
r91490 r91535 89 89 * @param aParent The NVRAM store owning the UEFI NVRAM content. 90 90 * @param pMachine 91 * @param hVfsUefiVarStore The UEFI variable store VFS handle. 92 */ 93 HRESULT UefiVariableStore::init(NvramStore *aParent, Machine *pMachine, RTVFS hVfsUefiVarStore) 91 */ 92 HRESULT UefiVariableStore::init(NvramStore *aParent, Machine *pMachine) 94 93 { 95 94 LogFlowThisFuncEnter(); … … 105 104 106 105 /* share the parent weakly */ 107 unconst(m->pParent) = aParent;106 unconst(m->pParent) = aParent; 108 107 unconst(m->pMachine) = pMachine; 109 m->hVfsUefiVarStore = hVfsUefiVarStore;108 m->hVfsUefiVarStore = NIL_RTVFS; 110 109 111 110 autoInitSpan.setSucceeded(); … … 129 128 return; 130 129 131 RTVfsRelease(m->hVfsUefiVarStore);130 Assert(m->hVfsUefiVarStore == NIL_RTVFS); 132 131 133 132 unconst(m->pParent) = NULL; … … 147 146 if (FAILED(adep.rc())) return adep.rc(); 148 147 148 HRESULT hrc = i_retainUefiVariableStore(true /*fReadonly*/); 149 if (FAILED(hrc)) return hrc; 150 149 151 AutoReadLock rlock(this COMMA_LOCKVAL_SRC_POS); 150 152 151 HRESULT hrc = S_OK;152 153 uint64_t cbVar = 0; 153 154 int vrc = i_uefiVarStoreQueryVarSz("PK", &cbVar); … … 178 179 hrc = setError(E_FAIL, tr("Failed to query the platform key variable size: %Rrc"), vrc); 179 180 181 i_releaseUefiVariableStore(); 180 182 return hrc; 181 183 } … … 187 189 AutoMutableStateDependency adep(m->pMachine); 188 190 if (FAILED(adep.rc())) return adep.rc(); 191 192 HRESULT hrc = i_retainUefiVariableStore(false /*fReadonly*/); 193 if (FAILED(hrc)) return hrc; 189 194 190 195 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); … … 196 201 { 197 202 uint8_t bVar = fEnabled ? 0x1 : 0x0; 198 returni_uefiVarStoreSetVar(&GuidSecureBootEnable, "SecureBootEnable",199 200 201 202 203 hrc = i_uefiVarStoreSetVar(&GuidSecureBootEnable, "SecureBootEnable", 204 EFI_VAR_HEADER_ATTR_NON_VOLATILE 205 | EFI_VAR_HEADER_ATTR_BOOTSERVICE_ACCESS 206 | EFI_VAR_HEADER_ATTR_RUNTIME_ACCESS, 207 &bVar, sizeof(bVar)); 203 208 } 204 209 else if (vrc == VERR_FILE_NOT_FOUND) /* No platform key means no secure boot support. */ 205 return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Secure boot is not available because the platform key (PK) is not enrolled")); 206 207 return setError(E_FAIL, tr("Failed to query the platform key variable size: %Rrc"), vrc); 210 hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("Secure boot is not available because the platform key (PK) is not enrolled")); 211 else 212 hrc = setError(E_FAIL, tr("Failed to query the platform key variable size: %Rrc"), vrc); 213 214 i_releaseUefiVariableStore(); 215 return hrc; 208 216 } 209 217 … … 217 225 if (FAILED(adep.rc())) return adep.rc(); 218 226 227 HRESULT hrc = i_retainUefiVariableStore(false /*fReadonly*/); 228 if (FAILED(hrc)) return hrc; 229 219 230 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); 220 231 … … 222 233 EFI_GUID OwnerGuid; 223 234 RTEfiGuidFromUuid(&OwnerGuid, aOwnerUuid.raw()); 224 return i_uefiVarStoreSetVar(&OwnerGuid, aName.c_str(), fAttr, &aData.front(), aData.size()); 235 hrc = i_uefiVarStoreSetVar(&OwnerGuid, aName.c_str(), fAttr, &aData.front(), aData.size()); 236 237 i_releaseUefiVariableStore(); 238 return hrc; 225 239 } 226 240 … … 244 258 std::vector<BYTE> &aData) 245 259 { 246 RT_NOREF(aName, aOwnerUuid, aAttributes, aData); 247 248 HRESULT hrc = S_OK; 260 /* the machine needs to be mutable */ 261 AutoMutableStateDependency adep(m->pMachine); 262 if (FAILED(adep.rc())) return adep.rc(); 263 264 HRESULT hrc = i_retainUefiVariableStore(true /*fReadonly*/); 265 if (FAILED(hrc)) return hrc; 266 267 AutoReadLock rlock(this COMMA_LOCKVAL_SRC_POS); 268 249 269 uint32_t fAttr; 250 270 int vrc = i_uefiVarStoreQueryVarAttr(aName.c_str(), &fAttr); … … 276 296 hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to query the attributes of variable '%s': %Rrc"), aName.c_str(), vrc); 277 297 298 i_releaseUefiVariableStore(); 278 299 return hrc; 279 300 } … … 286 307 AutoMutableStateDependency adep(m->pMachine); 287 308 if (FAILED(adep.rc())) return adep.rc(); 309 310 HRESULT hrc = i_retainUefiVariableStore(true /*fReadonly*/); 311 if (FAILED(hrc)) return hrc; 288 312 289 313 AutoReadLock rlock(this COMMA_LOCKVAL_SRC_POS); … … 317 341 } 318 342 343 i_releaseUefiVariableStore(); 344 319 345 if (RT_FAILURE(vrc)) 320 346 return setError(VBOX_E_IPRT_ERROR, tr("Failed to query the variables: %Rrc"), vrc); … … 329 355 AutoMutableStateDependency adep(m->pMachine); 330 356 if (FAILED(adep.rc())) return adep.rc(); 357 358 HRESULT hrc = i_retainUefiVariableStore(false /*fReadonly*/); 359 if (FAILED(hrc)) return hrc; 331 360 332 361 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); … … 341 370 const com::Guid GuidVBox(UuidVBox); 342 371 343 return i_uefiVarStoreAddSignatureToDb(&GuidGlobalVar, "PK", g_abUefiOracleDefPk, g_cbUefiOracleDefPk, 344 GuidVBox, SignatureType_X509); 372 hrc = i_uefiVarStoreAddSignatureToDb(&GuidGlobalVar, "PK", g_abUefiOracleDefPk, g_cbUefiOracleDefPk, 373 GuidVBox, SignatureType_X509); 374 375 i_releaseUefiVariableStore(); 376 return hrc; 345 377 } 346 378 … … 352 384 if (FAILED(adep.rc())) return adep.rc(); 353 385 386 HRESULT hrc = i_retainUefiVariableStore(false /*fReadonly*/); 387 if (FAILED(hrc)) return hrc; 388 354 389 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); 355 390 356 391 EFI_GUID GuidGlobalVar = EFI_GLOBAL_VARIABLE_GUID; 357 return i_uefiVarStoreAddSignatureToDbVec(&GuidGlobalVar, "PK", aData, aOwnerUuid, SignatureType_X509); 392 hrc = i_uefiVarStoreAddSignatureToDbVec(&GuidGlobalVar, "PK", aData, aOwnerUuid, SignatureType_X509); 393 394 i_releaseUefiVariableStore(); 395 return hrc; 358 396 } 359 397 … … 365 403 if (FAILED(adep.rc())) return adep.rc(); 366 404 405 HRESULT hrc = i_retainUefiVariableStore(false /*fReadonly*/); 406 if (FAILED(hrc)) return hrc; 407 367 408 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); 368 409 369 410 EFI_GUID GuidGlobalVar = EFI_GLOBAL_VARIABLE_GUID; 370 return i_uefiVarStoreAddSignatureToDbVec(&GuidGlobalVar, "KEK", aData, aOwnerUuid, enmSignatureType); 411 hrc = i_uefiVarStoreAddSignatureToDbVec(&GuidGlobalVar, "KEK", aData, aOwnerUuid, enmSignatureType); 412 413 i_releaseUefiVariableStore(); 414 return hrc; 371 415 } 372 416 … … 378 422 if (FAILED(adep.rc())) return adep.rc(); 379 423 424 HRESULT hrc = i_retainUefiVariableStore(false /*fReadonly*/); 425 if (FAILED(hrc)) return hrc; 426 380 427 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); 381 428 382 429 EFI_GUID GuidSecurityDb = EFI_GLOBAL_VARIABLE_GUID; 383 return i_uefiVarStoreAddSignatureToDbVec(&GuidSecurityDb, "db", aData, aOwnerUuid, enmSignatureType); 430 hrc = i_uefiVarStoreAddSignatureToDbVec(&GuidSecurityDb, "db", aData, aOwnerUuid, enmSignatureType); 431 432 i_releaseUefiVariableStore(); 433 return hrc; 384 434 } 385 435 … … 391 441 if (FAILED(adep.rc())) return adep.rc(); 392 442 443 HRESULT hrc = i_retainUefiVariableStore(false /*fReadonly*/); 444 if (FAILED(hrc)) return hrc; 445 393 446 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); 394 447 395 448 EFI_GUID GuidSecurityDb = EFI_IMAGE_SECURITY_DATABASE_GUID; 396 return i_uefiVarStoreAddSignatureToDbVec(&GuidSecurityDb, "dbx", aData, aOwnerUuid, enmSignatureType); 449 hrc = i_uefiVarStoreAddSignatureToDbVec(&GuidSecurityDb, "dbx", aData, aOwnerUuid, enmSignatureType); 450 451 i_releaseUefiVariableStore(); 452 return hrc; 397 453 } 398 454 … … 402 458 AutoMutableStateDependency adep(m->pMachine); 403 459 if (FAILED(adep.rc())) return adep.rc(); 460 461 HRESULT hrc = i_retainUefiVariableStore(false /*fReadonly*/); 462 if (FAILED(hrc)) return hrc; 404 463 405 464 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); … … 415 474 const com::Guid GuidMs(UuidMs); 416 475 417 HRESULThrc = i_uefiVarStoreAddSignatureToDb(&EfiGuidGlobalVar, "KEK", g_abUefiMicrosoftKek, g_cbUefiMicrosoftKek,418 476 hrc = i_uefiVarStoreAddSignatureToDb(&EfiGuidGlobalVar, "KEK", g_abUefiMicrosoftKek, g_cbUefiMicrosoftKek, 477 GuidMs, SignatureType_X509); 419 478 if (SUCCEEDED(hrc)) 420 479 { … … 426 485 } 427 486 487 i_releaseUefiVariableStore(); 428 488 return hrc; 429 489 } … … 591 651 592 652 /** 653 * Retains the reference of the variable store from the parent. 654 * 655 * @returns COM status code. 656 * @param fReadonly Flag whether the access is readonly. 657 */ 658 HRESULT UefiVariableStore::i_retainUefiVariableStore(bool fReadonly) 659 { 660 Assert(m->hVfsUefiVarStore = NIL_RTVFS); 661 return m->pParent->i_retainUefiVarStore(&m->hVfsUefiVarStore, fReadonly); 662 } 663 664 665 /** 666 * Releases the reference of the variable store from the parent. 667 * 668 * @returns COM status code. 669 */ 670 HRESULT UefiVariableStore::i_releaseUefiVariableStore(void) 671 { 672 RTVFS hVfs = m->hVfsUefiVarStore; 673 674 m->hVfsUefiVarStore = NIL_RTVFS; 675 return m->pParent->i_releaseUefiVarStore(hVfs); 676 } 677 678 679 /** 593 680 * Adds the given variable to the variable store. 594 681 *
Note:
See TracChangeset
for help on using the changeset viewer.