yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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