Changeset 94720 in vbox
- Timestamp:
- Apr 27, 2022 12:58:00 PM (3 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r94660 r94720 21 21 # pragma once 22 22 #endif 23 24 #include <VBox/VBoxCryptoIf.h> 23 25 24 26 #include "VirtualBoxBase.h" … … 292 294 void i_storeSettingsKey(const Utf8Str &aKey); 293 295 bool i_isMediaUuidInUse(const Guid &aId, DeviceType_T deviceType); 296 HRESULT i_retainCryptoIf(PCVBOXCRYPTOIF *ppCryptoIf); 297 HRESULT i_releaseCryptoIf(PCVBOXCRYPTOIF pCryptoIf); 298 HRESULT i_unloadCryptoIfModule(void); 294 299 295 300 -
trunk/src/VBox/Main/src-all/ExtPackManagerImpl.cpp
r94714 r94720 3099 3099 bool fRunningVMs = i_areThereAnyRunningVMs(); 3100 3100 bool fVetoingCP = pExtPack->i_areThereCloudProviderUninstallVetos(); 3101 bool fUnloadedCryptoMod = m->pVirtualBox->i_unloadCryptoIfModule() == S_OK; 3101 3102 autoLock.acquire(); 3102 3103 hrc = i_refreshExtPack(pStrName->c_str(), false /*a_fUnusableIsError*/, &pExtPack); … … 3111 3112 LogRel(("Upgrading extension pack '%s' failed because at least one Cloud Provider is still busy.", pStrName->c_str())); 3112 3113 hrc = setError(E_FAIL, tr("Upgrading extension pack '%s' failed because at least one Cloud Provider is still busy"), 3114 pStrName->c_str()); 3115 } 3116 else if (!fUnloadedCryptoMod) 3117 { 3118 LogRel(("Upgrading extension pack '%s' failed because the cryptographic support module is still in use.", pStrName->c_str())); 3119 hrc = setError(E_FAIL, tr("Upgrading extension pack '%s' failed because the cryptographic support module is still in use"), 3113 3120 pStrName->c_str()); 3114 3121 } … … 3227 3234 bool fRunningVMs = i_areThereAnyRunningVMs(); 3228 3235 bool fVetoingCP = pExtPack->i_areThereCloudProviderUninstallVetos(); 3236 bool fUnloadedCryptoMod = m->pVirtualBox->i_unloadCryptoIfModule() == S_OK; 3229 3237 autoLock.acquire(); 3230 if (a_fForcedRemoval || (!fRunningVMs && !fVetoingCP ))3238 if (a_fForcedRemoval || (!fRunningVMs && !fVetoingCP && fUnloadedCryptoMod)) 3231 3239 { 3232 3240 hrc = i_refreshExtPack(a_pstrName->c_str(), false /*a_fUnusableIsError*/, &pExtPack); … … 3296 3304 a_pstrName->c_str()); 3297 3305 } 3306 else if (!fUnloadedCryptoMod) 3307 { 3308 LogRel(("Uninstall extension pack '%s' failed because the cryptographic support module is still in use.", a_pstrName->c_str())); 3309 hrc = setError(E_FAIL, tr("Uninstall extension pack '%s' failed because the cryptographic support module is still in use"), 3310 a_pstrName->c_str()); 3311 } 3298 3312 else 3299 3313 { -
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r94660 r94720 44 44 #include <VBox/param.h> 45 45 #include <VBox/settings.h> 46 #include <VBox/sup.h> 46 47 #include <VBox/version.h> 47 48 … … 317 318 , fWatcherIsReliable(RTSystemGetNtVersion() >= RTSYSTEM_MAKE_NT_VERSION(6, 0, 0)) 318 319 #endif 320 , hLdrModCrypto(NIL_RTLDRMOD) 321 , cRefsCrypto(0) 322 , pCryptoIf(NULL) 319 323 { 320 324 #if defined(RT_OS_WINDOWS) && defined(VBOXSVC_WITH_CLIENT_WATCHER) … … 441 445 bool fWatcherIsReliable; 442 446 #endif 447 448 /** @name Members related to the cryptographic support interface. 449 * @{ */ 450 /** The loaded module handle if loaded. */ 451 RTLDRMOD hLdrModCrypto; 452 /** Reference counter tracking how many users of the cryptographic support 453 * are there currently. */ 454 volatile uint32_t cRefsCrypto; 455 /** Pointer to the cryptographic support interface. */ 456 PCVBOXCRYPTOIF pCryptoIf; 457 /** @} */ 443 458 }; 444 459 … … 1067 1082 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 1068 1083 1084 /* 1085 * Unload the cryptographic module if loaded before the extension 1086 * pack manager is torn down. 1087 */ 1088 Assert(!m->cRefsCrypto); 1089 if (m->hLdrModCrypto != NIL_RTLDRMOD) 1090 { 1091 m->pCryptoIf = NULL; 1092 1093 int vrc = RTLdrClose(m->hLdrModCrypto); 1094 AssertRC(vrc); 1095 m->hLdrModCrypto = NIL_RTLDRMOD; 1096 } 1097 1069 1098 #ifdef VBOX_WITH_EXTPACK 1070 1099 if (m->ptrExtPackManager) … … 6050 6079 6051 6080 6081 /** 6082 * Retains a reference to the default cryptographic interface. 6083 * 6084 * @returns COM status code. 6085 * @param ppCryptoIf Where to store the pointer to the cryptographic interface on success. 6086 * 6087 * @note Locks this object for writing. 6088 */ 6089 HRESULT VirtualBox::i_retainCryptoIf(PCVBOXCRYPTOIF *ppCryptoIf) 6090 { 6091 AssertReturn(ppCryptoIf != NULL, E_INVALIDARG); 6092 6093 AutoCaller autoCaller(this); 6094 AssertComRCReturnRC(autoCaller.rc()); 6095 6096 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); 6097 6098 /* Try to load the extension pack module if it isn't currently. */ 6099 HRESULT hrc = S_OK; 6100 if (m->hLdrModCrypto == NIL_RTLDRMOD) 6101 { 6102 /* 6103 * Check that a crypto extension pack name is set and resolve it into a 6104 * library path. 6105 */ 6106 Utf8Str strExtPack; 6107 hrc = m->pSystemProperties->getDefaultCryptoExtPack(strExtPack); 6108 if (FAILED(hrc)) 6109 return hrc; 6110 if (strExtPack.isEmpty()) 6111 return setError(VBOX_E_OBJECT_NOT_FOUND, 6112 tr("Ńo extension pack providing a crpytographic support module could be found")); 6113 6114 Utf8Str strCryptoLibrary; 6115 int vrc = m->ptrExtPackManager->i_getCryptoLibraryPathForExtPack(&strExtPack, &strCryptoLibrary); 6116 if (RT_SUCCESS(vrc)) 6117 { 6118 RTERRINFOSTATIC ErrInfo; 6119 vrc = SUPR3HardenedLdrLoadPlugIn(strCryptoLibrary.c_str(), &m->hLdrModCrypto, RTErrInfoInitStatic(&ErrInfo)); 6120 if (RT_SUCCESS(vrc)) 6121 { 6122 /* Resolve the entry point and query the pointer to the cryptographic interface. */ 6123 PFNVBOXCRYPTOENTRY pfnCryptoEntry = NULL; 6124 vrc = RTLdrGetSymbol(m->hLdrModCrypto, VBOX_CRYPTO_MOD_ENTRY_POINT, (void **)&pfnCryptoEntry); 6125 if (RT_SUCCESS(vrc)) 6126 { 6127 vrc = pfnCryptoEntry(&m->pCryptoIf); 6128 if (RT_FAILURE(vrc)) 6129 hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrc, 6130 tr("Failed to query the interface callback table from the cryptographic support module '%s' from extension pack '%s'"), 6131 strCryptoLibrary.c_str(), strExtPack.c_str()); 6132 } 6133 else 6134 hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrc, 6135 tr("Failed to resolve the entry point for the cryptographic support module '%s' from extension pack '%s'"), 6136 strCryptoLibrary.c_str(), strExtPack.c_str()); 6137 } 6138 else 6139 hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrc, 6140 tr("Couldn't load the cryptographic support module '%s' from extension pack '%s' (error: '%s')"), 6141 strCryptoLibrary.c_str(), strExtPack.c_str(), ErrInfo.Core.pszMsg); 6142 } 6143 else 6144 hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrc, 6145 tr("Couldn't resolve the library path of the crpytographic support module for extension pack '%s'"), 6146 strExtPack.c_str()); 6147 } 6148 6149 if (SUCCEEDED(hrc)) 6150 { 6151 ASMAtomicIncU32(&m->cRefsCrypto); 6152 *ppCryptoIf = m->pCryptoIf; 6153 } 6154 6155 return hrc; 6156 } 6157 6158 6159 /** 6160 * Releases the reference of the given cryptographic interface. 6161 * 6162 * @returns COM status code. 6163 * @param pCryptoIf Pointer to the cryptographic interface to release. 6164 * 6165 * @note Locks this object for writing. 6166 */ 6167 HRESULT VirtualBox::i_releaseCryptoIf(PCVBOXCRYPTOIF pCryptoIf) 6168 { 6169 AutoCaller autoCaller(this); 6170 AssertComRCReturnRC(autoCaller.rc()); 6171 6172 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); 6173 6174 AssertReturn(pCryptoIf == m->pCryptoIf, E_INVALIDARG); 6175 6176 ASMAtomicDecU32(&m->cRefsCrypto); 6177 return S_OK; 6178 } 6179 6180 6181 /** 6182 * Tries to unload any loaded cryptographic support module if it is not in use currently. 6183 * 6184 * @returns COM status code. 6185 * 6186 * @note Locks this object for writing. 6187 */ 6188 HRESULT VirtualBox::i_unloadCryptoIfModule(void) 6189 { 6190 AutoCaller autoCaller(this); 6191 AssertComRCReturnRC(autoCaller.rc()); 6192 6193 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); 6194 6195 if (m->cRefsCrypto) 6196 return setError(E_ACCESSDENIED, 6197 tr("The cryptographic support module is in use and can't be unloaded")); 6198 6199 if (m->hLdrModCrypto != NIL_RTLDRMOD) 6200 { 6201 int vrc = RTLdrClose(m->hLdrModCrypto); 6202 AssertRC(vrc); 6203 m->hLdrModCrypto = NIL_RTLDRMOD; 6204 } 6205 6206 return S_OK; 6207 } 6208 6209 6052 6210 #ifdef RT_OS_WINDOWS 6053 6211 #include <psapi.h>
Note:
See TracChangeset
for help on using the changeset viewer.