Blame SOURCES/kvm-virtiofsd-introduce-inode-refcount-to-prevent-use-af.patch

902636
From da6ee5c24397d2ca93dfaf275fdd9dafc922da15 Mon Sep 17 00:00:00 2001
902636
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
902636
Date: Mon, 27 Jan 2020 19:02:11 +0100
902636
Subject: [PATCH 100/116] virtiofsd: introduce inode refcount to prevent
902636
 use-after-free
902636
MIME-Version: 1.0
902636
Content-Type: text/plain; charset=UTF-8
902636
Content-Transfer-Encoding: 8bit
902636
902636
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
902636
Message-id: <20200127190227.40942-97-dgilbert@redhat.com>
902636
Patchwork-id: 93550
902636
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 096/112] virtiofsd: introduce inode refcount to prevent use-after-free
902636
Bugzilla: 1694164
902636
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
902636
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
902636
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
902636
902636
From: Stefan Hajnoczi <stefanha@redhat.com>
902636
902636
If thread A is using an inode it must not be deleted by thread B when
902636
processing a FUSE_FORGET request.
902636
902636
The FUSE protocol itself already has a counter called nlookup that is
902636
used in FUSE_FORGET messages.  We cannot trust this counter since the
902636
untrusted client can manipulate it via FUSE_FORGET messages.
902636
902636
Introduce a new refcount to keep inodes alive for the required lifespan.
902636
lo_inode_put() must be called to release a reference.  FUSE's nlookup
902636
counter holds exactly one reference so that the inode stays alive as
902636
long as the client still wants to remember it.
902636
902636
Note that the lo_inode->is_symlink field is moved to avoid creating a
902636
hole in the struct due to struct field alignment.
902636
902636
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
902636
Reviewed-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
902636
Reviewed-by: Sergio Lopez <slp@redhat.com>
902636
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
902636
(cherry picked from commit c241aa9457d88c6a0d027f48fadfed131646bce3)
902636
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
902636
---
902636
 tools/virtiofsd/passthrough_ll.c | 169 +++++++++++++++++++++++++++++++++------
902636
 1 file changed, 146 insertions(+), 23 deletions(-)
902636
902636
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
902636
index e3a6d6b..ab16135 100644
902636
--- a/tools/virtiofsd/passthrough_ll.c
902636
+++ b/tools/virtiofsd/passthrough_ll.c
902636
@@ -97,7 +97,13 @@ struct lo_key {
902636
 
902636
 struct lo_inode {
902636
     int fd;
902636
-    bool is_symlink;
902636
+
902636
+    /*
902636
+     * Atomic reference count for this object.  The nlookup field holds a
902636
+     * reference and release it when nlookup reaches 0.
902636
+     */
902636
+    gint refcount;
902636
+
902636
     struct lo_key key;
902636
 
902636
     /*
902636
@@ -116,6 +122,8 @@ struct lo_inode {
902636
     fuse_ino_t fuse_ino;
902636
     pthread_mutex_t plock_mutex;
902636
     GHashTable *posix_locks; /* protected by lo_inode->plock_mutex */
902636
+
902636
+    bool is_symlink;
902636
 };
902636
 
902636
 struct lo_cred {
902636
@@ -471,6 +479,23 @@ static ssize_t lo_add_inode_mapping(fuse_req_t req, struct lo_inode *inode)
902636
     return elem - lo_data(req)->ino_map.elems;
902636
 }
902636
 
902636
+static void lo_inode_put(struct lo_data *lo, struct lo_inode **inodep)
902636
+{
902636
+    struct lo_inode *inode = *inodep;
902636
+
902636
+    if (!inode) {
902636
+        return;
902636
+    }
902636
+
902636
+    *inodep = NULL;
902636
+
902636
+    if (g_atomic_int_dec_and_test(&inode->refcount)) {
902636
+        close(inode->fd);
902636
+        free(inode);
902636
+    }
902636
+}
902636
+
902636
+/* Caller must release refcount using lo_inode_put() */
902636
 static struct lo_inode *lo_inode(fuse_req_t req, fuse_ino_t ino)
902636
 {
902636
     struct lo_data *lo = lo_data(req);
902636
@@ -478,6 +503,9 @@ static struct lo_inode *lo_inode(fuse_req_t req, fuse_ino_t ino)
902636
 
902636
     pthread_mutex_lock(&lo->mutex);
902636
     elem = lo_map_get(&lo->ino_map, ino);
902636
+    if (elem) {
902636
+        g_atomic_int_inc(&elem->inode->refcount);
902636
+    }
902636
     pthread_mutex_unlock(&lo->mutex);
902636
 
902636
     if (!elem) {
902636
@@ -487,10 +515,23 @@ static struct lo_inode *lo_inode(fuse_req_t req, fuse_ino_t ino)
902636
     return elem->inode;
902636
 }
902636
 
902636
+/*
902636
+ * TODO Remove this helper and force callers to hold an inode refcount until
902636
+ * they are done with the fd.  This will be done in a later patch to make
902636
+ * review easier.
902636
+ */
902636
 static int lo_fd(fuse_req_t req, fuse_ino_t ino)
902636
 {
902636
     struct lo_inode *inode = lo_inode(req, ino);
902636
-    return inode ? inode->fd : -1;
902636
+    int fd;
902636
+
902636
+    if (!inode) {
902636
+        return -1;
902636
+    }
902636
+
902636
+    fd = inode->fd;
902636
+    lo_inode_put(lo_data(req), &inode;;
902636
+    return fd;
902636
 }
902636
 
902636
 static void lo_init(void *userdata, struct fuse_conn_info *conn)
902636
@@ -545,6 +586,10 @@ static void lo_getattr(fuse_req_t req, fuse_ino_t ino,
902636
     fuse_reply_attr(req, &buf, lo->timeout);
902636
 }
902636
 
902636
+/*
902636
+ * Increments parent->nlookup and caller must release refcount using
902636
+ * lo_inode_put(&parent).
902636
+ */
902636
 static int lo_parent_and_name(struct lo_data *lo, struct lo_inode *inode,
902636
                               char path[PATH_MAX], struct lo_inode **parent)
902636
 {
902636
@@ -582,6 +627,7 @@ retry:
902636
         p = &lo->root;
902636
         pthread_mutex_lock(&lo->mutex);
902636
         p->nlookup++;
902636
+        g_atomic_int_inc(&p->refcount);
902636
         pthread_mutex_unlock(&lo->mutex);
902636
     } else {
902636
         *last = '\0';
902636
@@ -625,6 +671,7 @@ retry:
902636
 
902636
 fail_unref:
902636
     unref_inode_lolocked(lo, p, 1);
902636
+    lo_inode_put(lo, &p);
902636
 fail:
902636
     if (retries) {
902636
         retries--;
902636
@@ -663,6 +710,7 @@ fallback:
902636
     if (res != -1) {
902636
         res = utimensat(parent->fd, path, tv, AT_SYMLINK_NOFOLLOW);
902636
         unref_inode_lolocked(lo, parent, 1);
902636
+        lo_inode_put(lo, &parent);
902636
     }
902636
 
902636
     return res;
902636
@@ -780,11 +828,13 @@ static void lo_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
902636
             goto out_err;
902636
         }
902636
     }
902636
+    lo_inode_put(lo, &inode;;
902636
 
902636
     return lo_getattr(req, ino, fi);
902636
 
902636
 out_err:
902636
     saverr = errno;
902636
+    lo_inode_put(lo, &inode;;
902636
     fuse_reply_err(req, saverr);
902636
 }
902636
 
902636
@@ -801,6 +851,7 @@ static struct lo_inode *lo_find(struct lo_data *lo, struct stat *st)
902636
     if (p) {
902636
         assert(p->nlookup > 0);
902636
         p->nlookup++;
902636
+        g_atomic_int_inc(&p->refcount);
902636
     }
902636
     pthread_mutex_unlock(&lo->mutex);
902636
 
902636
@@ -820,6 +871,10 @@ static void posix_locks_value_destroy(gpointer data)
902636
     free(plock);
902636
 }
902636
 
902636
+/*
902636
+ * Increments nlookup and caller must release refcount using
902636
+ * lo_inode_put(&parent).
902636
+ */
902636
 static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
902636
                         struct fuse_entry_param *e)
902636
 {
902636
@@ -827,7 +882,8 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
902636
     int res;
902636
     int saverr;
902636
     struct lo_data *lo = lo_data(req);
902636
-    struct lo_inode *inode, *dir = lo_inode(req, parent);
902636
+    struct lo_inode *inode = NULL;
902636
+    struct lo_inode *dir = lo_inode(req, parent);
902636
 
902636
     /*
902636
      * name_to_handle_at() and open_by_handle_at() can reach here with fuse
902636
@@ -868,6 +924,13 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
902636
         }
902636
 
902636
         inode->is_symlink = S_ISLNK(e->attr.st_mode);
902636
+
902636
+        /*
902636
+         * One for the caller and one for nlookup (released in
902636
+         * unref_inode_lolocked())
902636
+         */
902636
+        g_atomic_int_set(&inode->refcount, 2);
902636
+
902636
         inode->nlookup = 1;
902636
         inode->fd = newfd;
902636
         newfd = -1;
902636
@@ -883,6 +946,8 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
902636
         pthread_mutex_unlock(&lo->mutex);
902636
     }
902636
     e->ino = inode->fuse_ino;
902636
+    lo_inode_put(lo, &inode;;
902636
+    lo_inode_put(lo, &dir;;
902636
 
902636
     fuse_log(FUSE_LOG_DEBUG, "  %lli/%s -> %lli\n", (unsigned long long)parent,
902636
              name, (unsigned long long)e->ino);
902636
@@ -894,6 +959,8 @@ out_err:
902636
     if (newfd != -1) {
902636
         close(newfd);
902636
     }
902636
+    lo_inode_put(lo, &inode;;
902636
+    lo_inode_put(lo, &dir;;
902636
     return saverr;
902636
 }
902636
 
902636
@@ -991,6 +1058,7 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent,
902636
 {
902636
     int res;
902636
     int saverr;
902636
+    struct lo_data *lo = lo_data(req);
902636
     struct lo_inode *dir;
902636
     struct fuse_entry_param e;
902636
     struct lo_cred old = {};
902636
@@ -1032,9 +1100,11 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent,
902636
              name, (unsigned long long)e.ino);
902636
 
902636
     fuse_reply_entry(req, &e);
902636
+    lo_inode_put(lo, &dir;;
902636
     return;
902636
 
902636
 out:
902636
+    lo_inode_put(lo, &dir;;
902636
     fuse_reply_err(req, saverr);
902636
 }
902636
 
902636
@@ -1085,6 +1155,7 @@ fallback:
902636
     if (res != -1) {
902636
         res = linkat(parent->fd, path, dfd, name, 0);
902636
         unref_inode_lolocked(lo, parent, 1);
902636
+        lo_inode_put(lo, &parent);
902636
     }
902636
 
902636
     return res;
902636
@@ -1095,6 +1166,7 @@ static void lo_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t parent,
902636
 {
902636
     int res;
902636
     struct lo_data *lo = lo_data(req);
902636
+    struct lo_inode *parent_inode;
902636
     struct lo_inode *inode;
902636
     struct fuse_entry_param e;
902636
     int saverr;
902636
@@ -1104,17 +1176,18 @@ static void lo_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t parent,
902636
         return;
902636
     }
902636
 
902636
+    parent_inode = lo_inode(req, parent);
902636
     inode = lo_inode(req, ino);
902636
-    if (!inode) {
902636
-        fuse_reply_err(req, EBADF);
902636
-        return;
902636
+    if (!parent_inode || !inode) {
902636
+        errno = EBADF;
902636
+        goto out_err;
902636
     }
902636
 
902636
     memset(&e, 0, sizeof(struct fuse_entry_param));
902636
     e.attr_timeout = lo->timeout;
902636
     e.entry_timeout = lo->timeout;
902636
 
902636
-    res = linkat_empty_nofollow(lo, inode, lo_fd(req, parent), name);
902636
+    res = linkat_empty_nofollow(lo, inode, parent_inode->fd, name);
902636
     if (res == -1) {
902636
         goto out_err;
902636
     }
902636
@@ -1133,13 +1206,18 @@ static void lo_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t parent,
902636
              name, (unsigned long long)e.ino);
902636
 
902636
     fuse_reply_entry(req, &e);
902636
+    lo_inode_put(lo, &parent_inode);
902636
+    lo_inode_put(lo, &inode;;
902636
     return;
902636
 
902636
 out_err:
902636
     saverr = errno;
902636
+    lo_inode_put(lo, &parent_inode);
902636
+    lo_inode_put(lo, &inode;;
902636
     fuse_reply_err(req, saverr);
902636
 }
902636
 
902636
+/* Increments nlookup and caller must release refcount using lo_inode_put() */
902636
 static struct lo_inode *lookup_name(fuse_req_t req, fuse_ino_t parent,
902636
                                     const char *name)
902636
 {
902636
@@ -1176,6 +1254,7 @@ static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name)
902636
 
902636
     fuse_reply_err(req, res == -1 ? errno : 0);
902636
     unref_inode_lolocked(lo, inode, 1);
902636
+    lo_inode_put(lo, &inode;;
902636
 }
902636
 
902636
 static void lo_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
902636
@@ -1183,8 +1262,10 @@ static void lo_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
902636
                       unsigned int flags)
902636
 {
902636
     int res;
902636
-    struct lo_inode *oldinode;
902636
-    struct lo_inode *newinode;
902636
+    struct lo_inode *parent_inode;
902636
+    struct lo_inode *newparent_inode;
902636
+    struct lo_inode *oldinode = NULL;
902636
+    struct lo_inode *newinode = NULL;
902636
     struct lo_data *lo = lo_data(req);
902636
 
902636
     if (!is_safe_path_component(name) || !is_safe_path_component(newname)) {
902636
@@ -1192,6 +1273,13 @@ static void lo_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
902636
         return;
902636
     }
902636
 
902636
+    parent_inode = lo_inode(req, parent);
902636
+    newparent_inode = lo_inode(req, newparent);
902636
+    if (!parent_inode || !newparent_inode) {
902636
+        fuse_reply_err(req, EBADF);
902636
+        goto out;
902636
+    }
902636
+
902636
     oldinode = lookup_name(req, parent, name);
902636
     newinode = lookup_name(req, newparent, newname);
902636
 
902636
@@ -1204,8 +1292,8 @@ static void lo_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
902636
 #ifndef SYS_renameat2
902636
         fuse_reply_err(req, EINVAL);
902636
 #else
902636
-        res = syscall(SYS_renameat2, lo_fd(req, parent), name,
902636
-                       lo_fd(req, newparent), newname, flags);
902636
+        res = syscall(SYS_renameat2, parent_inode->fd, name,
902636
+                        newparent_inode->fd, newname, flags);
902636
         if (res == -1 && errno == ENOSYS) {
902636
             fuse_reply_err(req, EINVAL);
902636
         } else {
902636
@@ -1215,12 +1303,16 @@ static void lo_rename(fuse_req_t req, fuse_ino_t parent, const char *name,
902636
         goto out;
902636
     }
902636
 
902636
-    res = renameat(lo_fd(req, parent), name, lo_fd(req, newparent), newname);
902636
+    res = renameat(parent_inode->fd, name, newparent_inode->fd, newname);
902636
 
902636
     fuse_reply_err(req, res == -1 ? errno : 0);
902636
 out:
902636
     unref_inode_lolocked(lo, oldinode, 1);
902636
     unref_inode_lolocked(lo, newinode, 1);
902636
+    lo_inode_put(lo, &oldinode);
902636
+    lo_inode_put(lo, &newinode);
902636
+    lo_inode_put(lo, &parent_inode);
902636
+    lo_inode_put(lo, &newparent_inode);
902636
 }
902636
 
902636
 static void lo_unlink(fuse_req_t req, fuse_ino_t parent, const char *name)
902636
@@ -1244,6 +1336,7 @@ static void lo_unlink(fuse_req_t req, fuse_ino_t parent, const char *name)
902636
 
902636
     fuse_reply_err(req, res == -1 ? errno : 0);
902636
     unref_inode_lolocked(lo, inode, 1);
902636
+    lo_inode_put(lo, &inode;;
902636
 }
902636
 
902636
 static void unref_inode_lolocked(struct lo_data *lo, struct lo_inode *inode,
902636
@@ -1265,8 +1358,9 @@ static void unref_inode_lolocked(struct lo_data *lo, struct lo_inode *inode,
902636
         g_hash_table_destroy(inode->posix_locks);
902636
         pthread_mutex_destroy(&inode->plock_mutex);
902636
         pthread_mutex_unlock(&lo->mutex);
902636
-        close(inode->fd);
902636
-        free(inode);
902636
+
902636
+        /* Drop our refcount from lo_do_lookup() */
902636
+        lo_inode_put(lo, &inode;;
902636
     } else {
902636
         pthread_mutex_unlock(&lo->mutex);
902636
     }
902636
@@ -1280,6 +1374,7 @@ static int unref_all_inodes_cb(gpointer key, gpointer value, gpointer user_data)
902636
     inode->nlookup = 0;
902636
     lo_map_remove(&lo->ino_map, inode->fuse_ino);
902636
     close(inode->fd);
902636
+    lo_inode_put(lo, &inode;; /* Drop our refcount from lo_do_lookup() */
902636
 
902636
     return TRUE;
902636
 }
902636
@@ -1306,6 +1401,7 @@ static void lo_forget_one(fuse_req_t req, fuse_ino_t ino, uint64_t nlookup)
902636
              (unsigned long long)nlookup);
902636
 
902636
     unref_inode_lolocked(lo, inode, nlookup);
902636
+    lo_inode_put(lo, &inode;;
902636
 }
902636
 
902636
 static void lo_forget(fuse_req_t req, fuse_ino_t ino, uint64_t nlookup)
902636
@@ -1537,6 +1633,7 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
902636
     err = 0;
902636
 error:
902636
     lo_dirp_put(&d);
902636
+    lo_inode_put(lo, &dinode);
902636
 
902636
     /*
902636
      * If there's an error, we can only signal it if we haven't stored
902636
@@ -1595,6 +1692,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
902636
 {
902636
     int fd;
902636
     struct lo_data *lo = lo_data(req);
902636
+    struct lo_inode *parent_inode;
902636
     struct fuse_entry_param e;
902636
     int err;
902636
     struct lo_cred old = {};
902636
@@ -1607,12 +1705,18 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
902636
         return;
902636
     }
902636
 
902636
+    parent_inode = lo_inode(req, parent);
902636
+    if (!parent_inode) {
902636
+        fuse_reply_err(req, EBADF);
902636
+        return;
902636
+    }
902636
+
902636
     err = lo_change_cred(req, &old;;
902636
     if (err) {
902636
         goto out;
902636
     }
902636
 
902636
-    fd = openat(lo_fd(req, parent), name, (fi->flags | O_CREAT) & ~O_NOFOLLOW,
902636
+    fd = openat(parent_inode->fd, name, (fi->flags | O_CREAT) & ~O_NOFOLLOW,
902636
                 mode);
902636
     err = fd == -1 ? errno : 0;
902636
     lo_restore_cred(&old;;
902636
@@ -1625,8 +1729,8 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
902636
         pthread_mutex_unlock(&lo->mutex);
902636
         if (fh == -1) {
902636
             close(fd);
902636
-            fuse_reply_err(req, ENOMEM);
902636
-            return;
902636
+            err = ENOMEM;
902636
+            goto out;
902636
         }
902636
 
902636
         fi->fh = fh;
902636
@@ -1639,6 +1743,8 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
902636
     }
902636
 
902636
 out:
902636
+    lo_inode_put(lo, &parent_inode);
902636
+
902636
     if (err) {
902636
         fuse_reply_err(req, err);
902636
     } else {
902636
@@ -1712,16 +1818,18 @@ static void lo_getlk(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
902636
     plock =
902636
         lookup_create_plock_ctx(lo, inode, fi->lock_owner, lock->l_pid, &ret;;
902636
     if (!plock) {
902636
-        pthread_mutex_unlock(&inode->plock_mutex);
902636
-        fuse_reply_err(req, ret);
902636
-        return;
902636
+        saverr = ret;
902636
+        goto out;
902636
     }
902636
 
902636
     ret = fcntl(plock->fd, F_OFD_GETLK, lock);
902636
     if (ret == -1) {
902636
         saverr = errno;
902636
     }
902636
+
902636
+out:
902636
     pthread_mutex_unlock(&inode->plock_mutex);
902636
+    lo_inode_put(lo, &inode;;
902636
 
902636
     if (saverr) {
902636
         fuse_reply_err(req, saverr);
902636
@@ -1761,9 +1869,8 @@ static void lo_setlk(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
902636
         lookup_create_plock_ctx(lo, inode, fi->lock_owner, lock->l_pid, &ret;;
902636
 
902636
     if (!plock) {
902636
-        pthread_mutex_unlock(&inode->plock_mutex);
902636
-        fuse_reply_err(req, ret);
902636
-        return;
902636
+        saverr = ret;
902636
+        goto out;
902636
     }
902636
 
902636
     /* TODO: Is it alright to modify flock? */
902636
@@ -1772,7 +1879,11 @@ static void lo_setlk(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
902636
     if (ret == -1) {
902636
         saverr = errno;
902636
     }
902636
+
902636
+out:
902636
     pthread_mutex_unlock(&inode->plock_mutex);
902636
+    lo_inode_put(lo, &inode;;
902636
+
902636
     fuse_reply_err(req, saverr);
902636
 }
902636
 
902636
@@ -1898,6 +2009,7 @@ static void lo_flush(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
902636
     pthread_mutex_unlock(&inode->plock_mutex);
902636
 
902636
     res = close(dup(lo_fi_fd(req, fi)));
902636
+    lo_inode_put(lo_data(req), &inode;;
902636
     fuse_reply_err(req, res == -1 ? errno : 0);
902636
 }
902636
 
902636
@@ -2115,11 +2227,14 @@ out_free:
902636
     if (fd >= 0) {
902636
         close(fd);
902636
     }
902636
+
902636
+    lo_inode_put(lo, &inode;;
902636
     return;
902636
 
902636
 out_err:
902636
     saverr = errno;
902636
 out:
902636
+    lo_inode_put(lo, &inode;;
902636
     fuse_reply_err(req, saverr);
902636
     goto out_free;
902636
 }
902636
@@ -2190,11 +2305,14 @@ out_free:
902636
     if (fd >= 0) {
902636
         close(fd);
902636
     }
902636
+
902636
+    lo_inode_put(lo, &inode;;
902636
     return;
902636
 
902636
 out_err:
902636
     saverr = errno;
902636
 out:
902636
+    lo_inode_put(lo, &inode;;
902636
     fuse_reply_err(req, saverr);
902636
     goto out_free;
902636
 }
902636
@@ -2243,6 +2361,8 @@ out:
902636
     if (fd >= 0) {
902636
         close(fd);
902636
     }
902636
+
902636
+    lo_inode_put(lo, &inode;;
902636
     fuse_reply_err(req, saverr);
902636
 }
902636
 
902636
@@ -2289,6 +2409,8 @@ out:
902636
     if (fd >= 0) {
902636
         close(fd);
902636
     }
902636
+
902636
+    lo_inode_put(lo, &inode;;
902636
     fuse_reply_err(req, saverr);
902636
 }
902636
 
902636
@@ -2671,6 +2793,7 @@ static void setup_root(struct lo_data *lo, struct lo_inode *root)
902636
     root->key.ino = stat.st_ino;
902636
     root->key.dev = stat.st_dev;
902636
     root->nlookup = 2;
902636
+    g_atomic_int_set(&root->refcount, 2);
902636
 }
902636
 
902636
 static guint lo_key_hash(gconstpointer key)
902636
-- 
902636
1.8.3.1
902636