Changeset 52949 in vbox
- Timestamp:
- Oct 5, 2014 9:43:10 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/nt/nt.h
r52947 r52949 390 390 typedef CLIENT_ID *PCLIENT_ID; 391 391 #endif 392 393 /** @name User Shared Data 394 * @{ */ 395 396 #ifdef IPRT_NT_USE_WINTERNL 397 typedef struct _KSYSTEM_TIME 398 { 399 ULONG LowPart; 400 LONG High1Time; 401 LONG High2Time; 402 } KSYSTEM_TIME; 403 typedef KSYSTEM_TIME *PKSYSTEM_TIME; 404 405 typedef enum _NT_PRODUCT_TYPE 406 { 407 NtProductWinNt = 1, 408 NtProductLanManNt, 409 NtProductServer 410 } NT_PRODUCT_TYPE; 411 412 #define PROCESSOR_FEATURE_MAX 64 413 414 typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE 415 { 416 StandardDesign = 0, 417 NEC98x86, 418 EndAlternatives 419 } ALTERNATIVE_ARCHITECTURE_TYPE; 420 421 # if 0 422 typedef struct _XSTATE_FEATURE 423 { 424 ULONG Offset; 425 ULONG Size; 426 } XSTATE_FEATURE; 427 typedef XSTATE_FEATURE *PXSTATE_FEATURE; 428 429 #define MAXIMUM_XSTATE_FEATURES 64 430 431 typedef struct _XSTATE_CONFIGURATION 432 { 433 ULONG64 EnabledFeatures; 434 ULONG Size; 435 ULONG OptimizedSave : 1; 436 XSTATE_FEATURE Features[MAXIMUM_XSTATE_FEATURES]; 437 } XSTATE_CONFIGURATION; 438 typedef XSTATE_CONFIGURATION *PXSTATE_CONFIGURATION; 439 # endif 440 441 typedef struct _KUSER_SHARED_DATA 442 { 443 ULONG TickCountLowDeprecated; 444 ULONG TickCountMultiplier; 445 KSYSTEM_TIME volatile InterruptTime; 446 KSYSTEM_TIME volatile SystemTime; 447 KSYSTEM_TIME volatile TimeZoneBias; 448 USHORT ImageNumberLow; 449 USHORT ImageNumberHigh; 450 WCHAR NtSystemRoot[260]; 451 ULONG MaxStackTraceDepth; 452 ULONG CryptoExponent; 453 ULONG TimeZoneId; 454 ULONG LargePageMinimum; 455 ULONG AitSamplingValue; 456 ULONG AppCompatFlag; 457 ULONGLONG RNGSeedVersion; 458 ULONG GlobalValidationRunlevel; 459 LONG volatile TimeZoneBiasStamp; 460 ULONG Reserved2; 461 NT_PRODUCT_TYPE NtProductType; 462 BOOLEAN ProductTypeIsValid; 463 BOOLEAN Reserved0[1]; 464 USHORT NativeProcessorArchitecture; 465 ULONG NtMajorVersion; 466 ULONG NtMinorVersion; 467 BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX]; 468 ULONG Reserved1; 469 ULONG Reserved3; 470 ULONG volatile TimeSlip; 471 ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture; 472 ULONG AltArchitecturePad[1]; 473 LARGE_INTEGER SystemExpirationDate; 474 ULONG SuiteMask; 475 BOOLEAN KdDebuggerEnabled; 476 union 477 { 478 UCHAR MitigationPolicies; 479 struct 480 { 481 UCHAR NXSupportPolicy : 2; 482 UCHAR SEHValidationPolicy : 2; 483 UCHAR CurDirDevicesSkippedForDlls : 2; 484 UCHAR Reserved : 2; 485 }; 486 }; 487 UCHAR Reserved6[2]; 488 ULONG volatile ActiveConsoleId; 489 ULONG volatile DismountCount; 490 ULONG ComPlusPackage; 491 ULONG LastSystemRITEventTickCount; 492 ULONG NumberOfPhysicalPages; 493 BOOLEAN SafeBootMode; 494 UCHAR Reserved12[3]; 495 union 496 { 497 ULONG SharedDataFlags; 498 struct 499 { 500 ULONG DbgErrorPortPresent : 1; 501 ULONG DbgElevationEnabled : 1; 502 ULONG DbgVirtEnabled : 1; 503 ULONG DbgInstallerDetectEnabled : 1; 504 ULONG DbgLkgEnabled : 1; 505 ULONG DbgDynProcessorEnabled : 1; 506 ULONG DbgConsoleBrokerEnabled : 1; 507 ULONG DbgSecureBootEnabled : 1; 508 ULONG SpareBits : 24; 509 }; 510 }; 511 ULONG DataFlagsPad[1]; 512 ULONGLONG TestRetInstruction; 513 LONGLONG QpcFrequency; 514 ULONGLONG SystemCallPad[3]; 515 union 516 { 517 ULONG64 volatile TickCountQuad; 518 KSYSTEM_TIME volatile TickCount; 519 struct 520 { 521 ULONG ReservedTickCountOverlay[3]; 522 ULONG TickCountPad[1]; 523 }; 524 }; 525 ULONG Cookie; 526 ULONG CookiePad[1]; 527 LONGLONG ConsoleSessionForegroundProcessId; 528 ULONGLONG TimeUpdateLock; 529 ULONGLONG BaselineSystemTimeQpc; 530 ULONGLONG BaselineInterruptTimeQpc; 531 ULONGLONG QpcSystemTimeIncrement; 532 ULONGLONG QpcInterruptTimeIncrement; 533 ULONG QpcSystemTimeIncrement32; 534 ULONG QpcInterruptTimeIncrement32; 535 UCHAR QpcSystemTimeIncrementShift; 536 UCHAR QpcInterruptTimeIncrementShift; 537 UCHAR Reserved8[14]; 538 USHORT UserModeGlobalLogger[16]; 539 ULONG ImageFileExecutionOptions; 540 ULONG LangGenerationCount; 541 ULONGLONG Reserved4; 542 ULONGLONG volatile InterruptTimeBias; 543 ULONGLONG volatile QpcBias; 544 ULONG volatile ActiveProcessorCount; 545 UCHAR volatile ActiveGroupCount; 546 UCHAR Reserved9; 547 union 548 { 549 USHORT QpcData; 550 struct 551 { 552 BOOLEAN volatile QpcBypassEnabled; 553 UCHAR QpcShift; 554 }; 555 }; 556 LARGE_INTEGER TimeZoneBiasEffectiveStart; 557 LARGE_INTEGER TimeZoneBiasEffectiveEnd; 558 XSTATE_CONFIGURATION XState; 559 } KUSER_SHARED_DATA; 560 typedef KUSER_SHARED_DATA *PKUSER_SHARED_DATA; 561 #endif /* IPRT_NT_USE_WINTERNL */ 562 /** @} */ 563 392 564 393 565 /** @name Process And Thread Environment Blocks -
trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h
r52943 r52949 313 313 { 314 314 SUPR3HARDENEDMAINSTATE_NOT_YET_CALLED = 0, 315 SUPR3HARDENEDMAINSTATE_WIN_ VM_INIT_CALLED,315 SUPR3HARDENEDMAINSTATE_WIN_EARLY_INIT_CALLED, 316 316 SUPR3HARDENEDMAINSTATE_WIN_EARLY_IMPORTS_RESOLVED, 317 317 SUPR3HARDENEDMAINSTATE_WIN_EARLY_DEVICE_OPENED, … … 342 342 extern DECLHIDDEN(SUPR3HARDENEDMAINSTATE) g_enmSupR3HardenedMainState; 343 343 #ifdef RT_OS_WINDOWS 344 extern DECLHIDDEN(bool) g_fSupEarly VmProcessInit;344 extern DECLHIDDEN(bool) g_fSupEarlyProcessInit; 345 345 #endif 346 346 -
trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
r52947 r52949 1713 1713 g_SupPreInitData.u32EndMagic = SUPPREINITDATA_MAGIC; 1714 1714 #ifdef RT_OS_WINDOWS 1715 if (!g_fSupEarly VmProcessInit)1715 if (!g_fSupEarlyProcessInit) 1716 1716 #endif 1717 1717 g_SupPreInitData.Data.hDevice = SUP_HDEVICE_NIL; … … 1748 1748 * at dropping compatibility layers and process "security" solutions. 1749 1749 */ 1750 if ( !g_fSupEarly VmProcessInit1750 if ( !g_fSupEarlyProcessInit 1751 1751 && !(fFlags & SUPSECMAIN_FLAGS_DONT_OPEN_DEV) 1752 1752 && supR3HardenedWinIsReSpawnNeeded(1 /*iWhich*/, argc, argv)) 1753 1753 { 1754 1754 SUP_DPRINTF(("SUPR3HardenedMain: Respawn #1\n")); 1755 supR3HardenedWinInit(SUPSECMAIN_FLAGS_DONT_OPEN_DEV, true /*fAvastKludge*/);1755 supR3HardenedWinInit(SUPSECMAIN_FLAGS_DONT_OPEN_DEV, false /*fAvastKludge*/); 1756 1756 supR3HardenedVerifyAll(true /* fFatal */, pszProgName); 1757 1757 return supR3HardenedWinReSpawn(1 /*iWhich*/); … … 1764 1764 * by early VM process init.) 1765 1765 */ 1766 if (!g_fSupEarly VmProcessInit)1766 if (!g_fSupEarlyProcessInit) 1767 1767 supR3HardenedWinInit(fFlags, true /*fAvastKludge*/); 1768 1768 #endif /* RT_OS_WINDOWS */ … … 1777 1777 * driver. (Already done by early VM process init.) 1778 1778 */ 1779 if (!(fFlags & SUPSECMAIN_FLAGS_DONT_OPEN_DEV)) 1780 { 1779 1781 #ifdef RT_OS_WINDOWS 1780 if (!g_fSupEarlyVmProcessInit) 1781 #endif 1782 if (!(fFlags & SUPSECMAIN_FLAGS_DONT_OPEN_DEV)) 1782 /* 1783 * Windows: Verify the process (repeated by the kernel later). 1784 */ 1785 if (!g_fSupEarlyProcessInit) 1786 supR3HardenedWinVerifyProcess(); 1787 1788 /* 1789 * Windows: The second respawn. This time we make a special arrangement 1790 * with vboxdrv to monitor access to the new process from its inception. 1791 */ 1792 if (supR3HardenedWinIsReSpawnNeeded(2 /* iWhich*/, argc, argv)) 1783 1793 { 1794 SUP_DPRINTF(("SUPR3HardenedMain: Respawn #2\n")); 1795 return supR3HardenedWinReSpawn(2 /* iWhich*/); 1796 } 1797 SUP_DPRINTF(("SUPR3HardenedMain: Final process, opening VBoxDrv...\n")); 1798 supR3HardenedWinFlushLoaderCache(); 1799 #endif /* RT_OS_WINDOWS */ 1800 1801 /* 1802 * Open the vboxdrv device. 1803 */ 1784 1804 #ifdef RT_OS_WINDOWS 1785 /* 1786 * Windows: Verify the process (repeated by the kernel later. 1787 */ 1788 supR3HardenedWinVerifyProcess(); 1789 1790 /* 1791 * Windows: The second respawn. This time we make a special arrangement 1792 * with vboxdrv to monitor access to the new process from its inception. 1793 */ 1794 if (supR3HardenedWinIsReSpawnNeeded(2 /* iWhich*/, argc, argv)) 1795 { 1796 SUP_DPRINTF(("SUPR3HardenedMain: Respawn #2\n")); 1797 return supR3HardenedWinReSpawn(2 /* iWhich*/); 1798 } 1799 SUP_DPRINTF(("SUPR3HardenedMain: Final process, opening VBoxDrv...\n")); 1800 supR3HardenedWinFlushLoaderCache(); 1801 #endif /* RT_OS_WINDOWS */ 1802 1803 /* 1804 * Open the vboxdrv device. 1805 */ 1805 if (!g_fSupEarlyProcessInit) 1806 #endif 1806 1807 supR3HardenedMainOpenDevice(); 1807 1808 } 1808 1809 1809 1810 #ifdef RT_OS_WINDOWS -
trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp
r52908 r52949 3578 3578 if (pHandleInfo->Object == pProtectedProcess) 3579 3579 { 3580 /* Handles within the protected process isfine. */3580 /* Handles within the protected process are fine. */ 3581 3581 if ( !(pHandleInfo->GrantedAccess & SUPDRV_NT_EVIL_PROCESS_RIGHTS) 3582 3582 || pHandleInfo->UniqueProcessId == hProtectedPid) -
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r52947 r52949 200 200 * supR3HardenedVmProcessInit. */ 201 201 static SUPR3WINPROCPARAMS g_ProcParams = { NULL, NULL, 0, 0 }; 202 /** Set if supR3HardenedVmProcessInit was invoked. */ 203 bool g_fSupEarlyVmProcessInit = false; 202 /** Set if supR3HardenedEarlyProcessInit was invoked. */ 203 bool g_fSupEarlyProcessInit = false; 204 /** Set if the stub device has been opened (stub process only). */ 205 bool g_fSupStubOpened = false; 204 206 205 207 /** @name Global variables initialized by suplibHardenedWindowsMain. … … 311 313 #endif 312 314 313 DECLASM(void) supR3Hardened VmProcessInitThunk(void);315 DECLASM(void) supR3HardenedEarlyProcessInitThunk(void); 314 316 315 317 … … 351 353 return pwszCur - pwsz; 352 354 } 355 356 357 /** 358 * Our version of GetTickCount. 359 * @returns Millisecond timestamp. 360 */ 361 static uint64_t supR3HardenedWinGetMilliTS(void) 362 { 363 PKUSER_SHARED_DATA pUserSharedData = (PKUSER_SHARED_DATA)(uintptr_t)0x7ffe0000; 364 365 /* use interrupt time */ 366 LARGE_INTEGER Time; 367 do 368 { 369 Time.HighPart = pUserSharedData->InterruptTime.High1Time; 370 Time.LowPart = pUserSharedData->InterruptTime.LowPart; 371 } while (pUserSharedData->InterruptTime.High2Time != Time.HighPart); 372 373 return (uint64_t)Time.QuadPart / 10000; 374 } 375 353 376 354 377 … … 3510 3533 * process asynchronously. 3511 3534 */ 3512 DWORD dwStart = GetTickCount();3535 uint64_t uMsTsStart = supR3HardenedWinGetMilliTS(); 3513 3536 uint32_t cMsKludge = (g_fSupAdversaries & SUPHARDNT_ADVERSARY_SYMANTEC_SYSPLANT) ? 256 : g_fSupAdversaries ? 64 : 16; 3514 3537 do … … 3518 3541 Time.QuadPart = -8000000 / 100; /* 8ms in 100ns units, relative time. */ 3519 3542 NtDelayExecution(FALSE, &Time); 3520 } while (GetTickCount() - dwStart < cMsKludge); 3521 SUP_DPRINTF(("supR3HardNtPuChTriggerInitialImageEvents: Startup delay kludge #1: %u ms\n", GetTickCount() - dwStart)); 3543 } while (supR3HardenedWinGetMilliTS() - uMsTsStart < cMsKludge); 3544 SUP_DPRINTF(("supR3HardNtPuChTriggerInitialImageEvents: Startup delay kludge #1: %u ms\n", 3545 supR3HardenedWinGetMilliTS() - uMsTsStart)); 3522 3546 3523 3547 /* … … 3778 3802 { 3779 3803 NTSTATUS rcNtWait; 3780 DWORD dwStartTick = GetTickCount();3804 uint64_t uMsTsStart = supR3HardenedWinGetMilliTS(); 3781 3805 do 3782 3806 { … … 3793 3817 || rcNtWait == STATUS_USER_APC 3794 3818 || rcNtWait == STATUS_ALERTED) 3795 && GetTickCount() - dwStartTick< 60 * 1000);3819 && supR3HardenedWinGetMilliTS() - uMsTsStart < 60 * 1000); 3796 3820 if (fExitOk) 3797 3821 supR3HardenedError(rc, false /*fFatal*/, … … 3822 3846 * close the event semaphore and set it to NULL. 3823 3847 */ 3824 static void supR3HardenedWinCheck VmChild(HANDLE hProcWait, uintptr_t uChildExeAddr, HANDLE *phEvtParent, HANDLE *phEvtChild)3848 static void supR3HardenedWinCheckChild(HANDLE hProcWait, uintptr_t uChildExeAddr, HANDLE *phEvtParent, HANDLE *phEvtChild) 3825 3849 { 3826 3850 /* … … 3828 3852 */ 3829 3853 uintptr_t uChildAddr = uChildExeAddr + ((uintptr_t)&g_ProcParams - (uintptr_t)NtCurrentPeb()->ImageBaseAddress); 3830 SIZE_T cbIgnored ;3854 SIZE_T cbIgnored = 0; 3831 3855 SUPR3WINPROCPARAMS ChildProcParams; 3832 3856 RT_ZERO(ChildProcParams); 3833 3857 NTSTATUS rcNt = NtReadVirtualMemory(hProcWait, (PVOID)uChildAddr, &ChildProcParams, sizeof(ChildProcParams), &cbIgnored); 3834 3858 if (!NT_SUCCESS(rcNt)) 3835 supR3HardenedWinKillChild(hProcWait, "supR3HardenedWinCheck VmChild", rcNt,3859 supR3HardenedWinKillChild(hProcWait, "supR3HardenedWinCheckChild", rcNt, 3836 3860 "NtReadVirtualMemory(,%p,) failed reading child process status: %#x\n", uChildAddr, rcNt); 3837 3861 … … 3841 3865 rcNt = NtSetEvent(*phEvtChild, NULL); 3842 3866 if (!NT_SUCCESS(rcNt)) 3843 supR3HardenedWinKillChild(hProcWait, "supR3HardenedWinCheck VmChild", rcNt, "NtSetEvent failed: %#x\n", rcNt);3867 supR3HardenedWinKillChild(hProcWait, "supR3HardenedWinCheckChild", rcNt, "NtSetEvent failed: %#x\n", rcNt); 3844 3868 3845 3869 /* … … 3850 3874 rcNt = NtClose(*phEvtChild); 3851 3875 if (!NT_SUCCESS(rcNt)) 3852 supR3HardenedWinKillChild(hProcWait, "supR3HardenedWinCheck VmChild", rcNt, "NtClose failed on event sem: %#x\n", rcNt);3876 supR3HardenedWinKillChild(hProcWait, "supR3HardenedWinCheckChild", rcNt, "NtClose failed on event sem: %#x\n", rcNt); 3853 3877 *phEvtChild = NULL; 3854 3878 *phEvtParent = NULL; … … 3862 3886 /* An error occurred, report it. */ 3863 3887 ChildProcParams.szErrorMsg[sizeof(ChildProcParams.szErrorMsg) - 1] = '\0'; 3864 supR3HardenedFatalMsg("supR3HardenedWinCheck VmChild", kSupInitOp_Misc, ChildProcParams.rc, "%s", ChildProcParams.szErrorMsg);3865 } 3866 3867 3868 static void supR3HardenedWin InitVmChild(HANDLE hProcess, HANDLE hThread, uintptr_t uChildNtDllAddr, uintptr_t uChildExeAddr,3869 HANDLE hEvtChild, HANDLE hEvtParent)3888 supR3HardenedFatalMsg("supR3HardenedWinCheckChild", kSupInitOp_Misc, ChildProcParams.rc, "%s", ChildProcParams.szErrorMsg); 3889 } 3890 3891 3892 static void supR3HardenedWinSetupChildInit(HANDLE hProcess, HANDLE hThread, uintptr_t uChildNtDllAddr, uintptr_t uChildExeAddr, 3893 HANDLE hEvtChild, HANDLE hEvtParent) 3870 3894 { 3871 3895 /* … … 3884 3908 NTSTATUS rcNt = NtWriteVirtualMemory(hProcess, (PVOID)uChildAddr, &ChildProcParams, sizeof(ChildProcParams), &cbIgnored); 3885 3909 if (!NT_SUCCESS(rcNt)) 3886 supR3HardenedWinKillChild(hProcess, "supR3HardenedWin InitVmChild", rcNt,3910 supR3HardenedWinKillChild(hProcess, "supR3HardenedWinSetupChildInit", rcNt, 3887 3911 "NtWriteVirtualMemory(,%p,) failed writing child process parameters: %#x\n", uChildAddr, rcNt); 3888 3912 … … 3894 3918 int rc = supHardNtLdrCacheOpen("ntdll.dll", &pLdrEntry); 3895 3919 if (RT_FAILURE(rc)) 3896 supR3HardenedWinKillChild(hProcess, "supR3HardenedWin InitVmChild", rc,3920 supR3HardenedWinKillChild(hProcess, "supR3HardenedWinSetupChildInit", rc, 3897 3921 "supHardNtLdrCacheOpen failed on NTDLL: %Rrc\n", rc); 3898 3922 … … 3900 3924 rc = supHardNtLdrCacheEntryGetBits(pLdrEntry, &pbChildNtDllBits, uChildNtDllAddr, NULL, NULL, NULL /*pErrInfo*/); 3901 3925 if (RT_FAILURE(rc)) 3902 supR3HardenedWinKillChild(hProcess, "supR3HardenedWin InitVmChild", rc,3926 supR3HardenedWinKillChild(hProcess, "supR3HardenedWinSetupChildInit", rc, 3903 3927 "supHardNtLdrCacheEntryGetBits failed on NTDLL: %Rrc\n", rc); 3904 3928 … … 3907 3931 "LdrInitializeThunk", &uLdrInitThunk); 3908 3932 if (RT_FAILURE(rc)) 3909 supR3HardenedWinKillChild(hProcess, "supR3HardenedWin InitVmChild", rc,3933 supR3HardenedWinKillChild(hProcess, "supR3HardenedWinSetupChildInit", rc, 3910 3934 "Error locating LdrInitializeThunk in NTDLL: %Rrc", rc); 3911 3935 PVOID pvLdrInitThunk = (PVOID)(uintptr_t)uLdrInitThunk; 3912 SUP_DPRINTF(("supR3HardenedWin InitVmChild: uLdrInitThunk=%p\n", (uintptr_t)uLdrInitThunk));3936 SUP_DPRINTF(("supR3HardenedWinSetupChildInit: uLdrInitThunk=%p\n", (uintptr_t)uLdrInitThunk)); 3913 3937 3914 3938 /* 3915 3939 * Calculate the address of our code in the child process. 3916 3940 */ 3917 uintptr_t uEarly VmProcInitEP = uChildExeAddr + ( (uintptr_t)&supR3HardenedVmProcessInitThunk3918 3941 uintptr_t uEarlyProcInitEP = uChildExeAddr + ( (uintptr_t)&supR3HardenedEarlyProcessInitThunk 3942 - (uintptr_t)NtCurrentPeb()->ImageBaseAddress); 3919 3943 3920 3944 /* 3921 3945 * Compose the LdrInitializeThunk replacement bytes. 3946 * Note! The amount of code we replace here must be less or equal to what 3947 * the process verification code ignores. 3922 3948 */ 3923 3949 uint8_t abNew[16]; … … 3927 3953 abNew[1] = 0x25; 3928 3954 *(uint32_t *)&abNew[2] = 0; 3929 *(uint64_t *)&abNew[6] = uEarly VmProcInitEP;3955 *(uint64_t *)&abNew[6] = uEarlyProcInitEP; 3930 3956 #elif defined(RT_ARCH_X86) 3931 3957 abNew[0] = 0xe9; 3932 *(uint32_t *)&abNew[1] = uEarly VmProcInitEP - ((uint32_t)uLdrInitThunk + 5);3958 *(uint32_t *)&abNew[1] = uEarlyProcInitEP - ((uint32_t)uLdrInitThunk + 5); 3933 3959 #else 3934 3960 # error "Unsupported arch." … … 3943 3969 rcNt = NtProtectVirtualMemory(hProcess, &pvProt, &cbProt, PAGE_EXECUTE_READWRITE, &fOldProt); 3944 3970 if (!NT_SUCCESS(rcNt)) 3945 supR3HardenedWinKillChild(hProcess, "supR3HardenedWin InitVmChild", rcNt,3971 supR3HardenedWinKillChild(hProcess, "supR3HardenedWinSetupChildInit", rcNt, 3946 3972 "NtProtectVirtualMemory/LdrInitializeThunk failed: %#x", rcNt); 3947 3973 3948 3974 rcNt = NtWriteVirtualMemory(hProcess, pvLdrInitThunk, abNew, sizeof(abNew), &cbIgnored); 3949 3975 if (!NT_SUCCESS(rcNt)) 3950 supR3HardenedWinKillChild(hProcess, "supR3HardenedWin InitVmChild", rcNt,3976 supR3HardenedWinKillChild(hProcess, "supR3HardenedWinSetupChildInit", rcNt, 3951 3977 "NtWriteVirtualMemory/LdrInitializeThunk failed: %#x", rcNt); 3952 3978 … … 3955 3981 rcNt = NtProtectVirtualMemory(hProcess, &pvProt, &cbProt, fOldProt, &fOldProt); 3956 3982 if (!NT_SUCCESS(rcNt)) 3957 supR3HardenedWinKillChild(hProcess, "supR3HardenedWin InitVmChild", rcNt,3983 supR3HardenedWinKillChild(hProcess, "supR3HardenedWinSetupChildInit", rcNt, 3958 3984 "NtProtectVirtualMemory/LdrInitializeThunk[restore] failed: %#x", rcNt); 3959 3985 3960 3986 /* Caller starts child execution. */ 3961 SUP_DPRINTF(("supR3HardenedWin InitVmChild: Start child.\n"));3987 SUP_DPRINTF(("supR3HardenedWinSetupChildInit: Start child.\n")); 3962 3988 } 3963 3989 … … 3983 4009 * Set up VM child communication event semaphores. 3984 4010 */ 4011 OBJECT_ATTRIBUTES ObjAttrs; 3985 4012 HANDLE hEvtChild = NULL; 4013 InitializeObjectAttributes(&ObjAttrs, NULL /*pName*/, OBJ_INHERIT, NULL /*hRootDir*/, NULL /*pSecDesc*/); 4014 SUPR3HARDENED_ASSERT_NT_SUCCESS(NtCreateEvent(&hEvtChild, EVENT_ALL_ACCESS, &ObjAttrs, NotificationEvent, FALSE)); 4015 3986 4016 HANDLE hEvtParent = NULL; 3987 if (iWhich >= 2) 3988 { 3989 OBJECT_ATTRIBUTES ObjAttrs; 3990 InitializeObjectAttributes(&ObjAttrs, NULL /*pName*/, OBJ_INHERIT, NULL /*hRootDir*/, NULL /*pSecDesc*/); 3991 SUPR3HARDENED_ASSERT_NT_SUCCESS(NtCreateEvent(&hEvtChild, EVENT_ALL_ACCESS, &ObjAttrs, NotificationEvent, FALSE)); 3992 InitializeObjectAttributes(&ObjAttrs, NULL /*pName*/, OBJ_INHERIT, NULL /*hRootDir*/, NULL /*pSecDesc*/); 3993 SUPR3HARDENED_ASSERT_NT_SUCCESS(NtCreateEvent(&hEvtParent, EVENT_ALL_ACCESS, &ObjAttrs, NotificationEvent, FALSE)); 3994 } 4017 InitializeObjectAttributes(&ObjAttrs, NULL /*pName*/, OBJ_INHERIT, NULL /*hRootDir*/, NULL /*pSecDesc*/); 4018 SUPR3HARDENED_ASSERT_NT_SUCCESS(NtCreateEvent(&hEvtParent, EVENT_ALL_ACCESS, &ObjAttrs, NotificationEvent, FALSE)); 3995 4019 3996 4020 /* … … 4140 4164 * Start the process execution. 4141 4165 */ 4142 if (iWhich >= 2) 4143 supR3HardenedWinInitVmChild(hProcess, hThread, uChildNtDllAddr, uChildExeAddr, hEvtChild, hEvtParent); 4166 supR3HardenedWinSetupChildInit(hProcess, hThread, uChildNtDllAddr, uChildExeAddr, hEvtChild, hEvtParent); 4144 4167 4145 4168 ULONG cSuspendCount = 0; … … 4155 4178 PROCESS_BASIC_INFORMATION BasicInfo; 4156 4179 HANDLE hProcWait; 4157 ULONG fRights = SYNCHRONIZE | PROCESS_TERMINATE ;4180 ULONG fRights = SYNCHRONIZE | PROCESS_TERMINATE | PROCESS_VM_READ; 4158 4181 if (g_uNtVerCombined >= SUP_MAKE_NT_VER_SIMPLE(6, 0)) /* Introduced in Vista. */ 4159 4182 fRights |= PROCESS_QUERY_LIMITED_INFORMATION; 4160 4183 else 4161 4184 fRights |= PROCESS_QUERY_INFORMATION; 4162 if (iWhich == 2)4163 fRights |= PROCESS_VM_READ;4164 4185 rcNt = NtDuplicateObject(NtCurrentProcess(), hProcess, 4165 4186 NtCurrentProcess(), &hProcWait, 4166 4187 fRights, 0 /*HandleAttributes*/, 0); 4167 4188 if (rcNt == STATUS_ACCESS_DENIED) 4189 { 4190 supR3HardenedError(rcNt, false /*fFatal*/, 4191 "supR3HardenedWinDoReSpawn: NtDuplicateObject(,,,,%#x,,) -> %#x, retrying with only %#x...\n", 4192 fRights, rcNt, SYNCHRONIZE); 4168 4193 rcNt = NtDuplicateObject(NtCurrentProcess(), hProcess, 4169 4194 NtCurrentProcess(), &hProcWait, 4170 4195 SYNCHRONIZE, 0 /*HandleAttributes*/, 0); 4196 } 4171 4197 if (!NT_SUCCESS(rcNt)) 4172 4198 supR3HardenedWinKillChild(hProcess, "supR3HardenedWinReSpawn", VERR_INVALID_NAME, … … 4177 4203 4178 4204 /* 4179 * Signal the VM child that we've closed the unrestricted handles. 4180 */ 4181 if (iWhich >= 2) 4182 { 4183 rcNt = NtSetEvent(hEvtChild, NULL); 4184 if (!NT_SUCCESS(rcNt)) 4185 supR3HardenedWinKillChild(hProcess, "supR3HardenedWinReSpawn", VERR_INVALID_NAME, 4186 "NtSetEvent failed on child process handle: %#x\n", rcNt); 4187 } 4205 * Signal the child that we've closed the unrestricted handles. 4206 */ 4207 rcNt = NtSetEvent(hEvtChild, NULL); 4208 if (!NT_SUCCESS(rcNt)) 4209 supR3HardenedWinKillChild(hProcess, "supR3HardenedWinReSpawn", VERR_INVALID_NAME, 4210 "NtSetEvent failed on child process handle: %#x\n", rcNt); 4188 4211 4189 4212 /* … … 4233 4256 rcNt = NtWaitForMultipleObjects(cHandles, &ahHandles[0], WaitAnyObject, TRUE /*Alertable*/, NULL /*pTimeout*/); 4234 4257 if (rcNt == STATUS_WAIT_0 + 1 && hEvtParent != NULL) 4235 supR3HardenedWinCheck VmChild(hProcWait, uChildExeAddr, &hEvtParent, &hEvtChild);4258 supR3HardenedWinCheckChild(hProcWait, uChildExeAddr, &hEvtParent, &hEvtChild); 4236 4259 else if ( (ULONG)rcNt - (ULONG)STATUS_WAIT_0 < cHandles 4237 4260 || (ULONG)rcNt - (ULONG)STATUS_ABANDONED_WAIT_0 < cHandles) … … 4418 4441 static void supR3HardenedWinOpenStubDevice(void) 4419 4442 { 4443 if (g_fSupStubOpened) 4444 return; 4445 4420 4446 /* 4421 4447 * Retry if we think driver might still be initializing (STATUS_NO_SUCH_DEVICE + \Drivers\VBoxDrv). 4422 4448 */ 4423 4449 static const WCHAR s_wszName[] = L"\\Device\\VBoxDrvStub"; 4424 DWORD const uStartTick = GetTickCount();4450 uint64_t const uMsTsStart = supR3HardenedWinGetMilliTS(); 4425 4451 NTSTATUS rcNt; 4426 4452 uint32_t iTry; … … 4457 4483 if (rcNt != STATUS_NO_SUCH_DEVICE) 4458 4484 break; 4459 if (iTry > 0 && GetTickCount() - uStartTick> 5000) /* 5 sec, at least two tries */4485 if (iTry > 0 && supR3HardenedWinGetMilliTS() - uMsTsStart > 5000) /* 5 sec, at least two tries */ 4460 4486 break; 4461 4487 if (!supR3HardenedWinDriverExists("VBoxDrv")) … … 4476 4502 } 4477 4503 4478 if (!NT_SUCCESS(rcNt)) 4504 if (NT_SUCCESS(rcNt)) 4505 g_fSupStubOpened = true; 4506 else 4479 4507 { 4480 4508 /* … … 4542 4570 * suggestions accordingly. 4543 4571 */ 4572 /** @todo don't fail during early init, wait till later and try load the driver if missing or at least query the service manager for additional information. */ 4544 4573 if ( rcNt == STATUS_NO_SUCH_DEVICE 4545 4574 || rcNt == STATUS_OBJECT_NAME_NOT_FOUND) … … 4579 4608 /* 4580 4609 * Before the 2nd respawn we set up a child protection deal with the 4581 * support driver via /Devices/VBoxDrvStub. 4610 * support driver via /Devices/VBoxDrvStub. (We tried to do this 4611 * during the early init, but in case we had trouble accessing vboxdrv we 4612 * retry it here where we have kernel32.dll and others to pull in for 4613 * better diagnostics.) 4582 4614 */ 4583 4615 if (iWhich == 2) … … 4687 4719 for (uint32_t iLoop = 0; iLoop < 16; iLoop++) 4688 4720 { 4689 uint32_t 4690 DWORD dwStart = GetTickCount();4721 uint32_t cSleeps = 0; 4722 uint64_t uMsTsStart = supR3HardenedWinGetMilliTS(); 4691 4723 do 4692 4724 { … … 4696 4728 NtDelayExecution(FALSE, &Time); 4697 4729 cSleeps++; 4698 } while ( GetTickCount() - dwStart <= cMsFudge4730 } while ( supR3HardenedWinGetMilliTS() - uMsTsStart <= cMsFudge 4699 4731 || cSleeps < 8); 4700 4732 SUP_DPRINTF(("supR3HardenedWinInit: Startup delay kludge #2/%u: %u ms, %u sleeps\n", 4701 iLoop, GetTickCount() - dwStart, cSleeps));4733 iLoop, supR3HardenedWinGetMilliTS() - uMsTsStart, cSleeps)); 4702 4734 4703 4735 cFixes = 0; … … 5364 5396 if (g_ProcParams.hEvtParent || g_ProcParams.hEvtChild) 5365 5397 { 5366 SUPR3HARDENED_ASSERT(g_fSupEarly VmProcessInit);5398 SUPR3HARDENED_ASSERT(g_fSupEarlyProcessInit); 5367 5399 NtSetEvent(g_ProcParams.hEvtParent, NULL); 5368 5400 NtClose(g_ProcParams.hEvtParent); … … 5372 5404 } 5373 5405 else 5374 SUPR3HARDENED_ASSERT(!g_fSupEarly VmProcessInit);5406 SUPR3HARDENED_ASSERT(!g_fSupEarlyProcessInit); 5375 5407 5376 5408 /* … … 5479 5511 5480 5512 /** 5481 * Routine called by the supR3HardenedVmProcessInitThunk assembly routine when 5482 * LdrInitializeThunk is executed in during process initialization. 5483 * 5484 * This initializes the VM process, hooking NTDLL APIs and opening the device 5485 * driver before any other DLLs gets loaded into the process. This greately 5486 * reduces and controls the trusted code base of the process compared to the 5487 * opening it from SUPR3HardenedMain, avoid issues with so call protection 5488 * software that is in the habit of patching half of the ntdll and kernel32 5489 * APIs in the process, making it almost indistinguishable from software that is 5490 * up to no good. Once we've opened vboxdrv, the process should be locked down 5491 * so thighly that only kernel software and csrss can mess with the process. 5492 */ 5493 DECLASM(uintptr_t) supR3HardenedVmProcessInit(void) 5513 * Routine called by the supR3HardenedEarlyProcessInitThunk assembly routine 5514 * when LdrInitializeThunk is executed in during process initialization. 5515 * 5516 * This initializes the Stub and VM processes, hooking NTDLL APIs and opening 5517 * the device driver before any other DLLs gets loaded into the process. This 5518 * greately reduces and controls the trusted code base of the process compared 5519 * to opening the driver from SUPR3HardenedMain. It also avoids issues with so 5520 * call protection software that is in the habit of patching half of the ntdll 5521 * and kernel32 APIs in the process, making it almost indistinguishable from 5522 * software that is up to no good. Once we've opened vboxdrv, the process 5523 * should be locked down so thighly that only kernel software and csrss can mess 5524 * with the process. 5525 */ 5526 DECLASM(uintptr_t) supR3HardenedEarlyProcessInit(void) 5494 5527 { 5495 5528 /* … … 5497 5530 */ 5498 5531 if (!ASMAtomicCmpXchgU32((uint32_t volatile *)&g_enmSupR3HardenedMainState, 5499 SUPR3HARDENEDMAINSTATE_WIN_ VM_INIT_CALLED,5532 SUPR3HARDENEDMAINSTATE_WIN_EARLY_INIT_CALLED, 5500 5533 SUPR3HARDENEDMAINSTATE_NOT_YET_CALLED)) 5501 5534 { … … 5503 5536 return 0x22; /* crash */ 5504 5537 } 5505 g_fSupEarly VmProcessInit = true;5538 g_fSupEarlyProcessInit = true; 5506 5539 5507 5540 /* … … 5524 5557 Timeout.QuadPart = -600000000; /* 60 second */ 5525 5558 NTSTATUS rcNt = NtWaitForSingleObject(g_ProcParams.hEvtChild, FALSE /*Alertable*/, &Timeout); 5526 if ( NT_SUCCESS(rcNt))5559 if (rcNt != STATUS_SUCCESS) 5527 5560 rcNt = NtClearEvent(g_ProcParams.hEvtChild); 5528 5561 if (!NT_SUCCESS(rcNt)) … … 5568 5601 * Open the driver. 5569 5602 */ 5570 SUP_DPRINTF(("supR3HardenedVmProcessInit: Opening vboxdrv...\n")); 5571 supR3HardenedMainOpenDevice(); 5603 if (cArgs >= 1 && suplibHardenedStrCmp(papszArgs[0], SUPR3_RESPAWN_1_ARG0) == 0) 5604 { 5605 SUP_DPRINTF(("supR3HardenedVmProcessInit: Opening vboxdrv stub...\n")); 5606 supR3HardenedWinOpenStubDevice(); 5607 } 5608 else if (cArgs >= 1 && suplibHardenedStrCmp(papszArgs[0], SUPR3_RESPAWN_2_ARG0) == 0) 5609 { 5610 SUP_DPRINTF(("supR3HardenedVmProcessInit: Opening vboxdrv...\n")); 5611 supR3HardenedMainOpenDevice(); 5612 } 5613 else 5614 supR3HardenedFatal("Unexpected first argument '%s'!\n", papszArgs[0]); 5572 5615 g_enmSupR3HardenedMainState = SUPR3HARDENEDMAINSTATE_WIN_EARLY_DEVICE_OPENED; 5573 5616 -
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMainA-win.asm
r52945 r52949 36 36 37 37 ; External code. 38 extern NAME(supR3Hardened VmProcessInit)38 extern NAME(supR3HardenedEarlyProcessInit) 39 39 40 40 … … 83 83 84 84 ;; 85 ; Alternative code for LdrInitializeThunk that performs the VM process startup. 85 ; Alternative code for LdrInitializeThunk that performs the early process startup 86 ; for the Stub and VM processes. 86 87 ; 87 88 ; This does not concern itself with any arguments on stack or in registers that … … 89 90 ; them all before we restart the restored LdrInitializeThunk routine. 90 91 ; 91 BEGINPROC supR3HardenedVmProcessInitThunk 92 ; @sa supR3HardenedEarlyProcessInit 93 ; 94 BEGINPROC supR3HardenedEarlyProcessInitThunk 92 95 ; 93 96 ; Prologue. … … 123 126 ; resume address in xAX, which we put in the "return" stack position. 124 127 ; 125 call NAME(supR3Hardened VmProcessInit)128 call NAME(supR3HardenedEarlyProcessInit) 126 129 mov [xBP + xCB], xAX 127 130 … … 145 148 leave 146 149 ret 147 ENDPROC supR3Hardened VmProcessInitThunk150 ENDPROC supR3HardenedEarlyProcessInitThunk 148 151 149 152 -
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedNoCrt-win.cpp
r52947 r52949 269 269 if (!hHeap) 270 270 { 271 if ( g_fSupEarly VmProcessInit271 if ( g_fSupEarlyProcessInit 272 272 && g_enmSupR3HardenedMainState <= SUPR3HARDENEDMAINSTATE_WIN_EP_CALLED) 273 273 return supR3HardenedEarlyAlloc(cb, false /*fZero*/); … … 287 287 if (!hHeap) 288 288 { 289 if ( g_fSupEarly VmProcessInit289 if ( g_fSupEarlyProcessInit 290 290 && g_enmSupR3HardenedMainState <= SUPR3HARDENEDMAINSTATE_WIN_EP_CALLED) 291 291 return supR3HardenedEarlyAlloc(cb, true /*fZero*/); … … 328 328 329 329 void *pv; 330 if (g_fSupEarly VmProcessInit)330 if (g_fSupEarlyProcessInit) 331 331 { 332 332 uint32_t iHeap = supR3HardenedEarlyFind(pvOld); … … 387 387 if (pv) 388 388 { 389 if (g_fSupEarly VmProcessInit)389 if (g_fSupEarlyProcessInit) 390 390 { 391 391 uint32_t iHeap = supR3HardenedEarlyFind(pv); -
trunk/src/VBox/HostDrivers/Support/win/import-template-ntdll.h
r52947 r52949 64 64 SUPHARNT_IMPORT_STDCALL(RtlAddAccessAllowedAce, 16) 65 65 SUPHARNT_IMPORT_STDCALL(RtlAddAccessDeniedAce, 16) 66 SUPHARNT_IMPORT_STDCALL _EARLY(RtlAllocateHeap, 12)66 SUPHARNT_IMPORT_STDCALL(RtlAllocateHeap, 12) 67 67 SUPHARNT_IMPORT_STDCALL(RtlCompactHeap, 8) 68 68 SUPHARNT_IMPORT_STDCALL(RtlCopySid, 12) 69 69 SUPHARNT_IMPORT_STDCALL(RtlCreateAcl, 12) 70 SUPHARNT_IMPORT_STDCALL _EARLY(RtlCreateHeap, 24)70 SUPHARNT_IMPORT_STDCALL(RtlCreateHeap, 24) 71 71 SUPHARNT_IMPORT_STDCALL(RtlCreateProcessParameters, 40) 72 72 SUPHARNT_IMPORT_STDCALL(RtlCreateSecurityDescriptor, 8) … … 79 79 SUPHARNT_IMPORT_STDCALL_EARLY(RtlExitUserThread, 4) 80 80 SUPHARNT_IMPORT_STDCALL(RtlExpandEnvironmentStrings_U, 16) 81 SUPHARNT_IMPORT_STDCALL _EARLY(RtlFreeHeap, 12)81 SUPHARNT_IMPORT_STDCALL(RtlFreeHeap, 12) 82 82 SUPHARNT_IMPORT_STDCALL_EARLY(RtlFreeUnicodeString, 4) 83 83 SUPHARNT_IMPORT_STDCALL_EARLY(RtlGetLastNtStatus, 0) … … 91 91 SUPHARNT_IMPORT_STDCALL_EARLY(RtlSetLastWin32Error, 4) 92 92 SUPHARNT_IMPORT_STDCALL_EARLY(RtlSetLastWin32ErrorAndNtStatusFromNtStatus, 4) 93 SUPHARNT_IMPORT_STDCALL _EARLY(RtlSizeHeap, 12)93 SUPHARNT_IMPORT_STDCALL(RtlSizeHeap, 12) 94 94 SUPHARNT_IMPORT_STDCALL_EARLY(RtlSubAuthoritySid, 8) 95 95
Note:
See TracChangeset
for help on using the changeset viewer.