thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-virtiofsd-fail-when-parent-inode-isn-t-known-in-lo_d.patch

ddf19c
From b3cd18ab58e331d3610cf00f857d6a945f11a030 Mon Sep 17 00:00:00 2001
ddf19c
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
ddf19c
Date: Mon, 27 Jan 2020 19:01:49 +0100
ddf19c
Subject: [PATCH 078/116] virtiofsd: fail when parent inode isn't known in
ddf19c
 lo_do_lookup()
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-75-dgilbert@redhat.com>
ddf19c
Patchwork-id: 93529
ddf19c
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 074/112] virtiofsd: fail when parent inode isn't known in lo_do_lookup()
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
The Linux file handle APIs (struct export_operations) can access inodes
ddf19c
that are not attached to parents because path name traversal is not
ddf19c
performed.  Refuse if there is no parent in lo_do_lookup().
ddf19c
ddf19c
Also clean up lo_do_lookup() while we're here.
ddf19c
ddf19c
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
ddf19c
Signed-off-by: Stefan Hajnoczi <stefanha@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 9de4fab5995d115f8ebfb41d8d94a866d80a1708)
ddf19c
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ddf19c
---
ddf19c
 tools/virtiofsd/passthrough_ll.c | 14 ++++++++++++--
ddf19c
 1 file changed, 12 insertions(+), 2 deletions(-)
ddf19c
ddf19c
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
ddf19c
index de12e75..33bfb4d 100644
ddf19c
--- a/tools/virtiofsd/passthrough_ll.c
ddf19c
+++ b/tools/virtiofsd/passthrough_ll.c
ddf19c
@@ -777,6 +777,15 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
ddf19c
     struct lo_data *lo = lo_data(req);
ddf19c
     struct lo_inode *inode, *dir = lo_inode(req, parent);
ddf19c
 
ddf19c
+    /*
ddf19c
+     * name_to_handle_at() and open_by_handle_at() can reach here with fuse
ddf19c
+     * mount point in guest, but we don't have its inode info in the
ddf19c
+     * ino_map.
ddf19c
+     */
ddf19c
+    if (!dir) {
ddf19c
+        return ENOENT;
ddf19c
+    }
ddf19c
+
ddf19c
     memset(e, 0, sizeof(*e));
ddf19c
     e->attr_timeout = lo->timeout;
ddf19c
     e->entry_timeout = lo->timeout;
ddf19c
@@ -786,7 +795,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
ddf19c
         name = ".";
ddf19c
     }
ddf19c
 
ddf19c
-    newfd = openat(lo_fd(req, parent), name, O_PATH | O_NOFOLLOW);
ddf19c
+    newfd = openat(dir->fd, name, O_PATH | O_NOFOLLOW);
ddf19c
     if (newfd == -1) {
ddf19c
         goto out_err;
ddf19c
     }
ddf19c
@@ -796,7 +805,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
ddf19c
         goto out_err;
ddf19c
     }
ddf19c
 
ddf19c
-    inode = lo_find(lo_data(req), &e->attr);
ddf19c
+    inode = lo_find(lo, &e->attr);
ddf19c
     if (inode) {
ddf19c
         close(newfd);
ddf19c
         newfd = -1;
ddf19c
@@ -812,6 +821,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
ddf19c
         inode->is_symlink = S_ISLNK(e->attr.st_mode);
ddf19c
         inode->refcount = 1;
ddf19c
         inode->fd = newfd;
ddf19c
+        newfd = -1;
ddf19c
         inode->ino = e->attr.st_ino;
ddf19c
         inode->dev = e->attr.st_dev;
ddf19c
 
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c