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