Skip to content

Commit

Permalink
tpm: fix crash when FD >= 1024 and unnecessary errors due to EINTR
Browse files Browse the repository at this point in the history
Replace select() with poll() to fix a crash when QEMU has a large number
of FDs. Also use RETRY_ON_EINTR to avoid unnecessary errors due to EINTR.

Cc: qemu-stable@nongnu.org
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2020133
Fixes: 56a3c24 ("tpm: Probe for connected TPM 1.2 or TPM 2")
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
(cherry picked from commit 8e32ddf)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
  • Loading branch information
elmarco authored and Michael Tokarev committed Sep 13, 2023
1 parent bd1dd50 commit 64e355f
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions backends/tpm/tpm_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,8 @@ static int tpm_util_request(int fd,
void *response,
size_t responselen)
{
fd_set readfds;
GPollFD fds[1] = { {.fd = fd, .events = G_IO_IN } };
int n;
struct timeval tv = {
.tv_sec = 1,
.tv_usec = 0,
};

n = write(fd, request, requestlen);
if (n < 0) {
Expand All @@ -127,11 +123,8 @@ static int tpm_util_request(int fd,
return -EFAULT;
}

FD_ZERO(&readfds);
FD_SET(fd, &readfds);

/* wait for a second */
n = select(fd + 1, &readfds, NULL, NULL, &tv);
n = RETRY_ON_EINTR(g_poll(fds, 1, 1000));
if (n != 1) {
return -errno;
}
Expand Down

0 comments on commit 64e355f

Please sign in to comment.