Oliver Kurth [Wed, 3 Jul 2019 21:28:56 +0000 (14:28 -0700)]
Fix process command name for special linux processes.
While listing down the processes in a linux guest, the existing
procMgr library reads /proc/<PID>/cmdline file and parses the
content. While reading this, an assumption is made that there is
a null terminating character at the end of the file content.
This holds true for most of the processes. But for few special processes,
the cmdline file doesn't have the terminating null character.
Oliver Kurth [Wed, 3 Jul 2019 21:28:56 +0000 (14:28 -0700)]
Fix the command name for few linux processes.
ProcMgr library publishes the 'command name' attribute for
each process while listing down all the processes. For doing this,
the commandline is first parsed from /proc/<PID>/cmdline file
and the part starting from the right-most '/' is considered as the
command name. This is OK only if we have an absolute path for the
command binary. Other wise, this may result in incorrect results.
For example:
sshd: root@pts/1
gdm-session-worker [pam/gdm-autologin]
Fixed the code to ignore the parsing if we do not have an absolute
path.
Note: There are two ways how the command name is retrieved for each
process.
1. /proc/<PID>/cmdline is parsed.
If (1) fails for some reason, then
2. /proc/<PID>/status is parsed.
There is no issue with (2). This changeset fixes the parsing issue only
with (1) approach mentioned above.
Oliver Kurth [Wed, 3 Jul 2019 21:28:56 +0000 (14:28 -0700)]
Add support for NVMe disks; IDE and SATA disk devices in 3.x Linux kernels
Support has been added for virtual disks attached to an NVMe
controller. The device "label" will provide the "nvme<n>" for the
controller. The disk unit is provided in the device "nsid" file.
An earlier implementation (Linux 2.6 kernels) provided the unit
number as the final digit group in the device node name.
The Linux 3.x kernel has some differences in the layout of IDE and
SATA disk devices in the sysfs filesystem. The differences from the
sysfs in a 2.6 Linux kernel are:
- The IDE "class" file and SATA "class" and "label" files are in a
different directory.
- IDE controller and SATA device nodes begin with "ata" where "host"
was used in earlier kernel sysfs filesystems.
GuestInfoGetDevClass() has been modfied to check in two possible
locations for the "class" file. The directory located will also
contain the "label" file for SCSI, SAS, and SATA disk devices.
GuestInfoGetIdeSataDev() has been modified to search for either
ata<n> or host<n> directories in the sysfs tree for the disk device.
Oliver Kurth [Wed, 3 Jul 2019 21:26:55 +0000 (14:26 -0700)]
Truncate oversize partition names
Truncate disk partition names if they are too large, rather than just
skipping all the disk information for the guest. Closes
https://github.com/vmware/open-vm-tools/issues/346 .
This patch aims to fix an issue found by Coverity Scan.
This issue is a False Positive, the outBuf is only freed in specific
scenario, so there is no 'BAD FREE'. But it's better to reconstruct the
related code to clear the SCA error.
Oliver Kurth [Mon, 17 Jun 2019 18:41:38 +0000 (11:41 -0700)]
linuxDeployment.c: Suppress the telinit error if the first telinit commands
has made VM reboot.
The code executes '/sbin/telinit 6' repeatedly to reboot VM. VM will be
rebooting if the telinit command executed successfully(exitcode==0).
Observed the repeated telinit command might get error(exitcode==1) on some
GOSes, ex: Ubuntu18.04, RHEL7.4/7.5 and Fedora 29.
Observed no such error on older GOSes, ex: Ubuntu14.04, RHEL6.6
The error telinit log is confusing, actually it does NOT mean customization
failed.
This change does NOT log telinit error, and returns deployPkg status to
make sure the log is consistent with customization result when the first
'telinit 6' succeeded but one of the following 'telinit 6' command failed.
The following actions are unchanged with or without this change:
1. log telinit error, stop loop and exit 127 if the first 'telinit 6' fails.
2. repeatedly execute 'telinit 6' if previous one executed successfully
(exitcode==0).
Fix coverity uninitialized variable "requestId" by zeroing it
in HgfsServerGetRequest before passing to the request packet
HgfsUnpackPacketParams extraction function which will use it
in a log message.
Also moved an assert useful for testing protocol changes which was
incorrect in its placement.
Oliver Kurth [Mon, 17 Jun 2019 18:41:37 +0000 (11:41 -0700)]
Determine Linux OS disk devices associated with mounted filesystems.
For each filesystem for which disk guestInfo is currently collected,
determine the virtual hardware device being used. This is currently
represented as <cntrl class><cntrl #>:<device #>, eg. scsi0:0,
scsi1:0, ide0:0 or sata1:4 and matches the virtual device label seen
in VMX.
A Linux logical volume based filesystem can reside on multiple disks.
In order to handle LVMs, the disk devices for each filesystem are
maintained as a variable array of disk device names.
For Linux guests, disk device names are passed as a json array.
Oliver Kurth [Mon, 17 Jun 2019 18:41:37 +0000 (11:41 -0700)]
Fix 'Using uninitialized value' issue reported by Coverity.
* In a error code path, 'exitCode' variable is used without
any initialization. This issue was reported by the Coverity.
Fixed it by initializing the 'exitCode' to -1.
* While fixing this, moved the variables to the if block where
they are acutally used.
Oliver Kurth [Mon, 17 Jun 2019 18:41:36 +0000 (11:41 -0700)]
Improvements for ProcMgr library.
* This changeset fixes various issues related to ProcMgr library.
== Retrieve the absolute path of the image for each process ==
* When listing down the processes, it is useful to retrieve the
absolute path of the process binary.
=== For Linux ===:
* In /proc filesystem, /proc/{PID}/exe is a symlink to the binary
and we can make use of it to figure out the absolute path.
* If /proc/{PID}/exe is not a valid symlink, then the 'cmdline'
is parsed and aboslute path is calculated accordingly.
* Note: This changeset tries its best to figure out the absolute path.
If it can't, then the attribute is set to NULL.
== Misc issues fixed. ==
=== Linux ===
* Fixed a memory leak with 'procCmdName' while looping through the
/proc/ directory entries.
* Fixed another memory leak with cmdLineTemp and cmdStatTemp variables
while listing down the processes in linux guests.
* In few cases, /proc/{PID}/cmdline file contains multiple NUL
characters at the end. In that case, the existing code converts them
into 'whitespaces'. Fixed the code to chop of all the trailing
whitespaces in the command line.
Oliver Kurth [Mon, 3 Jun 2019 20:39:45 +0000 (13:39 -0700)]
Fix memory leak in SNEBuildHash function.
In a specific code path, if a key already exists in the hashtable,
the memory allocated for 'value' variable is not being freed. This
leads to a memory leak. Fixed.
Oliver Kurth [Mon, 3 Jun 2019 20:39:44 +0000 (13:39 -0700)]
Crash during File_WalkDirectoryNext
In the rewrite of File_WalkDirectoryNext, a bug was introduced in the
invalid Unicode path. Invalid Unicode occurs very rarely... and the
bug finally turned up. Fix this... the bug is rather obvious.
Oliver Kurth [Mon, 3 Jun 2019 20:39:44 +0000 (13:39 -0700)]
Fix asianux identification.
Add asianux to distroArray and change how asianux releases 7 and 8
are identified.
This came in as a pull request on github for open-vm-tools:
https://github.com/vmware/open-vm-tools/pull/325 . Apparently
the OS identification in /etc/asianux-release changed with Asianux
7, and as a result tools does not identify it correctly.
Oliver Kurth [Mon, 3 Jun 2019 20:39:44 +0000 (13:39 -0700)]
Update to common source code; does not affect open-vm-tools.
Allow an asyncWebSocket to connect through an existing socket descriptor
Because Windows does not allow unprivileged processes to specify
DSCP (formerly ToS) values on TCP traffic, in order to support
DSCP for Blast WebSockets we must obtain a preconfigured socket
descriptor from a privileged process and then build the WebSocket
connection over that socket.
This changeset extends the asyncWebSocket API by adding a Connect
function that can accept and use an existing socket descriptor in
addition to the usual collection of WebSocket Connect parameters.
Because the asyncWebSocket is built over an asyncTCPSocket, this
change ripples down into the asyncTCPSocket API which also gets a
new Connect variant with a socket descriptor parameter.
To avoid duplicating existing logic, the old Connect variants
are modified to do their work by invoking the new API with
a distinguished socket descriptor value of -1. This value
indicates that no existing socket descriptor is provided and
that a new socket should be created and used for the connection.
In this changeset, passing in an existing socket is supported
only on the Windows platform. The feature is not required on
other platforms, where unprivileged processes are permitted to
define DSCP values for their connections. Attempting to create
a connection over an existing socket on other platforms will
result in a Connect failure.
Oliver Kurth [Mon, 3 Jun 2019 20:39:44 +0000 (13:39 -0700)]
Round out Log functions to all levels
Logs would be measurably more useful for debugging if the available
levels were used correctly and consistently. As a step towards
encouraging such use, define Log_Warning() and Log_Info() as synonyms
for Warning() and Log() (which, for historical reasons, are not
declared in log.h). Also remove all the conflicting private definitions.
Oliver Kurth [Wed, 22 May 2019 20:09:36 +0000 (13:09 -0700)]
Pick up filesystem (fsType) name for Linux disks.
Building upon the OS Volume Disk Mapping changes added for Windows
guests, pick up and propogate the filesystem type for Linux disks.
Move fsType related code and declaration out of the _WIN32 specific
source code.
Diskwiper code (for Linux) modified to pass along filesystem type
obtained from the MNTINFO structure from the non-Windows guest.
Also passing along the mount point for device-based mapping to be done
in the guestInfo plugin.
Oliver Kurth [Wed, 8 May 2019 22:27:20 +0000 (15:27 -0700)]
Fix the 'procCmdName' attribute of process information.
* When listing down the processes, /proc/{PID}/cmdline file is read
and parsed to figure out the command name. While doing this parsing,
the terminating NUL character is not parsed. Due to this, if any
process doesn't have any command line arguments, the 'command name' is
retrieved as NULL.
Note: This issue doesn't happen if the cmdLine has any arguments.
Ex:
/usr/bin/vmtoolsd -> 'cmdName' is retrieved as NULL
/usr/bin/vmtoolsd -n vmusr -> 'cmdName' is retrieved properly as 'vmtoolsd'
* Fixed the code to include the trailing NUL character also while parsing.
Oliver Kurth [Wed, 8 May 2019 22:27:20 +0000 (15:27 -0700)]
Hgfs fuse Client: fix max name length setting for statvfs
Detected internally with Fedora 29 and reported in
https://github.com/vmware/open-vm-tools/issues/337,
the statvfs structure must provide a valid max name length field. Setting
to NAME_MAX. This allows the GUI Files application to create new folders
and rename existing ones correctly.
Oliver Kurth [Wed, 8 May 2019 22:27:19 +0000 (15:27 -0700)]
Fix copy/paste on Ubuntu 19.04 guest
Ubuntu 19.04 chooses Nautilus 3.32 as the default file browser. From
3.30, Nautilus checks mime type when pasting files from the clipboard,
and the target type is also changed to UTF8_STRING instead of
x-special/gnome-copied-files. To support Ubuntu 19.04, apply this
change into our guest code.
Oliver Kurth [Wed, 8 May 2019 22:27:19 +0000 (15:27 -0700)]
Add a comment in vmci_sockets.h about why a file handle is "leaked"
Let's add a comment in vmci_sockets.h explaining why we intentionally "leak"
a file handle in VMCISock_GetAFValueFd.
fd is intentionally left open when outFd is NULL. Closing it
will break applications running on Linux without a fixed AF for
vSockets. In such cases, the fd will be closed during cleanup when
the application exits.
Oliver Kurth [Wed, 8 May 2019 22:27:19 +0000 (15:27 -0700)]
Fix a trivial Coverity-reported memory leak.
If AuthLoadPAM doesn't find all the needed symbols from the pam
library, then dlclose the library, as is already done for
the same-named funtion in bora/lib/auth/authPosix.c.
Oliver Kurth [Wed, 8 May 2019 22:27:19 +0000 (15:27 -0700)]
Fix Coverity-reported double memory free errors.
Similar double memory free errors were reported in each of two
functions, VixToolsListAuthAliases and VixToolsListMappedAliases.
The fixes for each function are similar: be consistent in using
tmpBuf2 (renamed tmpBuf) as the pointer to the overall buffer being
computed and tmpBuf (renamed nextBuf) as the "next" version of the
buffer. Specifically, in the computation of recordBuf following exit
from the for loop, use the variable formerly known as tmpBuf2 rather
than the one formerly known as tmpBuf.
The variables were renamed in an attempt to distinguish more clearly
between them and how they are used. Also, with these changes in
place, it's evident that there's no need to free nextBuf in the abort
case and as a result its scope can be limited.
Oliver Kurth [Wed, 8 May 2019 22:27:18 +0000 (15:27 -0700)]
Fixes for few leaks and improved error handling.
Fix a memory leak detected by coverity scan. It is not critical,
but it is real in an error case when there is no end mark. While
fixing it, also enhanced code to handle different error cases
properly because we would want valid content to be decoded even
when there are invalid marks in the log file. Invalid log marks
are possible when vmware.log gets rotated in the middle of guest
logging.
While verifying the fix using valgrind, found a couple of more
leaks in panic and warning stubs. Addressed those as well.
Oliver Kurth [Tue, 30 Apr 2019 20:24:25 +0000 (13:24 -0700)]
Provide a shutdown function for users of the unicode library to free memory
allocated by Unicode_Init().
Most applications using the unicode library do not free related memory
since they are about to terminate. A Unicode_Shutdown() function is
provided which will explicitly free the memory allocated by Unicode_Init().
Oliver Kurth [Tue, 30 Apr 2019 20:24:25 +0000 (13:24 -0700)]
vm_basic_defs.h: include stddef.h
The stddef.h header has existed since C89. It includes interesting
things like an offsetof definition, and a definition of NULL.
Let's stop re-inventing this long-standardized header. Except
in vmkernel, where bogus __FreeBSD__ values break gcc's <stddef.h>.
(Detail: vmkernel networking likes to define __FreeBSD__ to empty
or 1, whereas ABI requires "FreeBSD major version".
This change is deliberately minimal as touching headers included
everywhere is inherently fragile. Further cleanups (like removing
vmw_offsetof) can be done in follow-up changes.
The stddef.h header is a 'freestanding' header, which means it's
part of the language and not a "system" header. It is thus safe
to include (modulo vmkernel-networking problem above).
bora-vmsoft/apps/vmtoolsbib/i18n.c: MsgLoadCatalog()
- Coverity reported memory leak when an error is encountered parsing a
line from a message catalog.
- Second memory leak on error missed.
bora-vmsoft/vgauth/common/i18n.c: MsgLoadCatalog()
- Coverity reported some dead code.
- Missed reporting memory leak when error is encountered parsing a
line from a message catalog.
Oliver Kurth [Tue, 30 Apr 2019 20:24:24 +0000 (13:24 -0700)]
Toolsd uses log.text RPC only when the useLogTextRpc is set to TRUE.
This allows the tools installer to start use the log.text RPC without
worrying about that toolsd has not completed the work of scrubbing its logs
for security and privacy issues.
Oliver Kurth [Tue, 30 Apr 2019 20:24:24 +0000 (13:24 -0700)]
Fix memory leak in SNEBuildHash function.
In a specific code path of the SNEBuildHash function, when the
environment variable is of the format VMWARE_*=[0|1], the value
is not freed. Fixed the memory leak.