mirror of
https://github.com/stefanberger/swtpm.git
synced 2026-02-05 22:54:09 +00:00
swtpm: Have SWTPM_IO_Read read at least the 10 bytes from the TPM header
Have SWTPM_IO_Read() read at leat the 10 bytes from the (regular) TPM header. This solves a particular problem with the TPM 2 header prefix for which we will add support in the subsequent patch. In the prefix case the IBM TSS 2 stack sends 4 bytes for the command, then 1 byte for the locality, and then 4 bytes for the length indicator followed by the command. If we just read once we would only then get 4 bytes. Reading 10 bytes gets all of these plus the sub- sequent TPM command or the whole TPM command in case this prefix header is missing. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
parent
71beceeda4
commit
dc2895812a
@ -64,7 +64,7 @@
|
||||
#include "logging.h"
|
||||
#include "swtpm_debug.h"
|
||||
#include "swtpm_io.h"
|
||||
|
||||
#include "tpmlib.h"
|
||||
|
||||
/*
|
||||
global variables
|
||||
@ -90,6 +90,7 @@ TPM_RESULT SWTPM_IO_Read(TPM_CONNECTION_FD *connection_fd, /* read/write file
|
||||
size_t bufferSize) /* input: max size of output buffer */
|
||||
{
|
||||
ssize_t n;
|
||||
size_t offset = 0;
|
||||
|
||||
if (connection_fd->fd < 0) {
|
||||
TPM_DEBUG("SWTPM_IO_Read: Passed file descriptor is invalid\n");
|
||||
@ -97,17 +98,20 @@ TPM_RESULT SWTPM_IO_Read(TPM_CONNECTION_FD *connection_fd, /* read/write file
|
||||
}
|
||||
|
||||
while (true) {
|
||||
n = read(connection_fd->fd, buffer, bufferSize);
|
||||
n = read(connection_fd->fd, &buffer[offset], bufferSize - offset);
|
||||
if (n < 0 && errno == EINTR)
|
||||
continue;
|
||||
if (n > 0) {
|
||||
*bufferLength = n;
|
||||
offset += n;
|
||||
if (offset < sizeof(struct tpm_req_header))
|
||||
continue;
|
||||
break;
|
||||
} else {
|
||||
return TPM_IOERROR;
|
||||
}
|
||||
}
|
||||
|
||||
*bufferLength = offset;
|
||||
TPM_PrintAll(" SWTPM_IO_Read:", " ", buffer, *bufferLength);
|
||||
|
||||
return 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user