cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
22c213
From 4ebabb66f4132186152edf8e1907fce436bf5c69 Mon Sep 17 00:00:00 2001
22c213
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
22c213
Date: Mon, 27 Jan 2020 19:02:06 +0100
22c213
Subject: [PATCH 095/116] virtiofsd: make lo_release() atomic
22c213
MIME-Version: 1.0
22c213
Content-Type: text/plain; charset=UTF-8
22c213
Content-Transfer-Encoding: 8bit
22c213
22c213
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
Message-id: <20200127190227.40942-92-dgilbert@redhat.com>
22c213
Patchwork-id: 93545
22c213
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 091/112] virtiofsd: make lo_release() atomic
22c213
Bugzilla: 1694164
22c213
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
22c213
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
22c213
22c213
From: Stefan Hajnoczi <stefanha@redhat.com>
22c213
22c213
Hold the lock across both lo_map_get() and lo_map_remove() to prevent
22c213
races between two FUSE_RELEASE requests.  In this case I don't see a
22c213
serious bug but it's safer to do things atomically.
22c213
22c213
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
22c213
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
(cherry picked from commit baed65c060c0e524530bc243eec427fb408bd477)
22c213
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
22c213
---
22c213
 tools/virtiofsd/passthrough_ll.c | 12 ++++++++----
22c213
 1 file changed, 8 insertions(+), 4 deletions(-)
22c213
22c213
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
22c213
index 9414935..690edbc 100644
22c213
--- a/tools/virtiofsd/passthrough_ll.c
22c213
+++ b/tools/virtiofsd/passthrough_ll.c
22c213
@@ -1772,14 +1772,18 @@ static void lo_release(fuse_req_t req, fuse_ino_t ino,
22c213
                        struct fuse_file_info *fi)
22c213
 {
22c213
     struct lo_data *lo = lo_data(req);
22c213
-    int fd;
22c213
+    struct lo_map_elem *elem;
22c213
+    int fd = -1;
22c213
 
22c213
     (void)ino;
22c213
 
22c213
-    fd = lo_fi_fd(req, fi);
22c213
-
22c213
     pthread_mutex_lock(&lo->mutex);
22c213
-    lo_map_remove(&lo->fd_map, fi->fh);
22c213
+    elem = lo_map_get(&lo->fd_map, fi->fh);
22c213
+    if (elem) {
22c213
+        fd = elem->fd;
22c213
+        elem = NULL;
22c213
+        lo_map_remove(&lo->fd_map, fi->fh);
22c213
+    }
22c213
     pthread_mutex_unlock(&lo->mutex);
22c213
 
22c213
     close(fd);
22c213
-- 
22c213
1.8.3.1
22c213