Changeset 52414 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Aug 19, 2014 2:05:18 PM (10 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support/win
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp
r52406 r52414 179 179 PFNCRYPTCATCATALOGINFOFROMCONTEXT g_pfnCryptCATCatalogInfoFromContext; 180 180 181 /** Indicates active WinVerifyTrust thread. */ 181 /** Where we store the TLS entry for detecting WinVerifyTrustRecursion. */ 182 static uint32_t g_iTlsWinVerifyTrustRecursion = UINT32_MAX; 183 /** Fallback WinVerifyTrust recursion protection. */ 182 184 static uint32_t volatile g_idActiveThread = UINT32_MAX; 183 185 … … 1870 1872 1871 1873 /* 1874 * Allocate TLS entry for WinVerifyTrust recursion prevention. 1875 */ 1876 DWORD iTls = TlsAlloc(); 1877 if (iTls != TLS_OUT_OF_INDEXES) 1878 g_iTlsWinVerifyTrustRecursion = iTls; 1879 else 1880 supR3HardenedError(GetLastError(), false /*fFatal*/, "TlsAlloc failed"); 1881 1882 /* 1872 1883 * Resolve it. 1873 1884 */ … … 2343 2354 /* 2344 2355 * Call the windows verify trust API if we've resolved it and aren't in 2345 * some obvious recursion. Assume we won't be having too much 2346 * concurrency, so a single global variable should suffice, right... 2356 * some obvious recursion. 2347 2357 */ 2348 2358 if (g_pfnWinVerifyTrust != NULL) 2349 2359 { 2350 uint32_t const idCurrentThread = GetCurrentThreadId(); 2351 if (g_idActiveThread != idCurrentThread) 2360 /* Check for recursion. */ 2361 bool fNoRecursion; 2362 if (g_iTlsWinVerifyTrustRecursion != UINT32_MAX) 2352 2363 { 2353 ASMAtomicCmpXchgU32(&g_idActiveThread, idCurrentThread, UINT32_MAX); 2354 2364 fNoRecursion = TlsGetValue(g_iTlsWinVerifyTrustRecursion) == 0; 2365 if (fNoRecursion) 2366 TlsSetValue(g_iTlsWinVerifyTrustRecursion, (void *)1); 2367 } 2368 else 2369 { 2370 uint32_t const idCurrentThread = GetCurrentThreadId(); 2371 fNoRecursion = ASMAtomicCmpXchgU32(&g_idActiveThread, idCurrentThread, UINT32_MAX); 2372 } 2373 if (fNoRecursion) 2374 { 2375 /* We can call WinVerifyTrust. */ 2355 2376 if (pfWinVerifyTrust) 2356 2377 *pfWinVerifyTrust = true; … … 2385 2406 } 2386 2407 2387 ASMAtomicCmpXchgU32(&g_idActiveThread, UINT32_MAX, idCurrentThread); 2408 /* Unwind recursion. */ 2409 if (g_iTlsWinVerifyTrustRecursion != UINT32_MAX) 2410 TlsSetValue(g_iTlsWinVerifyTrustRecursion, (void *)0); 2411 else 2412 ASMAtomicWriteU32(&g_idActiveThread, UINT32_MAX); 2388 2413 } 2389 2414 else … … 2405 2430 { 2406 2431 return g_pfnWinVerifyTrust != NULL 2407 && g_idActiveThread != GetCurrentThreadId(); 2432 && ( g_iTlsWinVerifyTrustRecursion != UINT32_MAX 2433 ? (uintptr_t)TlsGetValue(g_iTlsWinVerifyTrustRecursion) == 0 2434 : g_idActiveThread != GetCurrentThreadId() ); 2408 2435 } 2409 2436 -
trunk/src/VBox/HostDrivers/Support/win/import-template-kernel32.h
r52403 r52414 21 21 SUPHARNT_IMPORT_STDCALL(SetLastError, 4) 22 22 SUPHARNT_IMPORT_STDCALL(Sleep, 4) 23 SUPHARNT_IMPORT_STDCALL(TlsAlloc, 0) 24 SUPHARNT_IMPORT_STDCALL(TlsGetValue, 4) 25 SUPHARNT_IMPORT_STDCALL(TlsSetValue, 8) 23 26 SUPHARNT_IMPORT_STDCALL(VirtualProtectEx, 20) 24 27 SUPHARNT_IMPORT_STDCALL(WriteFile, 20)
Note:
See TracChangeset
for help on using the changeset viewer.