Changeset 52169 in vbox
- Timestamp:
- Jul 24, 2014 2:12:57 PM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 95213
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/Makefile.kmk
r52030 r52169 363 363 endif 364 364 365 SUPR3HardenedMain.cpp_DEFS = VBOX_SVN_REV=$(VBOX_SVN_REV) 366 365 367 366 368 # -
trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h
r52160 r52169 89 89 # define supR3HardenedErrorV supR3HardenedStaticErrorV 90 90 # define supR3HardenedError supR3HardenedStaticError 91 # define supR3HardenedOpenLog supR3HardenedStaticOpenLog 92 # define supR3HardenedLogV supR3HardenedStaticLogV 93 # define supR3HardenedLog supR3HardenedStaticLog 91 94 # define supR3HardenedVerifyAll supR3HardenedStaticVerifyAll 92 95 # define supR3HardenedVerifyFixedDir supR3HardenedStaticVerifyFixedDir … … 131 134 132 135 /** Debug output macro. */ 133 #ifdef DEBUG_bird134 # if def IN_SUP_HARDENED_R3135 # define SUP_DPRINTF(a) suplibHardenedPrintF a136 #ifdef IN_SUP_HARDENED_R3 137 # if defined(DEBUG_bird) && defined(RT_OS_WINDOWS) 138 # define SUP_DPRINTF(a) do { supR3HardenedStaticLog a; suplibHardenedPrintF a; } while (0) 136 139 # else 140 # define SUP_DPRINTF(a) do { supR3HardenedStaticLog a; } while (0) 141 # endif 142 #else 143 # if defined(DEBUG_bird) && defined(RT_OS_WINDOWS) 137 144 # define SUP_DPRINTF(a) RTLogPrintf a 145 # else 146 # define SUP_DPRINTF(a) do { } while (0) 138 147 # endif 139 #else140 # define SUP_DPRINTF(a) do { } while (0)141 148 #endif 142 149 … … 401 408 DECLHIDDEN(int) supR3HardenedError(int rc, bool fFatal, const char *pszFormat, ...); 402 409 410 /** 411 * Open any startup log file specified in the argument. 412 */ 413 DECLHIDDEN(void) supR3HardenedOpenLog(int *pcArgs, char **papszArgs); 414 415 /** 416 * Write to the startup log file. 417 */ 418 DECLHIDDEN(void) supR3HardenedLogV(const char *pszFormat, va_list va); 419 420 /** 421 * Write to the startup log file. 422 */ 423 DECLHIDDEN(void) supR3HardenedLog(const char *pszFormat, ...); 424 425 403 426 DECLHIDDEN(int) supR3HardenedVerifyAll(bool fFatal, const char *pszProgName); 404 427 DECLHIDDEN(int) supR3HardenedVerifyFixedDir(SUPINSTDIR enmDir, bool fFatal); -
trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
r52163 r52169 78 78 #include <VBox/sup.h> 79 79 #include <VBox/err.h> 80 #ifdef RT_OS_WINDOWS 81 # include <VBox/version.h> 82 #endif 80 83 #include <iprt/ctype.h> 81 84 #include <iprt/string.h> … … 141 144 static uint32_t g_uCaps; 142 145 # endif 146 #endif 147 148 /** The startup log file. */ 149 #ifdef RT_OS_WINDOWS 150 static HANDLE g_hStartupLog = NULL; 151 #else 152 static int g_hStartupLog = -1; 143 153 #endif 144 154 … … 235 245 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER; 236 246 NtWriteFile(hStdOut, NULL /*Event*/, NULL /*ApcRoutine*/, NULL /*ApcContext*/, 237 &Ios, (PVOID)pch, cch, NULL /*ByteOffset*/, NULL /*Key*/);247 &Ios, (PVOID)pch, (ULONG)cch, NULL /*ByteOffset*/, NULL /*Key*/); 238 248 } 239 249 #else … … 920 930 921 931 932 #ifdef RT_OS_WINDOWS 933 extern "C" uint32_t g_uNtVerCombined; 934 #endif 935 936 DECLHIDDEN(void) supR3HardenedOpenLog(int *pcArgs, char **papszArgs) 937 { 938 static const char s_szLogOption[] = "--sup-startup-log="; 939 940 /* 941 * Scan the argument vector. 942 */ 943 int cArgs = *pcArgs; 944 for (int iArg = 1; iArg < cArgs; iArg++) 945 if (strncmp(papszArgs[iArg], s_szLogOption, sizeof(s_szLogOption) - 1) == 0) 946 { 947 const char *pszLogFile = &papszArgs[iArg][sizeof(s_szLogOption) - 1]; 948 949 /* 950 * Drop the argument from the vector (has trailing NULL entry). 951 */ 952 memmove(&papszArgs[iArg], &papszArgs[iArg + 1], (cArgs - iArg) * sizeof(papszArgs[0])); 953 *pcArgs -= 1; 954 cArgs -= 1; 955 956 /* 957 * Open the log file, unless we've already opened one. 958 * First argument takes precedence 959 */ 960 #ifdef RT_OS_WINDOWS 961 if (g_hStartupLog == NULL) 962 { 963 PRTUTF16 pwszPath; 964 int rc = RTStrToUtf16(pszLogFile, &pwszPath); 965 if (RT_SUCCESS(rc)) 966 { 967 g_hStartupLog = CreateFileW(pwszPath, 968 GENERIC_WRITE, 969 FILE_SHARE_READ | FILE_SHARE_WRITE, 970 NULL, 971 OPEN_ALWAYS, 972 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, 973 NULL); 974 RTUtf16Free(pwszPath); 975 } 976 SUP_DPRINTF(("Log file opened: " VBOX_VERSION_STRING "r%u g_hStartupLog=%p g_uNtVerCombined=%#x\n", 977 VBOX_SVN_REV, g_hStartupLog, g_uNtVerCombined)); 978 } 979 #else 980 //g_hStartupLog = open() 981 #endif 982 } 983 } 984 985 986 DECLHIDDEN(void) supR3HardenedLogV(const char *pszFormat, va_list va) 987 { 988 #ifdef RT_OS_WINDOWS 989 if (g_hStartupLog) 990 { 991 char szBuf[5120]; 992 PCLIENT_ID pSelfId = &((PTEB)NtCurrentTeb())->ClientId; 993 size_t cchPrefix = RTStrPrintf(szBuf, sizeof(szBuf), "%x.%x: ", pSelfId->UniqueProcess, pSelfId->UniqueThread); 994 size_t cch = RTStrPrintfV(&szBuf[cchPrefix], sizeof(szBuf) - cchPrefix, pszFormat, va) + cchPrefix; 995 996 if ((size_t)cch >= sizeof(szBuf)) 997 cch = sizeof(szBuf) - 1; 998 999 if (!cch || szBuf[cch - 1] != '\n') 1000 szBuf[cch++] = '\n'; 1001 1002 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER; 1003 LARGE_INTEGER Offset; 1004 Offset.QuadPart = -1; /* Write to end of file. */ 1005 NtWriteFile(g_hStartupLog, NULL /*Event*/, NULL /*ApcRoutine*/, NULL /*ApcContext*/, 1006 &Ios, szBuf, (ULONG)cch, &Offset, NULL /*Key*/); 1007 } 1008 #else 1009 /* later */ 1010 #endif 1011 } 1012 1013 1014 DECLHIDDEN(void) supR3HardenedLog(const char *pszFormat, ...) 1015 { 1016 va_list va; 1017 va_start(va, pszFormat); 1018 supR3HardenedLogV(pszFormat, va); 1019 va_end(va); 1020 } 1021 1022 922 1023 /** 923 1024 * Prints the message prefix. … … 934 1035 { 935 1036 /* 936 * To the console first, like supR3HardenedFatalV. 1037 * First to the log. 1038 */ 1039 supR3HardenedLog("Error %d in %s! (enmWhat=%d)\n", rc, pszWhere, enmWhat); 1040 va_list vaCopy; 1041 va_copy(vaCopy, va); 1042 supR3HardenedLogV(pszMsgFmt, vaCopy); 1043 va_end(vaCopy); 1044 1045 /* 1046 * Then to the console. 937 1047 */ 938 1048 suplibHardenedPrintPrefix(); … … 940 1050 941 1051 suplibHardenedPrintPrefix(); 942 va_list vaCopy;943 1052 va_copy(vaCopy, va); 944 1053 suplibHardenedPrintFV(pszMsgFmt, vaCopy); … … 1018 1127 DECLHIDDEN(void) supR3HardenedFatalV(const char *pszFormat, va_list va) 1019 1128 { 1129 supR3HardenedLog("Fatal error:\n"); 1130 va_list vaCopy; 1131 va_copy(vaCopy, va); 1132 supR3HardenedLogV(pszFormat, vaCopy); 1133 va_end(vaCopy); 1134 1020 1135 suplibHardenedPrintPrefix(); 1021 1136 suplibHardenedPrintFV(pszFormat, va); … … 1037 1152 if (fFatal) 1038 1153 supR3HardenedFatalV(pszFormat, va); 1154 1155 supR3HardenedLog("Error (rc=%d):\n", rc); 1156 va_list vaCopy; 1157 va_copy(vaCopy, va); 1158 supR3HardenedLogV(pszFormat, vaCopy); 1159 va_end(vaCopy); 1039 1160 1040 1161 suplibHardenedPrintPrefix(); … … 1052 1173 return rc; 1053 1174 } 1175 1054 1176 1055 1177 … … 1512 1634 DECLHIDDEN(int) SUPR3HardenedMain(const char *pszProgName, uint32_t fFlags, int argc, char **argv, char **envp) 1513 1635 { 1636 SUP_DPRINTF(("SUPR3HardenedMain: pszProgName=%s fFlags=%#x\n", pszProgName, fFlags)); 1637 1514 1638 /* 1515 1639 * Note! At this point there is no IPRT, so we will have to stick … … 1556 1680 && supR3HardenedWinIsReSpawnNeeded(1 /*iWhich*/, argc, argv)) 1557 1681 { 1682 SUP_DPRINTF(("SUPR3HardenedMain: Respawn #1\n")); 1558 1683 supR3HardenedWinInit(SUPSECMAIN_FLAGS_DONT_OPEN_DEV); 1559 1684 supR3HardenedVerifyAll(true /* fFatal */, pszProgName); … … 1591 1716 */ 1592 1717 if (supR3HardenedWinIsReSpawnNeeded(2 /* iWhich*/, argc, argv)) 1718 { 1719 SUP_DPRINTF(("SUPR3HardenedMain: Respawn #2\n")); 1593 1720 return supR3HardenedWinReSpawn(2 /* iWhich*/); 1721 } 1722 SUP_DPRINTF(("SUPR3HardenedMain: Final process, opening VBoxDrv...\n")); 1594 1723 #endif /* RT_OS_WINDOWS */ 1595 1724 … … 1624 1753 * call RTR3InitEx. 1625 1754 */ 1755 SUP_DPRINTF(("SUPR3HardenedMain: Load Runtime...\n")); 1626 1756 g_enmSupR3HardenedMainState = SUPR3HARDENEDMAINSTATE_INIT_RUNTIME; 1627 1757 supR3HardenedMainInitRuntime(fFlags); … … 1631 1761 * and pass control to it. 1632 1762 */ 1763 SUP_DPRINTF(("SUPR3HardenedMain: Load TrustedMain...\n")); 1633 1764 g_enmSupR3HardenedMainState = SUPR3HARDENEDMAINSTATE_GET_TRUSTED_MAIN; 1634 1765 PFNSUPTRUSTEDMAIN pfnTrustedMain = supR3HardenedMainGetTrustedMain(pszProgName); 1766 1767 SUP_DPRINTF(("SUPR3HardenedMain: Calling TrustedMain (%p)...\n", pfnTrustedMain)); 1635 1768 g_enmSupR3HardenedMainState = SUPR3HARDENEDMAINSTATE_CALLED_TRUSTED_MAIN; 1636 1769 return pfnTrustedMain(argc, argv, envp); -
trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyProcess-win.cpp
r52030 r52169 998 998 static int supHardNtVpScanVirtualMemory(PSUPHNTVPSTATE pThis, HANDLE hProcess) 999 999 { 1000 SUP_DPRINTF(("supHardNtVpScanVirtualMemory:\n")); 1001 1000 1002 uint32_t cXpExceptions = 0; 1001 1003 uintptr_t cbAdvance = 0; … … 1037 1039 "NtQueryVirtualMemory/MemorySectionName failed for %p: %#x", uPtrWhere, rcNt); 1038 1040 pThis->aImages[iImg].Name.UniStr.Buffer[pThis->aImages[iImg].Name.UniStr.Length / sizeof(WCHAR)] = '\0'; 1041 SUP_DPRINTF((MemInfo.AllocationBase == MemInfo.BaseAddress 1042 ? " *%p-%p %#06x/%#06x %#09x %ls\n" 1043 : " %p-%p %#06x/%#06x %#09x %ls\n", 1044 MemInfo.BaseAddress, (uintptr_t)MemInfo.BaseAddress - MemInfo.RegionSize - 1, MemInfo.Protect, 1045 MemInfo.AllocationProtect, MemInfo.Type, pThis->aImages[iImg].Name.UniStr.Buffer)); 1039 1046 1040 1047 /* New or existing image? */ … … 1082 1089 /* && MemInfo.BaseAddress == pPeb->ReadOnlySharedMemoryBase */ 1083 1090 && g_uNtVerCombined < SUP_MAKE_NT_VER_SIMPLE(6, 0) ) 1091 { 1084 1092 cXpExceptions++; 1093 SUP_DPRINTF((" %p-%p %#06x/%#06x %#09x XP CSRSS read-only region\n", MemInfo.BaseAddress, 1094 (uintptr_t)MemInfo.BaseAddress - MemInfo.RegionSize - 1, MemInfo.Protect, 1095 MemInfo.AllocationProtect, MemInfo.Type)); 1096 } 1085 1097 /* 1086 1098 * Executable memory? … … 1106 1118 } 1107 1119 #endif 1120 else 1121 SUP_DPRINTF((MemInfo.AllocationBase == MemInfo.BaseAddress 1122 ? " *%p-%p %#06x/%#06x %#09x\n" 1123 : " %p-%p %#06x/%#06x %#09x\n", 1124 MemInfo.BaseAddress, (uintptr_t)MemInfo.BaseAddress - MemInfo.RegionSize - 1, 1125 MemInfo.Protect, MemInfo.AllocationProtect, MemInfo.Type)); 1108 1126 1109 1127 /* -
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r52163 r52169 1543 1543 PVOID pvLdrInitThunk = (PVOID)((uintptr_t)LdrInitializeThunk + pThis->uNtDllAddr - pThis->uNtDllParentAddr); 1544 1544 PVOID pvNtTerminateThread = (PVOID)((uintptr_t)NtTerminateThread + pThis->uNtDllAddr - pThis->uNtDllParentAddr); 1545 SUP_DPRINTF(("supR3HardNtPuChTriggerInitialImageEvents: pvLdrInitThunk=%p pvNtTerminateThread=%p\n", 1546 pvLdrInitThunk, pvNtTerminateThread)); 1545 1547 1546 1548 /* … … 1787 1789 "NtQueryVirtualMemory/MemorySectionName failed for %p: %#x", pMemInfo->BaseAddress, rcNt); 1788 1790 uBuf.UniStr.Buffer[uBuf.UniStr.Length / sizeof(WCHAR)] = '\0'; 1791 SUP_DPRINTF(("supR3HardNtPuChSanitizeImage: %p '%ls'\n", pMemInfo->BaseAddress, uBuf.UniStr.Buffer)); 1792 1789 1793 1790 1794 /* … … 2042 2046 { 2043 2047 pThis->uNtDllAddr = (uintptr_t)MemInfo.AllocationBase; 2048 SUP_DPRINTF(("supR3HardNtPuChFindNtdll: uNtDllParentAddr=%p uNtDllChildAddr=%p\n", 2049 pThis->uNtDllParentAddr, pThis->uNtDllAddr)); 2044 2050 return; 2045 2051 } … … 2094 2100 else 2095 2101 This.cbPeb = PEB_SIZE_W81; 2102 2103 SUP_DPRINTF(("supR3HardenedWinPurifyChild: PebBaseAddress=%p cbPeb=%#x\n", This.BasicInfo.PebBaseAddress, This.cbPeb)); 2096 2104 2097 2105 SIZE_T cbActualMem; … … 2189 2197 GetLastError(), pwszCmdLine); 2190 2198 2199 SUP_DPRINTF(("supR3HardenedWinDoReSpawn(%d): New child %x.%x [kernel32].\n", 2200 iWhich, ProcessInfoW32.dwProcessId, ProcessInfoW32.dwThreadId)); 2191 2201 HANDLE hProcess = ProcessInfoW32.hProcess; 2192 2202 HANDLE hThread = ProcessInfoW32.hThread; … … 2242 2252 rcNt, CmdLine.Buffer); 2243 2253 2254 SUP_DPRINTF(("supR3HardenedWinDoReSpawn(%d): New child %x.%x [ntdll].\n", 2255 iWhich, ProcessInfo.ClientId.UniqueProcess, ProcessInfo.ClientId.UniqueThread)); 2244 2256 RtlDestroyProcessParameters(pProcParams); 2245 2257 … … 2247 2259 HANDLE hThread = ProcessInfoNt.ThreadHandle; 2248 2260 #endif 2261 2249 2262 2250 2263 /* … … 2288 2301 { 2289 2302 /* Failure is unacceptable, kill the process. */ 2290 DWORD dwErr = GetLastError();2291 2303 NtTerminateProcess(hProcess, RTEXITCODE_FAILURE); 2292 supR3HardenedError( dwErr, false /*fFatal*/, "NtDuplicateObject failed on child process handle: %u\n", dwErr);2304 supR3HardenedError(rcNt, false /*fFatal*/, "NtDuplicateObject failed on child process handle: %#x\n", rcNt); 2293 2305 2294 2306 NTSTATUS rcNtExit = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &BasicInfo, sizeof(BasicInfo), NULL); … … 2314 2326 && GetTickCount() - dwStartTick < 60 * 1000); 2315 2327 if (fExitOk) 2316 supR3HardenedError( dwErr, false /*fFatal*/,2328 supR3HardenedError(rcNt, false /*fFatal*/, 2317 2329 "NtDuplicateObject failed and we failed to kill child: rcNt=%u rcNtWait=%u hProcess=%p\n", 2318 2330 rcNt, rcNtWait, hProcess); … … 2387 2399 * Proxy the termination code of the child, if it exited already. 2388 2400 */ 2389 rcNt= NtQueryInformationProcess(hProcWait, ProcessBasicInformation, &BasicInfo, sizeof(BasicInfo), NULL);2390 if ( !NT_SUCCESS(rcNt )2401 NTSTATUS rcNt2 = NtQueryInformationProcess(hProcWait, ProcessBasicInformation, &BasicInfo, sizeof(BasicInfo), NULL); 2402 if ( !NT_SUCCESS(rcNt2) 2391 2403 || BasicInfo.ExitStatus == STATUS_PENDING) 2392 2404 BasicInfo.ExitStatus = RTEXITCODE_FAILURE; 2393 2405 2394 2406 NtClose(hProcWait); 2407 SUP_DPRINTF(("supR3HardenedWinDoReSpawn(%d): Quitting: ExitCode=%#x rcNt=%#x\n", BasicInfo.ExitStatus, rcNt)); 2395 2408 suplibHardenedExit((RTEXITCODE)BasicInfo.ExitStatus); 2396 2409 } … … 2749 2762 extern "C" void __stdcall suplibHardenedWindowsMain(void) 2750 2763 { 2751 RTEXITCODE 2764 RTEXITCODE rcExit = RTEXITCODE_FAILURE; 2752 2765 2753 2766 g_cSuplibHardenedWindowsMainCalls++; … … 2758 2771 */ 2759 2772 supR3HardenedWinInitVersion(); 2773 2774 /* 2775 * Convert the arguments to UTF-8 and open the log file if specified. 2776 * This must be done as early as possible since the code below may fail. 2777 */ 2778 PUNICODE_STRING pCmdLineStr = &NtCurrentPeb()->ProcessParameters->CommandLine; 2779 int cArgs; 2780 char **papszArgs = suplibCommandLineToArgvWStub(pCmdLineStr->Buffer, pCmdLineStr->Length / sizeof(WCHAR), &cArgs); 2781 2782 supR3HardenedOpenLog(&cArgs, papszArgs); 2760 2783 2761 2784 /* … … 2790 2813 2791 2814 /* 2792 * Convert the arguments to UTF-8 and call the C/C++ main function. 2793 */ 2794 PUNICODE_STRING pCmdLineStr = &NtCurrentPeb()->ProcessParameters->CommandLine; 2795 int cArgs; 2796 char **papszArgs = suplibCommandLineToArgvWStub(pCmdLineStr->Buffer, pCmdLineStr->Length / sizeof(WCHAR), &cArgs); 2797 2815 * Call the C/C++ main function. 2816 */ 2817 SUP_DPRINTF(("Calling main()\n")); 2798 2818 rcExit = (RTEXITCODE)main(cArgs, papszArgs, NULL); 2799 2819 … … 2801 2821 * Exit the process (never return). 2802 2822 */ 2823 SUP_DPRINTF(("Terminating the normal way: rcExit=%d\n", rcExit)); 2803 2824 suplibHardenedExit(rcExit); 2804 2825 }
Note:
See TracChangeset
for help on using the changeset viewer.