Blame SOURCES/kvm-virtiofsd-passthrough_ll-fix-refcounting-on-remove-r.patch

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