cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
ddf19c
From 97e232e75bbc0032f4a309d248f383384612eafe Mon Sep 17 00:00:00 2001
ddf19c
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
ddf19c
Date: Mon, 27 Jan 2020 19:01:25 +0100
ddf19c
Subject: [PATCH 054/116] virtiofsd: prevent ".." escape in lo_do_readdir()
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-51-dgilbert@redhat.com>
ddf19c
Patchwork-id: 93507
ddf19c
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 050/112] virtiofsd: prevent ".." escape in lo_do_readdir()
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: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
ddf19c
Construct a fake dirent for the root directory's ".." entry.  This hides
ddf19c
the parent directory from the FUSE client.
ddf19c
ddf19c
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
Reviewed-by: Sergio Lopez <slp@redhat.com>
ddf19c
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
(cherry picked from commit 752272da2b68a2312f0e11fc5303015a6c3ee1ac)
ddf19c
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ddf19c
---
ddf19c
 tools/virtiofsd/passthrough_ll.c | 36 ++++++++++++++++++++++--------------
ddf19c
 1 file changed, 22 insertions(+), 14 deletions(-)
ddf19c
ddf19c
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
ddf19c
index 79d5966..e3d65c3 100644
ddf19c
--- a/tools/virtiofsd/passthrough_ll.c
ddf19c
+++ b/tools/virtiofsd/passthrough_ll.c
ddf19c
@@ -1149,19 +1149,25 @@ out_err:
ddf19c
 static void lo_do_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
ddf19c
                           off_t offset, struct fuse_file_info *fi, int plus)
ddf19c
 {
ddf19c
+    struct lo_data *lo = lo_data(req);
ddf19c
     struct lo_dirp *d;
ddf19c
+    struct lo_inode *dinode;
ddf19c
     char *buf = NULL;
ddf19c
     char *p;
ddf19c
     size_t rem = size;
ddf19c
-    int err = ENOMEM;
ddf19c
+    int err = EBADF;
ddf19c
 
ddf19c
-    (void)ino;
ddf19c
+    dinode = lo_inode(req, ino);
ddf19c
+    if (!dinode) {
ddf19c
+        goto error;
ddf19c
+    }
ddf19c
 
ddf19c
     d = lo_dirp(req, fi);
ddf19c
     if (!d) {
ddf19c
         goto error;
ddf19c
     }
ddf19c
 
ddf19c
+    err = ENOMEM;
ddf19c
     buf = calloc(1, size);
ddf19c
     if (!buf) {
ddf19c
         goto error;
ddf19c
@@ -1192,15 +1198,21 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
ddf19c
         }
ddf19c
         nextoff = d->entry->d_off;
ddf19c
         name = d->entry->d_name;
ddf19c
+
ddf19c
         fuse_ino_t entry_ino = 0;
ddf19c
+        struct fuse_entry_param e = (struct fuse_entry_param){
ddf19c
+            .attr.st_ino = d->entry->d_ino,
ddf19c
+            .attr.st_mode = d->entry->d_type << 12,
ddf19c
+        };
ddf19c
+
ddf19c
+        /* Hide root's parent directory */
ddf19c
+        if (dinode == &lo->root && strcmp(name, "..") == 0) {
ddf19c
+            e.attr.st_ino = lo->root.ino;
ddf19c
+            e.attr.st_mode = DT_DIR << 12;
ddf19c
+        }
ddf19c
+
ddf19c
         if (plus) {
ddf19c
-            struct fuse_entry_param e;
ddf19c
-            if (is_dot_or_dotdot(name)) {
ddf19c
-                e = (struct fuse_entry_param){
ddf19c
-                    .attr.st_ino = d->entry->d_ino,
ddf19c
-                    .attr.st_mode = d->entry->d_type << 12,
ddf19c
-                };
ddf19c
-            } else {
ddf19c
+            if (!is_dot_or_dotdot(name)) {
ddf19c
                 err = lo_do_lookup(req, ino, name, &e);
ddf19c
                 if (err) {
ddf19c
                     goto error;
ddf19c
@@ -1210,11 +1222,7 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
ddf19c
 
ddf19c
             entsize = fuse_add_direntry_plus(req, p, rem, name, &e, nextoff);
ddf19c
         } else {
ddf19c
-            struct stat st = {
ddf19c
-                .st_ino = d->entry->d_ino,
ddf19c
-                .st_mode = d->entry->d_type << 12,
ddf19c
-            };
ddf19c
-            entsize = fuse_add_direntry(req, p, rem, name, &st, nextoff);
ddf19c
+            entsize = fuse_add_direntry(req, p, rem, name, &e.attr, nextoff);
ddf19c
         }
ddf19c
         if (entsize > rem) {
ddf19c
             if (entry_ino != 0) {
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c