yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
902636
From 8ce8ccc2a22798a89bac06a37427c3a3cea91a62 Mon Sep 17 00:00:00 2001
902636
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
902636
Date: Tue, 5 May 2020 16:35:54 +0100
902636
Subject: [PATCH 3/9] tools/virtiofsd/passthrough_ll: Fix double close()
902636
MIME-Version: 1.0
902636
Content-Type: text/plain; charset=UTF-8
902636
Content-Transfer-Encoding: 8bit
902636
902636
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
902636
Message-id: <20200505163600.22956-2-dgilbert@redhat.com>
902636
Patchwork-id: 96269
902636
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 1/7] tools/virtiofsd/passthrough_ll: Fix double close()
902636
Bugzilla: 1817445
902636
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
902636
RH-Acked-by: Max Reitz <mreitz@redhat.com>
902636
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
902636
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
902636
902636
From: Philippe Mathieu-Daudé <philmd@redhat.com>
902636
902636
On success, the fdopendir() call closes fd. Later on the error
902636
path we try to close an already-closed fd. This can lead to
902636
use-after-free. Fix by only closing the fd if the fdopendir()
902636
call failed.
902636
902636
Cc: qemu-stable@nongnu.org
902636
Fixes: b39bce121b (add dirp_map to hide lo_dirp pointers)
902636
Reported-by: Coverity (CID 1421933 USE_AFTER_FREE)
902636
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
902636
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
902636
Message-Id: <20200321120654.7985-1-philmd@redhat.com>
902636
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
902636
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
902636
(cherry picked from commit e1cd92d95cd4f97b3464c4e08cd5b22bf5ca05cb)
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 tools/virtiofsd/passthrough_ll.c | 3 +--
902636
 1 file changed, 1 insertion(+), 2 deletions(-)
902636
902636
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
902636
index 9cba3f1..50ff672 100644
902636
--- a/tools/virtiofsd/passthrough_ll.c
902636
+++ b/tools/virtiofsd/passthrough_ll.c
902636
@@ -1524,8 +1524,7 @@ out_err:
902636
     if (d) {
902636
         if (d->dp) {
902636
             closedir(d->dp);
902636
-        }
902636
-        if (fd != -1) {
902636
+        } else if (fd != -1) {
902636
             close(fd);
902636
         }
902636
         free(d);
902636
-- 
902636
1.8.3.1
902636