]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Internal branch sync. Included in this change:
authorVMware, Inc <>
Thu, 24 Feb 2011 21:25:21 +0000 (13:25 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Thu, 24 Feb 2011 21:25:21 +0000 (13:25 -0800)
. VIX: properly check file permissions before overwriting.

. changes in shared code that don't affect open-vm-tools functionality.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/include/vm_basic_asm_x86_64.h
open-vm-tools/modules/linux/shared/compat_netdevice.h
open-vm-tools/modules/shared/vmxnet/vmnet_def.h
open-vm-tools/services/plugins/vix/vixTools.c

index 194ae3e78074804d7401356617690d4dc432f04b..64d95122c5001b8f6020fc93a147e9e346a42094 100644 (file)
@@ -71,6 +71,25 @@ uint64 __shiftright128(uint64 lowPart, uint64 highPart, uint8 shift);
 
 #endif // _MSC_VER
 
+/*
+ * GET_CURRENT_RIP
+ *
+ * Return an approximation of the current instruction pointer. For example for a
+ * function call
+ * foo.c
+ * L123: Foo(GET_CURRENT_RIP())
+ *
+ * The return value from GET_CURRENT_RIP will point a debugger to L123.
+ */
+#if defined(__GNUC__)
+#define GET_CURRENT_RIP() ({                                                   \
+      void *__rip;                                                             \
+      asm("lea 0(%%rip), %0;\n\t"                                              \
+         : "=r" (__rip));                                                      \
+      __rip;                                                                   \
+})
+#endif
+
 /*
  * FXSAVE/FXRSTOR
  *     save/restore SIMD/MMX fpu state
index d29fcbdefcdcf4b657106fe7c4a3de0e6aaa2d9e..7a563048ddfddfac189fffc26e31de68b1ee60a0 100644 (file)
@@ -340,4 +340,10 @@ static inline int compat_unregister_netdevice_notifier(struct notifier_block *nb
 #   define compat_netif_tx_unlock(dev) do {} while (0)
 #endif
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)
+#   define COMPAT_VLAN_GROUP_ARRAY_LEN VLAN_N_VID
+#else
+#   define COMPAT_VLAN_GROUP_ARRAY_LEN VLAN_GROUP_ARRAY_LEN
+#endif
+
 #endif /* __COMPAT_NETDEVICE_H__ */
index 376b732239fcc697acf0493e774f810b641fcf6b..6e44aea2bb5cf2bdc370b1f8e9a60cecbdd8a2ae 100644 (file)
@@ -49,6 +49,8 @@
 #include "includeCheck.h"
 
 #define VMNET_NAME_BUFFER_LEN  128 /* Increased for i18n. */
+#define VMNET_COAL_SCHEME_NAME_LEN 16
+
 
 /*
  * capabilities - not all of these are implemented in the virtual HW
index 837dbb923ba31ad5814277225ecb010c2b781551..6dff451c8334c3bdf37c81f5658867d752df01a5 100644 (file)
@@ -1368,6 +1368,11 @@ VixToolsStartProgramImpl(const char *requestName,      // IN
 #endif
    GSource *timer;
 
+   /*
+    * Initialize this here so we can call free on its member variables in abort
+    */
+   memset(&procArgs, 0, sizeof procArgs);
+
    if (NULL != pid) {
       *pid = (int64) -1;
    }
@@ -1479,7 +1484,6 @@ VixToolsStartProgramImpl(const char *requestName,      // IN
     */
    asyncState = Util_SafeCalloc(1, sizeof *asyncState);
 
-   memset(&procArgs, 0, sizeof procArgs);
 #if defined(_WIN32)
    if (NULL != envVars) {
       err = VixToolsEnvironToEnvBlock(envVars, &envBlock);
@@ -4029,9 +4033,9 @@ VixToolsInitiateFileTransferToGuest(VixCommandRequestHeader *requestMsg)  // IN
 #if defined(_WIN32)
    int fd = -1;
    char *tempFilePath = NULL;
-#else
-   FileIOResult res;
+   static char *tempFileBaseName = "vmware";
 #endif
+   FileIOResult res;
 
    VixCommandInitiateFileTransferToGuestRequest *commandRequest;
    VMAutomationRequestParser parser;
@@ -4099,11 +4103,29 @@ VixToolsInitiateFileTransferToGuest(VixCommandRequestHeader *requestMsg)  // IN
    if (File_Exists(guestPathName)) {
       if (File_IsDirectory(guestPathName)) {
          err = VIX_E_NOT_A_FILE;
-         goto abort;
       } else if (!overwrite) {
          err = VIX_E_FILE_ALREADY_EXISTS;
-         goto abort;
+      } else {
+         /*
+          * If the file exists and overwrite flag is true, then check
+          * if the file is writable. If not, return a proper error.
+          */
+         res = FileIO_Access(guestPathName, FILEIO_ACCESS_WRITE);
+         if (FILEIO_SUCCESS != res) {
+            /*
+             * On Linux guests, FileIO_Access sets the proper errno
+             * on failure. On Windows guests, last errno is not
+             * set when FileIO_Access fails. So, we cannot use
+             * FoundryToolsDaemon_TranslateSystemErr() to translate the
+             * error. To maintain consistency for all the guests,
+             * return an explicit VIX_E_FILE_ACCESS_ERROR.
+             */
+            err = VIX_E_FILE_ACCESS_ERROR;
+            Debug("Unable to get access permissions for the file: %s\n",
+                  guestPathName);
+         }
       }
+      goto abort;
    }
 
    File_GetPathName(guestPathName, &dirName, &baseName);
@@ -4145,10 +4167,11 @@ VixToolsInitiateFileTransferToGuest(VixCommandRequestHeader *requestMsg)  // IN
     * create the temporary file with the exact specified filename. Any name
     * would be fine.
     */
-   fd = File_MakeTempEx(dirName, baseName, &tempFilePath);
+   fd = File_MakeTempEx(dirName, tempFileBaseName, &tempFilePath);
 
    if (fd > 0) {
       close(fd);
+      File_UnlinkNoFollow(tempFilePath);
    } else {
       /*
        * File_MakeTempEx() function internally uses Posix variant
@@ -4172,7 +4195,15 @@ VixToolsInitiateFileTransferToGuest(VixCommandRequestHeader *requestMsg)  // IN
    res = FileIO_Access(dirName, FILEIO_ACCESS_WRITE);
 
    if (FILEIO_SUCCESS != res) {
-      err = FoundryToolsDaemon_TranslateSystemErr();
+      /*
+       * On Linux guests, FileIO_Access sets the proper errno
+       * on failure. On Windows guests, last errno is not
+       * set when FileIO_Access fails. So, we cannot use
+       * FoundryToolsDaemon_TranslateSystemErr() to translate the
+       * error. To maintain consistency for all the guests,
+       * return an explicit VIX_E_FILE_ACCESS_ERROR.
+       */
+      err = VIX_E_FILE_ACCESS_ERROR;
       Debug("Unable to get access permissions for the directory: %s\n",
             dirName);
       goto abort;