Commit Graph

276 Commits

Author SHA1 Message Date
Stefan Berger
db60877590 swtpm: Allow file desciptor passing for pid file
Allow the passing of a file descriptor where the PID file will
be written into.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-05 10:43:25 -04:00
Stefan Berger
0d00e18f87 selinux: update policy for swtpm to support libvirt integration
Update the SELinux for swtpm so that swtpm can be launched from
libvirtd and QEMU can access swtpm's UnixIO socket and talk to it.

Use this as follows:

> cd src/selinux
> make clean all
> semodule -i *.pp
> restorecon /usr/bin/swtpm*

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-04 12:37:18 -04:00
Stefan Berger
f34e01a5a9 swtpm: Add 'uid' and 'gid' parameter to set UnxiIO file ownership
Implement support for uid and gid parameters that allows us to set the file
ownership of a UnixIO socket.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-03 07:48:25 -04:00
Stefan Berger
682fe58172 swtpm: Add 'mode' parameter to allow setting UnixIO path file mode bits
Implement support for a mode parameter that allows us to set the file
mode bits on a UnixIO socket.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-03 07:30:56 -04:00
Stefan Berger
7f46fa867f Register libtpms callbacks a lot earlier
Create tpmlib_register_callbacks and call it to register the
libtpms callbacks a lot earlier. Before it was done in tpmlib_start,
which was invoked by CMD_INIT, which was after state blobs could
have been set already.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-03-27 22:00:20 -04:00
Stefan Berger
66a10b3028 swtpm: Fix memory leak in ctrlchannel related to sockpath
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 21:11:12 -05:00
Stefan Berger
716608eca2 swtpm: fix memory leaks when getting or setting state
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 21:00:25 -05:00
Stefan Berger
98059a2908 swtpm: Also check the state blob in the CUSE TPM
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 15:31:09 -05:00
Stefan Berger
b085ff2335 swtpm: Validate state blobs after setting them
Validate the state blobs after they have been set (during
state migration) so that we can fall back to the migration
source in case they are not accepted by the TPM.

This patch requires the latest version of libtpms 0.6
from the master branch.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 14:24:06 -05:00
Stefan Berger
6e79c3b32d swtpm_setup: avoid using expect tool whenever possible
Avoid using the expect tool as much as possible. Use it only if
the user requested a special owner and/or SRK password.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-12 10:29:37 -05:00
Stefan Berger
78c185487e swtpm_setup: Strictly use passwords as specified by user
Use the passwords as specified by the user also when only temporarily
taking ownership. Use the zero password in case nothing has been
provided by the user. This is a first step to loosen the dependency
on expect, which pulls in too many dependencies.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-12 10:10:33 -05:00
Stefan Berger
bf544661b0 swtpm: loop in case poll sets errno EINTR
In case the poll() is interrupted by a signal handler and we
get EINTR, we loop again assuming that the signal handler will
send us a notification to end.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-30 09:07:46 -05:00
Stefan Berger
4a10cb1380 swtpm: close client file descriptor if POLLERR is indicated
POLLERR is indicated in some error cases when using the chardev with the
vtpm_proxy with runc. In case the flag is set, we terminate the client
connection rather than endlessly looping.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-30 09:01:01 -05:00
Stefan Berger
83764896f0 swtpm: Refuse to accept passed file descriptors < 3
File descriptors 0, 1, and 2, when used for file descriptor passing,
as is the case in some older version of runc/docker-ce (17.06), do
not work. So we refuse accepting these values and log the error message.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-30 09:01:01 -05:00
Marc Kleine-Budde
3f548f90a0 treewide: remove executable bit from config files and c-code
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2018-01-17 10:45:25 -05:00
Stefan Berger
e5477e193f swtpm_setup: fix typo in help screen
--no-overwrite -> --not-overwrite

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-12 09:48:40 -05:00
Stefan Berger
be5557f3ff swtpm_cert: Sign cert using SHA256
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-02 09:41:34 -05:00
Stefan Berger
a8bc74fd01 swtpm_setup: Only pass through vmid parameter if it was set
Only pass through the vmid parameter to the tool creating the cert
if this parameter was set. The tool creating the cert may require
it or ignore it and is supposed to be able to track certificates
for which it minted certs using this parameter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-20 20:18:54 -05:00
Stefan Berger
5b1090a583 swtpm_cert: Fix broken certificate verification
The certificate chain could not be verified due to a wrong
API call for getting the authority key id where the key id
was gotten instead.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-20 11:12:15 -05:00
Stefan Berger
8e9edf696a swtpm: reformat iovec and initialize input variable with zeros
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-10 11:28:59 -05:00
Stefan Berger
7306ee278a swtpm: check for invalid file descriptor (< 0)
Check for an invalid file descriptor in SWTPM_IO_Read before accessing
it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-08 09:44:17 -05:00
Stefan Berger
a56a22540e swtpm_bios: only copy the size of the source string + 1 byte
Determine the size of the unix_path parameter and then only copy
those number of bytes + terminating null into the destination.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 19:53:41 -05:00
Stefan Berger
f42eec69f3 swtpm_ioctl: only copy the size of the source string + 1 byte
Determine the size of the unix_path parameter and then only copy
those number of bytes + terminating null into the destination.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 18:06:38 -05:00
Stefan Berger
3bb2b4675a swtpm_ioctl: check for filename and input NULL pointers
Check whether filename and input pointers are NULL pointers.
Per previous code this is currently not possibly but should
resolve some issues with Coverity.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 17:52:27 -05:00
Stefan Berger
5d62484fb7 swtpm_ioctl: in get_blobtype() check for blobtype NULL pointer
Check whether the passed blobtype is a NULL pointer

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 17:45:20 -05:00
Stefan Berger
aaab5d0b16 swtpm_bios: Coverity: use void * for the command
Use void * for the command rather than tpm_header *, which we do
not need. This addresses a few Coverity complaints.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 17:06:00 -05:00
Stefan Berger
4f4f2f0a7e swtpm: Remove usage of TPMVersion enum
To allow it to compile with libtpms's master, remove the usage of
TPMLIB_TPMVersion type.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-05 12:50:21 -05:00
Stefan Berger
182fbb20d6 swtpm_ioctl: explicitly check for numbytes < 0
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-05 12:45:31 -05:00
Stefan Berger
6c441a5272 swtpm: Do not pass a negative file descriptor
Do not a pass a negative file descriptor to getsockopt(). This fixes
a Coverity issue.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-21 12:45:53 -05:00
Stefan Berger
3ca520fd1c swtpm_ioctl: print error message in case setting state blob fails
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-13 20:44:08 -05:00
Stefan Berger
e396140204 swtpm: log when the decryption of a state blob fails
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-13 20:43:11 -05:00
Stefan Berger
cf47149f88 swtpm: log when the decryption of the NVRAM file fails
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-13 19:35:23 -05:00
Stefan Berger
3760c34251 swtpm: Add truncate parameter for --log option
Enable the resetting of the log using a truncate parameter for the
--log option.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-11 14:47:27 -05:00
Stefan Berger
41deaf616e swtpm: always set the logging file descriptor on libtpms
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-11 14:24:12 -05:00
Stefan Berger
addf7c5e45 swtpm: Also log the control channel exchanges
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 21:48:17 -05:00
Stefan Berger
ccd1aeb15b swtpm: also log control channel commands 2017-11-10 21:32:44 -05:00
Stefan Berger
60afebf116 swtpm: Log an error if data encryption failed
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 19:04:57 -05:00
Stefan Berger
73fb0412ea swtpm: Remove file if errors occured writing it
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 19:04:57 -05:00
Stefan Berger
f1389afb87 swtpm: Move debugging output into own function
Move some of the debugging output into its own function and
differentiate output by TPM Version number.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 18:55:54 -05:00
Stefan Berger
eff9cc1672 swtpm_setup: Add options to overwrite or not overwrite TPM state
Add options --overwrite and --not-overwrite to allow or prevent
overwriting of existing TPM state. If neiter of the options is
given and existing state is found, an error is returned.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-09 10:54:07 -05:00
Stefan Berger
38304e9c81 swtpm: remove debug include file
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-05 15:38:13 -05:00
Stefan Berger
688c8e2400 swtpm: Implemented support for PTM_SET_BUFFERSIZE command
Implement a command for setting and querying the buffer size the
TPM implementation (libtpms) is using. The setting of the
buffersize allows to reduce the size of the buffer to a size
that the interface can support so that these two sizes match
and the TPM will not produce larger responses than what the
interface can support.

Extend swtpm_ioctl with an option to set the buffersize.

Adapt the existing tests to reflect the newly supported command.
Implement a new test for getting/setting of the buffer size.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-05 14:53:00 -05:00
Stefan Berger
ca7f7a4006 swtpm: fix segfault introduced in aa3999
Changeset aa3999 introduced a segfault when calling
ctrlchannel_set_client_fd() with a NULL pointer. Like all the other
functions, we return with -1 in this case.

Since the segfault occurred on process shutdown no problems were
noticeable through bad test results or so.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-30 12:02:56 -04:00
Stefan Berger
061f9dce5e swtpm: Install SIGPIPE signal handler to ignore signal
Install a SIGPIPE signal handler to ignore the signal from trying
to write to a broken pipe.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-27 08:37:40 -04:00
Stefan Berger
e09966f603 swtpm_setup: Fix a couple of typos
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-27 08:37:40 -04:00
Stefan Berger
298d17822c swtpm: clean up server and ctrlchannel at the end
Introduce another parameter to ctrlchannel_new and server_new
to pass the Unix socket's path. Implement ctrlchannel_free and
server_free to clean up and remove the Unix socket's path.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
aa3999d387 swtpm: Implement ctrlchannel_set_client_fd()
Implement ctrlchannel_set_client_fd() to set a new client
fd and return its current value.

Use this new function to set the file descriptor to -1 upon
closing its associate file descriptor in the main loop.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
75f9f0d300 swtpm: Implement server_set_fd()
Implement server_set_fd() function to get the current file descriptor
and set a new one on the server structure.

Use this function to transfer the server file descriptor from the
server structure to the mainloop structure and have the main loop
close the file descriptor.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
fa3d8e4910 swtpm_ioctl: Display error in case of read() returns < 0
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
6ee0bd79d7 swtpm: Fix header inclusion for OpenBSD
Signed-off-by: Stefan Berger <stefanb@linx.vnet.ibm.com>
2017-10-12 13:07:46 -04:00