Changeset 52632 in vbox
- Timestamp:
- Sep 5, 2014 11:00:50 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
include/iprt/thread.h (modified) (1 diff)
-
src/VBox/HostDrivers/Support/SUPLibInternal.h (modified) (1 diff)
-
src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp (modified) (1 diff)
-
src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/thread.h
r47572 r52632 276 276 RTDECL(int) RTThreadCreate(PRTTHREAD pThread, PFNRTTHREAD pfnThread, void *pvUser, size_t cbStack, 277 277 RTTHREADTYPE enmType, unsigned fFlags, const char *pszName); 278 /** @copydoc RTThreadCreate */ 279 typedef DECLCALLBACKPTR(int, PFNRTTHREADCREATE)(PRTTHREAD pThread, PFNRTTHREAD pfnThread, void *pvUser, size_t cbStack, 280 RTTHREADTYPE enmType, unsigned fFlags, const char *pszName); 281 278 282 279 283 /** -
trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h
r52523 r52632 443 443 DECLHIDDEN(bool) supR3HardenedWinIsReSpawnNeeded(int iWhich, int cArgs, char **papszArgs); 444 444 DECLHIDDEN(int) supR3HardenedWinReSpawn(int iWhich); 445 # ifdef _WINDEF_ 446 DECLHIDDEN(void) supR3HardenedWinCreateParentWatcherThread(HMODULE hVBoxRT); 447 # endif 445 448 DECLHIDDEN(void *) supR3HardenedWinLoadLibrary(const char *pszName, bool fSystem32Only); 446 449 extern RTUTF16 g_wszSupLibHardenedExePath[1024]; -
trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
r52527 r52632 1524 1524 supR3HardenedFatalMsg("supR3HardenedMainInitRuntime", kSupInitOp_IPRT, rc, 1525 1525 "RTR3InitEx failed with rc=%d", rc); 1526 1527 #if defined(RT_OS_WINDOWS) 1528 /* 1529 * Windows: Create thread that terminates the process when the parent stub 1530 * process terminates (VBoxNetDHCP, Ctrl-C, etc). 1531 */ 1532 if (!(fFlags & SUPSECMAIN_FLAGS_DONT_OPEN_DEV)) 1533 supR3HardenedWinCreateParentWatcherThread(hMod); 1534 #endif 1526 1535 } 1527 1536 -
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r52627 r52632 47 47 #include <iprt/param.h> 48 48 #include <iprt/path.h> 49 #include <iprt/thread.h> 49 50 #include <iprt/zero.h> 50 51 … … 75 76 do { \ 76 77 if (!(a_Expr)) \ 77 supR3HardenedFatal("%s: %s ", __FUNCTION__, #a_Expr); \78 supR3HardenedFatal("%s: %s\n", __FUNCTION__, #a_Expr); \ 78 79 } while (0) 79 80 … … 83 84 NTSTATUS rcNtAssert = (a_Expr); \ 84 85 if (!NT_SUCCESS(rcNtAssert)) \ 85 supR3HardenedFatal("%s: %s -> %#x ", __FUNCTION__, #a_Expr, rcNtAssert); \86 supR3HardenedFatal("%s: %s -> %#x\n", __FUNCTION__, #a_Expr, rcNtAssert); \ 86 87 } while (0) 87 88 … … 91 92 BOOL fRcAssert = (a_Expr); \ 92 93 if (fRcAssert == FALSE) \ 93 supR3HardenedFatal("%s: %s -> %#x ", __FUNCTION__, #a_Expr, GetLastError()); \94 supR3HardenedFatal("%s: %s -> %#x\n", __FUNCTION__, #a_Expr, GetLastError()); \ 94 95 } while (0) 95 96 … … 820 821 UniStrStatic.Buffer = &wszPath[cwcName + 1]; 821 822 UniStrStatic.Length = 0; 822 UniStrStatic.MaximumLength = (USHORT) sizeof(wszPath) - UniStrStatic.MaximumLength - sizeof(WCHAR);823 UniStrStatic.MaximumLength = (USHORT)(sizeof(wszPath) - cwcName * sizeof(WCHAR) - sizeof(WCHAR)); 823 824 824 825 static UNICODE_STRING const s_DefaultSuffix = RTNT_CONSTANT_UNISTR(L".dll"); … … 1953 1954 1954 1955 /** 1956 * IPRT thread that waits for the parent process to terminate and reacts by 1957 * exiting the current process. 1958 * 1959 * @returns VINF_SUCCESS 1960 * @param hSelf The current thread. Ignored. 1961 * @param pvUser The handle of the parent process. 1962 */ 1963 static DECLCALLBACK(int) supR3HardenedWinParentWatcherThread(RTTHREAD hSelf, void *pvUser) 1964 { 1965 HANDLE hProcWait = (HANDLE)pvUser; 1966 NOREF(hSelf); 1967 1968 /* 1969 * Wait for the parent to terminate. 1970 */ 1971 NTSTATUS rcNt; 1972 for (;;) 1973 { 1974 rcNt = NtWaitForSingleObject(hProcWait, TRUE /*Alertable*/, NULL /*pTimeout*/); 1975 if ( rcNt == STATUS_WAIT_0 1976 || rcNt == STATUS_ABANDONED_WAIT_0) 1977 break; 1978 if ( rcNt != STATUS_TIMEOUT 1979 && rcNt != STATUS_USER_APC 1980 && rcNt != STATUS_ALERTED) 1981 supR3HardenedFatal("NtWaitForSingleObject returned %#x\n", rcNt); 1982 } 1983 1984 /* 1985 * Proxy the termination code of the child, if it exited already. 1986 */ 1987 PROCESS_BASIC_INFORMATION BasicInfo; 1988 NTSTATUS rcNt2 = NtQueryInformationProcess(hProcWait, ProcessBasicInformation, &BasicInfo, sizeof(BasicInfo), NULL); 1989 if ( !NT_SUCCESS(rcNt2) 1990 || BasicInfo.ExitStatus == STATUS_PENDING) 1991 BasicInfo.ExitStatus = RTEXITCODE_FAILURE; 1992 1993 NtClose(hProcWait); 1994 SUP_DPRINTF(("supR3HardenedWinParentWatcherThread: Quitting: ExitCode=%#x rcNt=%#x\n", BasicInfo.ExitStatus, rcNt)); 1995 suplibHardenedExit((RTEXITCODE)BasicInfo.ExitStatus); 1996 1997 return VINF_SUCCESS; /* won't be reached. */ 1998 } 1999 2000 2001 /** 2002 * Creates the parent watcher thread that will make sure this process exits when 2003 * the parent does. 2004 * 2005 * This is a necessary evil to make VBoxNetDhcp and VBoxNetNat termination from 2006 * Main work without too much new magic. It also makes Ctrl-C or similar work 2007 * in on the hardened processes in the windows console. 2008 * 2009 * @param hVBoxRT The VBoxRT.dll handle. We use RTThreadCreate to 2010 * spawn the thread to avoid duplicating thread 2011 * creation and thread naming code from IPRT. 2012 */ 2013 DECLHIDDEN(void) supR3HardenedWinCreateParentWatcherThread(HMODULE hVBoxRT) 2014 { 2015 /* 2016 * Resolve runtime methods that we need. 2017 */ 2018 PFNRTTHREADCREATE pfnRTThreadCreate = (PFNRTTHREADCREATE)GetProcAddress(hVBoxRT, "RTThreadCreate"); 2019 SUPR3HARDENED_ASSERT(pfnRTThreadCreate != NULL); 2020 2021 /* 2022 * Find the parent process ID. 2023 */ 2024 PROCESS_BASIC_INFORMATION BasicInfo; 2025 NTSTATUS rcNt = NtQueryInformationProcess(NtCurrentProcess(), ProcessBasicInformation, &BasicInfo, sizeof(BasicInfo), NULL); 2026 if (!NT_SUCCESS(rcNt)) 2027 supR3HardenedFatal("supR3HardenedWinCreateParentWatcherThread: NtQueryInformationProcess failed: %#x\n", rcNt); 2028 2029 /* 2030 * Open the parent process for waiting and exitcode query. 2031 */ 2032 OBJECT_ATTRIBUTES ObjAttr; 2033 InitializeObjectAttributes(&ObjAttr, NULL, 0, NULL /*hRootDir*/, NULL /*pSecDesc*/); 2034 2035 CLIENT_ID ClientId; 2036 ClientId.UniqueProcess = (HANDLE)BasicInfo.InheritedFromUniqueProcessId; 2037 ClientId.UniqueThread = NULL; 2038 #if 0 /** @todo fix me later. */ 2039 HANDLE hParent; 2040 rcNt = NtOpenProcess(&hParent, SYNCHRONIZE | PROCESS_QUERY_INFORMATION, &ObjAttr, &ClientId); 2041 if (!NT_SUCCESS(rcNt)) 2042 supR3HardenedFatalMsg("supR3HardenedWinCreateParentWatcherThread", kSupInitOp_Misc, VERR_GENERAL_FAILUREps, 2043 "NtOpenProcess(%p.0) failed: %#x\n", ClientId.UniqueProcess, rcNt); 2044 2045 /* 2046 * Create the thread that should do the waiting. 2047 */ 2048 int rc = pfnRTThreadCreate(NULL, supR3HardenedWinParentWatcherThread, hParent, _64K /* stack */, 2049 RTTHREADTYPE_DEFAULT, 0 /*fFlags*/, "ParentWatcher"); 2050 if (RT_FAILURE(rc)) 2051 supR3HardenedFatal("supR3HardenedWinCreateParentWatcherThread: RTThreadCreate failed: %Rrc\n", rc); 2052 #endif 2053 } 2054 2055 2056 /** 1955 2057 * Install hooks for intercepting calls dealing with mapping shared libraries 1956 2058 * into the process.
Note:
See TracChangeset
for help on using the changeset viewer.

