From: VMware, Inc <> Date: Mon, 15 Oct 2012 04:52:01 +0000 (-0700) Subject: lib/misc: robustify Windows process checking X-Git-Tag: 2012.10.14-874563~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aaaeb0b4d317c97242974bdc714de19acfe2f7bf;p=thirdparty%2Fopen-vm-tools.git lib/misc: robustify Windows process checking It is possible for a process to prevent itself for even having it's name checked on Vista and later. We can use the denial of access to determine is a process is alive. Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/lib/misc/vthreadBase.c b/open-vm-tools/lib/misc/vthreadBase.c index db3ca6871..c4c309769 100644 --- a/open-vm-tools/lib/misc/vthreadBase.c +++ b/open-vm-tools/lib/misc/vthreadBase.c @@ -133,12 +133,12 @@ static void VThreadBaseSimpleFreeID(void *tlsData); static void VThreadBaseSafeDeleteTLS(void *data); static struct { - Atomic_Int key; - Atomic_Int dynamicID; - Atomic_Int numThreads; - Atomic_Ptr nativeHash; - void (*noIDFunc)(void); - void (*freeIDFunc)(void *); + Atomic_Int key; + Atomic_Int dynamicID; + Atomic_Int numThreads; + Atomic_Ptr nativeHash; + void (*noIDFunc)(void); + void (*freeIDFunc)(void *); } vthreadBaseGlobals = { { VTHREADBASE_INVALID_KEY }, { VTHREAD_ALLOCSTART_ID }, @@ -933,16 +933,23 @@ VThreadBaseNativeIsAlive(void *native) HANDLE hThread = OpenThread(Hostinfo_OpenThreadBits(), FALSE, (DWORD)(uintptr_t)native); - if (hThread != NULL) { + if (hThread == NULL) { + /* + * An access denied error tells us that the process is alive despite + * the inability of accessing its information. Commonly, access denied + * occurs when a process is trying to completely protect itself (e.g. + * a virus checker). + */ + + return (GetLastError() == ERROR_ACCESS_DENIED) ? TRUE : FALSE; + } else { DWORD exitCode; - BOOL success; + BOOL success = GetExitCodeThread(hThread, &exitCode); - success = GetExitCodeThread(hThread, &exitCode); ASSERT(success); /* No known ways GetExitCodeThread can fail */ CloseHandle(hThread); + return exitCode == STILL_ACTIVE; - } else { - return FALSE; } } #endif