dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0080-virtiofsd-fail-when-parent-inode-isn-t-known-in-lo_d.patch

1d442b
From: Miklos Szeredi <mszeredi@redhat.com>
1d442b
Date: Mon, 27 Jan 2020 19:01:49 +0000
1d442b
Subject: [PATCH] virtiofsd: fail when parent inode isn't known in
1d442b
 lo_do_lookup()
1d442b
1d442b
The Linux file handle APIs (struct export_operations) can access inodes
1d442b
that are not attached to parents because path name traversal is not
1d442b
performed.  Refuse if there is no parent in lo_do_lookup().
1d442b
1d442b
Also clean up lo_do_lookup() while we're here.
1d442b
1d442b
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1d442b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
1d442b
Reviewed-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
1d442b
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442b
(cherry picked from commit 9de4fab5995d115f8ebfb41d8d94a866d80a1708)
1d442b
---
1d442b
 tools/virtiofsd/passthrough_ll.c | 14 ++++++++++++--
1d442b
 1 file changed, 12 insertions(+), 2 deletions(-)
1d442b
1d442b
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
1d442b
index de12e75a9e..33bfb4d1f4 100644
1d442b
--- a/tools/virtiofsd/passthrough_ll.c
1d442b
+++ b/tools/virtiofsd/passthrough_ll.c
1d442b
@@ -777,6 +777,15 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
1d442b
     struct lo_data *lo = lo_data(req);
1d442b
     struct lo_inode *inode, *dir = lo_inode(req, parent);
1d442b
 
1d442b
+    /*
1d442b
+     * name_to_handle_at() and open_by_handle_at() can reach here with fuse
1d442b
+     * mount point in guest, but we don't have its inode info in the
1d442b
+     * ino_map.
1d442b
+     */
1d442b
+    if (!dir) {
1d442b
+        return ENOENT;
1d442b
+    }
1d442b
+
1d442b
     memset(e, 0, sizeof(*e));
1d442b
     e->attr_timeout = lo->timeout;
1d442b
     e->entry_timeout = lo->timeout;
1d442b
@@ -786,7 +795,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
1d442b
         name = ".";
1d442b
     }
1d442b
 
1d442b
-    newfd = openat(lo_fd(req, parent), name, O_PATH | O_NOFOLLOW);
1d442b
+    newfd = openat(dir->fd, name, O_PATH | O_NOFOLLOW);
1d442b
     if (newfd == -1) {
1d442b
         goto out_err;
1d442b
     }
1d442b
@@ -796,7 +805,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
1d442b
         goto out_err;
1d442b
     }
1d442b
 
1d442b
-    inode = lo_find(lo_data(req), &e->attr);
1d442b
+    inode = lo_find(lo, &e->attr);
1d442b
     if (inode) {
1d442b
         close(newfd);
1d442b
         newfd = -1;
1d442b
@@ -812,6 +821,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
1d442b
         inode->is_symlink = S_ISLNK(e->attr.st_mode);
1d442b
         inode->refcount = 1;
1d442b
         inode->fd = newfd;
1d442b
+        newfd = -1;
1d442b
         inode->ino = e->attr.st_ino;
1d442b
         inode->dev = e->attr.st_dev;
1d442b