]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/misc: robustify Windows process checking
authorVMware, Inc <>
Mon, 15 Oct 2012 04:52:01 +0000 (21:52 -0700)
committerDmitry Torokhov <dtor@vmware.com>
Fri, 19 Oct 2012 18:32:40 +0000 (11:32 -0700)
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 <dtor@vmware.com>
open-vm-tools/lib/misc/vthreadBase.c

index db3ca6871340e69c93d43e6558252c8b67b01cdc..c4c309769d643366d08a11c7ddbaebc197ecfd5f 100644 (file)
@@ -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