Commit Graph

926 Commits

Author SHA1 Message Date
Amarnath Valluri
1fb8bb790f Support added to receive data socket over control socket
As objected by QEMU upstream developers to use two different sockets for
starting/using of swtpm, This commit adds support for passing unix domain
socket over control channel.

The summary of the changes include:
 - Defined new control command CMD_SET_DATAFD, using this clients can send data
   socket.
 - set mlp.fd and mlp.flags outside of the mainloop
 - updated the testcases

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-09-29 13:11:01 -04:00
Stefan Berger
52d1090b74 swtpm: switch to recvmsg for receiving data
In preparation for receiving control messages via UnixIO sockets,
switch to recvmsg() for receiving the first chunk of data.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-28 09:40:16 -04:00
Stefan Berger
ec3352ff7f swtpm: enable receiving control commands in chunks
Enable receiving control commands in small chnunks. Allow 500ms
for the whole control command to be received.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-28 09:40:15 -04:00
Stefan Berger
dd96bd5417 swtpm: add missing PTM_CAP_GET_CONFIG to returned flags
Add the missing PTM_CAP_GET_CONFIG to the returned flags.

Fix the order of the flags on the way.

Fix the test cases that test for the flags.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-27 07:11:32 -04:00
Stefan Berger
b1fe8710d7 swtpm: Make 32bit CUSE swtpm work on 64bit host
Remove the check for the FUSE_IOCTL_COMPAT flag to make a 32bit
CUSE swtpm work on 64bit host.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-26 11:44:51 -04:00
Stefan Berger
c5b54f3279 Build: Fix coverity_scan parameters
Use a new and encrypted token. Fix other parameters. Build works now
and submits to coverity if coverty_scan branch is pushed to.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-22 10:51:57 -04:00
Stefan Berger
11e8030a9d Extend Travis integration with Coverity Scans
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-22 09:46:27 -04:00
Stefan Berger
2846f11541 ci: add .travis.yml
Add script for integration with Travis.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-31 13:21:41 -04:00
Stefan Berger
f1766b31b3 swtpm: raise error on unhandle command line parameters
Raise an error on unhandled non-option command line parameters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-25 10:59:14 -04:00
Stefan Berger
5817b1e497 Fix possible illegal buffer access
Fix possible illegal buffer access in case a character device
is used via ioctl. In this case we have to make sure we only
access the number of bytes in the ioctl structure itself.

In case of a socket, make sure we received enough bytes to
be able to access the payload.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-18 17:16:55 -04:00
Stefan Berger
b79146caa2 Fix memory leak of tpmstatedir in case of error
Fix memory leak of tpmstatedir in case of error.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-18 17:08:11 -04:00
Stefan Berger
c4b8d7b443 Fix memory leak of pidfile in case of error
Fix memory leak of pidfile in case of error.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-18 17:07:59 -04:00
Stefan Berger
01aa2ed3af tests: Run tests also on socket interfaces
Refactor the tests so that they all run on socket interfaces as well.

Use socket ports in the range of 65400-65499 for TPM 1.2 tests.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-11 14:04:40 -04:00
Stefan Berger
f3a149175c tests: add functions for running swtpm and swtpm_ioctl
To be able to run tests with either one of the interfaces, add function
for running swtpm and swtpm_ioctl commands and form the command line
parameters dependent on the type of interface being passed. We rely on
environment variables to provide the specific parameters that are needed
to run the program with the appropriate parameters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-11 14:04:40 -04:00
Stefan Berger
63ab6c3c21 Introduce '--flag not-need-init' for socket and chardev
Change the startup behavior with respect to requiring an INIT command
via control channel. We change this for the socket and chardev
interfaces so that the behavior now is the same as that of the CUSE
interface.

Introduce the --flag not-need-init command line option for the socket
and chardev interfaces to allow the old behavior using this option.

Adapt some of the test cases and swtpm_setup.sh.in that now need this
command line flag.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-11 14:04:40 -04:00
Stefan Berger
cf618c3d10 swtpm_setup: Allow running swtpm_setup as tss directly
Allow running swtpm_setup directly as tss user using the following
command lines as an example for how to do it:

mkdir /tmp/test-tss
chown tss:tss /tmp/test-tss
chmod 770 /tmp/test-tss
su -c "swtpm_setup --tpm-state /tmp/test-tss" -s /bin/sh tss

This change prevents us from requiring invocation under the root
user.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-11 14:04:19 -04:00
Stefan Berger
df28cf6258 swtpm_setup: replace show_help variable by change_user
Replace the show_help variable with change_user varaible with
opposite logic. The name of the variable is better for upcoming
changes.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-11 13:59:36 -04:00
Stefan Berger
70cb447a99 Fix return code for ResetEstablishmentBit
If the return code from the command processing function is 0,
get the error code from the command response and return that one
instead. The problem was that clients though resetting the
establishment bit worked in locality 0 for example, while it did
not.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-10 12:13:45 -04:00
Stefan Berger
ac78c63634 Fix a parameter problem in non-Linux function prototype
A parameter from the TPM2 backport had not been removed. Fix it so
it compiles on cygwin.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-10 12:12:44 -04:00
Stefan Berger
970faf77b7 swtpm_ioctl: fix ctrlcmd return parameter and fix state recv logic
Return the number of bytes received in case ctrlcmd does not
use an ioctl because in this case we need to know how many bytes
we received in the response.

The receiving of the state blob also needs to take into account
how many bytes were received in the initial response so we write
the proper amount of bytes from that response into the file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-30 16:09:27 -04:00
Stefan Berger
5130f4e357 swtpm: silence printf's in TPM1.2 inherited code
Silence the printf's in code taken from TPM1.2.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-29 15:49:08 -04:00
Stefan Berger
f18c4cce67 tests: Increase sleep time to accomocate slow ARM
Increase the timeout from 0.2 to 1 seconds so that a tests
passes on ARM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-29 14:27:58 -04:00
Stefan Berger
84259c17df swtpm: Enable --migration-key for socket and chardev interfaces
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-15 19:11:33 -04:00
Stefan Berger
8a1de2ce47 swtpm: log error if broken header is detected
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-15 19:10:13 -04:00
Stefan Berger
1ff4c6c54a swtpm: work on a copy of argv[] variables
While parsing the options we modified the argv[] values and
the commas disappeared, which showed when checking for the
swtpm processes using 'ps'. So, work on a copy of the options
parameter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-15 19:10:13 -04:00
Stefan Berger
95a0542a26 swtpm: Fix an endianess issue in ctrlchannel and offset bug
There was an offset bug in the code getting the state blobs
from a client.

Also fix an endianess bug in a control channel command.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-15 18:54:15 -04:00
Stefan Berger
e3d8093b00 swtpm_ioctl: enable state migration for socket interface 2017-06-15 18:53:31 -04:00
Stefan Berger
dc1111362b Implement allow-set-locality for CUSE TPM and extend test case.
Implement allow-set-locality for CUSE TPM and extend the existing
locality test case with commands that try to write the SetLocality
comamnd to the device.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-06 16:51:45 -04:00
Stefan Berger
3b563487b6 Extend help screen with allow-set-locality option
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-06 16:42:39 -04:00
Stefan Berger
a2f81ea2c6 Implement support for --locality allow-set-locality option
Implement support for --locality allow-set-locality option that
is primarily useful in cases when the VTPM proxy access is enabled
by file descriptor passing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-06 14:10:01 -04:00
Stefan Berger
cb35cba105 tests: Extend existing test with one for rejection of locality 4
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-01 16:59:20 -04:00
Stefan Berger
4a56541491 Add options for locality handling and SetLocality command
Add options for locality handling so that commands in locality
4 for example are rejected per command line parameter. This is
useful when the vTPM is used with containers.

Also implement the custom TPM/TPM2_SetLocality command to allow
the Linux vTPM proxy driver to set the locality in which subsequent
TPM commands will be executed.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-01 16:59:20 -04:00
Stefan Berger
bbf12ed918 tests: Increase socat timeout to avoid errors on slow ARM
Avoid getting useless test failures on ARM due to low timeout settings
of socat.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-05-31 17:47:11 -04:00
Stefan Berger
f071d82071 build: test for linux-* rather than linux-gnu
Check for linux-* when testing $host_os so we properly detect
when to set WITH_VTPM_PROXY.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-05-31 17:45:54 -04:00
Stefan Berger
9606607075 tests: create unix_tx function to use socat to talk to Unix socket
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-05-31 17:26:44 -04:00
Stefan Berger
768d657b69 Fix compilation errors on Debian Jessie 32bit ARM
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-05-31 13:45:44 -04:00
Stefan Berger
b12d77106c swtpm: Refactor error response creation
Refactor the function creating the error response.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-04-19 19:16:29 -04:00
Stefan Berger
811a255869 swtpm: Have the tpm_req_header struct packed
Add missing __attribute__((packed) to tpm_req_header struct.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-04-19 18:45:35 -04:00
Stefan Berger
43153f3d26 swtpm: Check return code < 0 from handle_server_options
Fix the missing check of return code from handle_server_options
to check for negative value like all the other checks also do.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-04-19 18:44:47 -04:00
Stefan Berger
073e71f99e swtpm: Add missing space after hex number
Add a missing space character after display of a hex number.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-04-07 11:23:30 -04:00
Stefan Berger
510f184896 swtpm: Fix memory leak related to option parameters
Fix a memory leak related to the option parameters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-31 08:55:08 -04:00
Stefan Berger
cba815690c swtpm: Use logprintf wherever possible
Use logprintf wherever possible. While the logging is not set up,
print error messages to stderr and prefix them with 'swtpm: '. After
the logging has been set up all error messages go into the log file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-31 08:55:08 -04:00
Stefan Berger
93f4a38940 swtpm: add logging option prefix=<prefix>
Add support for logging each line of output with a prefix.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-31 08:55:08 -04:00
Stefan Berger
8e794c635a swtpm: Use buffer printing for TPM_PrintAll
Use a buffer for printing in TPM_PrintAll. Emit the buffer
upon a new line. This prepares for printing every line with
a prefix.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-31 08:28:21 -04:00
Amarnath Valluri
87d56f936c Read all data at once incase of non-stream sockets.
Add MAIN_LOOP_FLAG_READALL for non SOCK_STREAM client sockets. This allows
reading all socket data once.

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-03-31 08:17:05 -04:00
Amarnath Valluri
0a0885cf9d swtpm: Keep client data connection alive
swtpm server is closing the client data connection after serving a single
request, which shall not happen. Hence added MAIN_LOOP_FLAG_KEEP_CONNECTION
mainloop flag to keep the client data connection alive, till client is alive.

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-03-31 08:17:05 -04:00
Amarnath Valluri
93edca48a2 swtpm: Added support for passing control channel client fd.
New option '--ctrl clientfd=<fd>' is added to the control socket parameters.
The passed 'fd' is used as control channel client-fd and treated as single
client mode.

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-03-31 08:15:51 -04:00
Amarnath Valluri
4cb30804d6 mainloop: enumerate the pollfd indexes.
Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-03-31 08:14:33 -04:00
Stefan Berger
3f37cc3e5f swtpm: Set errno to 0 before calling strtoul
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-31 08:14:33 -04:00
Stefan Berger
d7bbe3de5c swtpm_ioctl: Rearrange code for Unix client socket setup
Rearrange the code of the setup of the Unix client socket.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-14 08:37:56 -04:00