yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
ddf19c
From 5e33269d5fbc4ba4614bab4a6b9e0ef759bebcb7 Mon Sep 17 00:00:00 2001
ddf19c
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
ddf19c
Date: Mon, 27 Jan 2020 19:02:10 +0100
ddf19c
Subject: [PATCH 099/116] virtiofsd: passthrough_ll: fix refcounting on
ddf19c
 remove/rename
ddf19c
MIME-Version: 1.0
ddf19c
Content-Type: text/plain; charset=UTF-8
ddf19c
Content-Transfer-Encoding: 8bit
ddf19c
ddf19c
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
Message-id: <20200127190227.40942-96-dgilbert@redhat.com>
ddf19c
Patchwork-id: 93549
ddf19c
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 095/112] virtiofsd: passthrough_ll: fix refcounting on remove/rename
ddf19c
Bugzilla: 1694164
ddf19c
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
ddf19c
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
ddf19c
ddf19c
From: Miklos Szeredi <mszeredi@redhat.com>
ddf19c
ddf19c
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
ddf19c
Reviewed-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
ddf19c
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
(cherry picked from commit 9257e514d861afa759c36704e1904d43ca3fec88)
ddf19c
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ddf19c
---
ddf19c
 tools/virtiofsd/passthrough_ll.c | 50 +++++++++++++++++++++++++++++++++++++++-
ddf19c
 1 file changed, 49 insertions(+), 1 deletion(-)
ddf19c
ddf19c
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
ddf19c
index c819b5f..e3a6d6b 100644
ddf19c
--- a/tools/virtiofsd/passthrough_ll.c
ddf19c
+++ b/tools/virtiofsd/passthrough_ll.c
ddf19c
@@ -1140,17 +1140,42 @@ out_err:
ddf19c
     fuse_reply_err(req, saverr);
ddf19c
 }
ddf19c
 
ddf19c
+static struct lo_inode *lookup_name(fuse_req_t req, fuse_ino_t parent,
ddf19c
+                                    const char *name)
ddf19c
+{
ddf19c
+    int res;
ddf19c
+    struct stat attr;
ddf19c
+
ddf19c
+    res = fstatat(lo_fd(req, parent), name, &attr,
ddf19c
+                  AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
ddf19c
+    if (res == -1) {
ddf19c
+        return NULL;
ddf19c
+    }
ddf19c
+
ddf19c
+    return lo_find(lo_data(req), &attr);
ddf19c
+}
ddf19c
+
ddf19c
 static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name)
ddf19c
 {
ddf19c
     int res;
ddf19c
+    struct lo_inode *inode;
ddf19c
+    struct lo_data *lo = lo_data(req);
ddf19c
+
ddf19c
     if (!is_safe_path_component(name)) {
ddf19c
         fuse_reply_err(req, EINVAL);
ddf19c
         return;
ddf19c
     }
ddf19c
 
ddf19c
+    inode = lookup_name(req, parent, name);
ddf19c
+    if (!inode) {
ddf19c
+        fuse_reply_err(req, EIO);
ddf19c
+        return;
ddf19c
+    }
ddf19c
+
ddf19c
     res = unlinkat(lo_fd(req, parent), name, AT_REMOVEDIR);
ddf19c
 
ddf19c
     fuse_reply_err(req, res == -1 ? errno : 0);
ddf19c
+    unref_inode_lolocked(lo, inode, 1);
ddf19c
 }
ddf19c
 
ddf19c
 static void lo_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
ddf19c
@@ -1158,12 +1183,23 @@ static void lo_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
ddf19c
                       unsigned int flags)
ddf19c
 {
ddf19c
     int res;
ddf19c
+    struct lo_inode *oldinode;
ddf19c
+    struct lo_inode *newinode;
ddf19c
+    struct lo_data *lo = lo_data(req);
ddf19c
 
ddf19c
     if (!is_safe_path_component(name) || !is_safe_path_component(newname)) {
ddf19c
         fuse_reply_err(req, EINVAL);
ddf19c
         return;
ddf19c
     }
ddf19c
 
ddf19c
+    oldinode = lookup_name(req, parent, name);
ddf19c
+    newinode = lookup_name(req, newparent, newname);
ddf19c
+
ddf19c
+    if (!oldinode) {
ddf19c
+        fuse_reply_err(req, EIO);
ddf19c
+        goto out;
ddf19c
+    }
ddf19c
+
ddf19c
     if (flags) {
ddf19c
 #ifndef SYS_renameat2
ddf19c
         fuse_reply_err(req, EINVAL);
ddf19c
@@ -1176,26 +1212,38 @@ static void lo_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
ddf19c
             fuse_reply_err(req, res == -1 ? errno : 0);
ddf19c
         }
ddf19c
 #endif
ddf19c
-        return;
ddf19c
+        goto out;
ddf19c
     }
ddf19c
 
ddf19c
     res = renameat(lo_fd(req, parent), name, lo_fd(req, newparent), newname);
ddf19c
 
ddf19c
     fuse_reply_err(req, res == -1 ? errno : 0);
ddf19c
+out:
ddf19c
+    unref_inode_lolocked(lo, oldinode, 1);
ddf19c
+    unref_inode_lolocked(lo, newinode, 1);
ddf19c
 }
ddf19c
 
ddf19c
 static void lo_unlink(fuse_req_t req, fuse_ino_t parent, const char *name)
ddf19c
 {
ddf19c
     int res;
ddf19c
+    struct lo_inode *inode;
ddf19c
+    struct lo_data *lo = lo_data(req);
ddf19c
 
ddf19c
     if (!is_safe_path_component(name)) {
ddf19c
         fuse_reply_err(req, EINVAL);
ddf19c
         return;
ddf19c
     }
ddf19c
 
ddf19c
+    inode = lookup_name(req, parent, name);
ddf19c
+    if (!inode) {
ddf19c
+        fuse_reply_err(req, EIO);
ddf19c
+        return;
ddf19c
+    }
ddf19c
+
ddf19c
     res = unlinkat(lo_fd(req, parent), name, 0);
ddf19c
 
ddf19c
     fuse_reply_err(req, res == -1 ? errno : 0);
ddf19c
+    unref_inode_lolocked(lo, inode, 1);
ddf19c
 }
ddf19c
 
ddf19c
 static void unref_inode_lolocked(struct lo_data *lo, struct lo_inode *inode,
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c