- Timestamp:
- Jul 9, 2014 12:59:53 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/nt/nt.h
r51770 r51945 298 298 #ifndef ZwCurrentThread 299 299 # define ZwCurrentThread() NtCurrentThread() 300 #endif 301 /** @} */ 302 303 304 /** @name Directory object access rights. 305 * @{ */ 306 #ifndef DIRECTORY_QUERY 307 # define DIRECTORY_QUERY UINT32_C(0x00000001) 308 #endif 309 #ifndef DIRECTORY_TRAVERSE 310 # define DIRECTORY_TRAVERSE UINT32_C(0x00000002) 311 #endif 312 #ifndef DIRECTORY_CREATE_OBJECT 313 # define DIRECTORY_CREATE_OBJECT UINT32_C(0x00000004) 314 #endif 315 #ifndef DIRECTORY_CREATE_SUBDIRECTORY 316 # define DIRECTORY_CREATE_SUBDIRECTORY UINT32_C(0x00000008) 317 #endif 318 #ifndef DIRECTORY_ALL_ACCESS 319 # define DIRECTORY_ALL_ACCESS ( STANDARD_RIGHTS_REQUIRED | UINT32_C(0x0000000f) ) 300 320 #endif 301 321 /** @} */ -
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r51936 r51945 1386 1386 1387 1387 1388 static bool supR3HardenedWinDriverExists(const char *pszDriver) 1389 { 1390 /* 1391 * Open the driver object directory. 1392 */ 1393 UNICODE_STRING NtDirName; 1394 NtDirName.Buffer = L"\\Driver"; 1395 NtDirName.MaximumLength = sizeof(L"\\Driver"); 1396 NtDirName.Length = NtDirName.MaximumLength - sizeof(WCHAR); 1397 1398 OBJECT_ATTRIBUTES ObjAttr; 1399 InitializeObjectAttributes(&ObjAttr, &NtDirName, OBJ_CASE_INSENSITIVE, NULL /*hRootDir*/, NULL /*pSecDesc*/); 1400 1401 HANDLE hDir; 1402 NTSTATUS rcNt = NtOpenDirectoryObject(&hDir, DIRECTORY_QUERY | FILE_LIST_DIRECTORY, &ObjAttr); 1403 #ifdef VBOX_STRICT 1404 SUPR3HARDENED_ASSERT_NT_SUCCESS(rcNt); 1405 #endif 1406 if (!NT_SUCCESS(rcNt)) 1407 return true; 1408 1409 /* 1410 * Enumerate it, looking for the driver. 1411 */ 1412 bool fFound = true; 1413 ULONG uObjDirCtx = 0; 1414 do 1415 { 1416 uint32_t abBuffer[_64K + _1K]; 1417 ULONG cbActual; 1418 rcNt = NtQueryDirectoryObject(hDir, 1419 abBuffer, 1420 sizeof(abBuffer) - 4, /* minus four for string terminator space. */ 1421 FALSE /*ReturnSingleEntry */, 1422 FALSE /*RestartScan*/, 1423 &uObjDirCtx, 1424 &cbActual); 1425 if (!NT_SUCCESS(rcNt) || cbActual < sizeof(OBJECT_DIRECTORY_INFORMATION)) 1426 break; 1427 1428 POBJECT_DIRECTORY_INFORMATION pObjDir = (POBJECT_DIRECTORY_INFORMATION)abBuffer; 1429 while (pObjDir->Name.Length != 0) 1430 { 1431 WCHAR wcSaved = pObjDir->Name.Buffer[pObjDir->Name.Length / sizeof(WCHAR)]; 1432 pObjDir->Name.Buffer[pObjDir->Name.Length / sizeof(WCHAR)] = '\0'; 1433 if ( pObjDir->Name.Length > 1 1434 && RTUtf16ICmpAscii(pObjDir->Name.Buffer, pszDriver) == 0) 1435 { 1436 fFound = true; 1437 break; 1438 } 1439 pObjDir->Name.Buffer[pObjDir->Name.Length / sizeof(WCHAR)] = wcSaved; 1440 1441 /* Next directory entry. */ 1442 pObjDir++; 1443 } 1444 } while (!fFound); 1445 1446 /* 1447 * Clean up and return. 1448 */ 1449 NtClose(hDir); 1450 1451 return fFound; 1452 } 1453 1454 1388 1455 /** 1389 1456 * Called by the main code if supR3HardenedWinIsReSpawnNeeded returns @c true. … … 1394 1461 { 1395 1462 /* 1396 * Open the stub device. 1397 */ 1398 HANDLE hFile = RTNT_INVALID_HANDLE_VALUE; 1399 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER; 1400 1463 * Open the stub device. Retry if we think driver might still be 1464 * initializing (STATUS_NO_SUCH_DEVICE + \Drivers\VBoxDrv). 1465 */ 1401 1466 static const WCHAR s_wszName[] = L"\\Device\\VBoxDrvStub"; 1402 UNICODE_STRING NtName; 1403 NtName.Buffer = (PWSTR)s_wszName; 1404 NtName.Length = sizeof(s_wszName) - sizeof(WCHAR); 1405 NtName.MaximumLength = sizeof(s_wszName); 1406 1407 OBJECT_ATTRIBUTES ObjAttr; 1408 InitializeObjectAttributes(&ObjAttr, &NtName, OBJ_CASE_INSENSITIVE, NULL /*hRootDir*/, NULL /*pSecDesc*/); 1409 1410 NTSTATUS rcNt = NtCreateFile(&hFile, 1411 GENERIC_READ | GENERIC_WRITE, 1412 &ObjAttr, 1413 &Ios, 1414 NULL /* Allocation Size*/, 1415 FILE_ATTRIBUTE_NORMAL, 1416 FILE_SHARE_READ | FILE_SHARE_WRITE, 1417 FILE_OPEN, 1418 FILE_NON_DIRECTORY_FILE, 1419 NULL /*EaBuffer*/, 1420 0 /*EaLength*/); 1421 if (NT_SUCCESS(rcNt)) 1422 rcNt = Ios.Status; 1467 DWORD const uStartTick = GetTickCount(); 1468 NTSTATUS rcNt; 1469 uint32_t iTry; 1470 1471 for (iTry = 0;; iTry++) 1472 { 1473 HANDLE hFile = RTNT_INVALID_HANDLE_VALUE; 1474 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER; 1475 1476 UNICODE_STRING NtName; 1477 NtName.Buffer = (PWSTR)s_wszName; 1478 NtName.Length = sizeof(s_wszName) - sizeof(WCHAR); 1479 NtName.MaximumLength = sizeof(s_wszName); 1480 1481 OBJECT_ATTRIBUTES ObjAttr; 1482 InitializeObjectAttributes(&ObjAttr, &NtName, OBJ_CASE_INSENSITIVE, NULL /*hRootDir*/, NULL /*pSecDesc*/); 1483 1484 rcNt = NtCreateFile(&hFile, 1485 GENERIC_READ | GENERIC_WRITE, 1486 &ObjAttr, 1487 &Ios, 1488 NULL /* Allocation Size*/, 1489 FILE_ATTRIBUTE_NORMAL, 1490 FILE_SHARE_READ | FILE_SHARE_WRITE, 1491 FILE_OPEN, 1492 FILE_NON_DIRECTORY_FILE, 1493 NULL /*EaBuffer*/, 1494 0 /*EaLength*/); 1495 if (NT_SUCCESS(rcNt)) 1496 rcNt = Ios.Status; 1497 1498 /* The STATUS_NO_SUCH_DEVICE might be returned if the device is not 1499 completely initialized. Delay a little bit and try again. */ 1500 if (rcNt != STATUS_NO_SUCH_DEVICE) 1501 break; 1502 if (iTry > 0 && GetTickCount() - uStartTick > 5000) /* 5 sec, at least two tries */ 1503 break; 1504 if (!supR3HardenedWinDriverExists("VBoxDrv")) 1505 { 1506 /** @todo Consider starting the VBoxdrv.sys service. Requires 2nd process 1507 * though, rather complicated actually as CreateProcess causes all 1508 * kind of things to happen to this process which would make it hard to 1509 * pass the process verification tests... :-/ */ 1510 break; 1511 } 1512 1513 LARGE_INTEGER Time; 1514 if (iTry < 8) 1515 Time.QuadPart = -1000000 / 100; /* 1ms in 100ns units, relative time. */ 1516 else 1517 Time.QuadPart = -32000000 / 100; /* 32ms in 100ns units, relative time. */ 1518 NtDelayExecution(TRUE, &Time); 1519 } 1520 1423 1521 if (!NT_SUCCESS(rcNt)) 1424 1522 { … … 1438 1536 } 1439 1537 supR3HardenedFatalMsg("supR3HardenedWinReSpawn", kSupInitOp_Driver, VERR_OPEN_FAILED, 1440 "NtCreateFile(%ls) failed: %#x%s \n", s_wszName, rcNt, pszDefine);1538 "NtCreateFile(%ls) failed: %#x%s (%u retries)\n", s_wszName, rcNt, pszDefine, iTry); 1441 1539 } 1442 1540 supR3HardenedFatalMsg("supR3HardenedWinReSpawn", kSupInitOp_Driver, rc,
Note:
See TracChangeset
for help on using the changeset viewer.