Changeset 91535 in vbox for trunk/src/VBox
- Timestamp:
- Oct 4, 2021 9:15:19 AM (3 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/NvramStoreImpl.h
r91434 r91535 72 72 73 73 int i_loadStore(const char *pszPath); 74 int i_loadStoreFromTar(RTVFSFSSTREAM hVfsFssTar);75 74 int i_saveStore(void); 76 int i_saveStoreAsTar(void); 75 76 #ifndef VBOX_COM_INPROC 77 HRESULT i_retainUefiVarStore(PRTVFS phVfs, bool fReadonly); 78 HRESULT i_releaseUefiVarStore(RTVFS hVfs); 79 #endif 77 80 78 81 private: … … 84 87 // Wrapped NVRAM store members 85 88 HRESULT initUefiVariableStore(ULONG aSize); 89 90 int i_loadStoreFromTar(RTVFSFSSTREAM hVfsFssTar); 91 int i_saveStoreAsTar(void); 86 92 87 93 #ifdef VBOX_COM_INPROC -
trunk/src/VBox/Main/include/UefiVariableStoreImpl.h
r91457 r91535 41 41 42 42 // public initializer/uninitializer for internal purposes only 43 HRESULT init(NvramStore *aParent, Machine *pMachine , RTVFS hVfsUefiVarStore);43 HRESULT init(NvramStore *aParent, Machine *pMachine); 44 44 void uninit(); 45 45 … … 74 74 void i_uefiAttrMaskToVec(uint32_t fAttr, std::vector<UefiVariableAttributes_T> &aAttributes); 75 75 76 HRESULT i_retainUefiVariableStore(bool fReadonly); 77 HRESULT i_releaseUefiVariableStore(void); 78 76 79 HRESULT i_uefiVarStoreAddVar(PCEFI_GUID pGuid, const char *pszVar, uint32_t fAttr, PRTVFSFILE phVfsFile); 77 80 HRESULT i_uefiVarStoreSetVar(PCEFI_GUID pGuid, const char *pszVar, uint32_t fAttr, const void *pvData, size_t cbData); -
trunk/src/VBox/Main/src-all/NvramStoreImpl.cpp
r91497 r91535 339 339 if (it != m->bd->mapNvram.end()) 340 340 { 341 RTVFSFILE hVfsFileNvram = it->second; 342 RTVFS hVfsEfiVarStore; 343 int vrc = RTEfiVarStoreOpenAsVfs(hVfsFileNvram, 0 /*fMntFlags*/, 0 /*fVarStoreFlags*/, &hVfsEfiVarStore, 344 NULL /*pErrInfo*/); 345 if (RT_SUCCESS(vrc)) 346 { 347 unconst(m->pUefiVarStore).createObject(); 348 m->pUefiVarStore->init(this, m->pParent, hVfsEfiVarStore); 349 } 350 else 351 hrc = setError(E_FAIL, tr("Opening the UEFI variable store failed (%Rrc)."), vrc); 341 unconst(m->pUefiVarStore).createObject(); 342 m->pUefiVarStore->init(this, m->pParent); 352 343 } 353 344 else … … 710 701 711 702 #ifndef VBOX_COM_INPROC 703 HRESULT NvramStore::i_retainUefiVarStore(PRTVFS phVfs, bool fReadonly) 704 { 705 /* the machine needs to be mutable */ 706 AutoMutableStateDependency adep(m->pParent); 707 if (FAILED(adep.rc())) return adep.rc(); 708 709 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); 710 711 HRESULT hrc = S_OK; 712 NvramStoreIter it = m->bd->mapNvram.find("efi/nvram"); 713 if (it != m->bd->mapNvram.end()) 714 { 715 RTVFSFILE hVfsFileNvram = it->second; 716 RTVFS hVfsEfiVarStore; 717 uint32_t fMntFlags = fReadonly ? RTVFSMNT_F_READ_ONLY : 0; 718 719 int vrc = RTEfiVarStoreOpenAsVfs(hVfsFileNvram, fMntFlags, 0 /*fVarStoreFlags*/, &hVfsEfiVarStore, 720 NULL /*pErrInfo*/); 721 if (RT_SUCCESS(vrc)) 722 { 723 *phVfs = hVfsEfiVarStore; 724 if (!fReadonly) 725 m->pParent->i_setModified(Machine::IsModified_NvramStore); 726 } 727 else 728 hrc = setError(E_FAIL, tr("Opening the UEFI variable store failed (%Rrc)."), vrc); 729 } 730 else 731 hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The UEFI NVRAM file is not existing for this machine.")); 732 733 return hrc; 734 } 735 736 737 HRESULT NvramStore::i_releaseUefiVarStore(RTVFS hVfs) 738 { 739 RTVfsRelease(hVfs); 740 return S_OK; 741 } 742 743 712 744 /** 713 745 * Loads settings from the given machine node. … … 753 785 754 786 data.strNvramPath = m->bd->strNvramPath; 755 756 unconst(m->pUefiVarStore) = NULL;757 787 758 788 int vrc = i_saveStore(); -
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.