[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[qemu-xen staging-4.19] tpm: fix crash when FD >= 1024 and unnecessary errors due to EINTR



commit fcf58d6f20d29ee250f542ac8de968700c957134
Author:     Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>
AuthorDate: Mon Sep 11 17:25:51 2023 +0400
Commit:     Michael Tokarev <mjt@xxxxxxxxxx>
CommitDate: Wed Sep 20 10:18:14 2023 +0300

    tpm: fix crash when FD >= 1024 and unnecessary errors due to EINTR
    
    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@xxxxxxxxxx
    Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2020133
    Fixes: 56a3c24ffc ("tpm: Probe for connected TPM 1.2 or TPM 2")
    Signed-off-by: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>
    Reviewed-by: Michael Tokarev <mjt@xxxxxxxxxx>
    Reviewed-by: Stefan Berger <stefanb@xxxxxxxxxxxxx>
    Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxxxxx>
    (cherry picked from commit 8e32ddff69b6b4547cc00592ad816484e160817a)
    Signed-off-by: Michael Tokarev <mjt@xxxxxxxxxx>
---
 backends/tpm/tpm_util.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/backends/tpm/tpm_util.c b/backends/tpm/tpm_util.c
index a6e6d3e72f..1856589c3b 100644
--- a/backends/tpm/tpm_util.c
+++ b/backends/tpm/tpm_util.c
@@ -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) {
@@ -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;
     }
--
generated by git-patchbot for /home/xen/git/qemu-xen.git#staging-4.19



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.