From: Miklos Szeredi <mszeredi@redhat.com>
To: fuse-devel@lists.linux.dev, virtualization@lists.linux.dev
Cc: Li Wang <liwang@kylinos.cn>,
German Maglione <gmaglione@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH v3 5/5] virtiofs: fix forget leak on submount unmount
Date: Tue, 1 Dec 2026 11:58:53 +0100 [thread overview]
Message-ID: <20261201105855.430993-5-mszeredi@redhat.com> (raw)
In-Reply-To: <20261201105855.430993-1-mszeredi@redhat.com>
generic_shutdown_super() clears SB_ACTIVE before calling evict_inodes(),
so fuse_evict_inode() skipped both the FUSE_FORGET for fi->nlookup and
fuse_cleanup_submount_lookup() for every remaining inode.
For a full unmount that is mostly fine: FUSE_DESTROY has already told the
server to drop everything. But a submount unmount takes the same path
with the connection still alive: fuse_mount_remove() returns false, so
fuse_conn_destroy() is not called and no FUSE_DESTROY is sent. The
server then keeps the lookup count of every inode of the submount for the
lifetime of the connection, which can be arbitrarily long if the parent
mount stays around and submounts come and go.
fuse_submount_lookup is worse, because it is freed nowhere else: the
object and its embedded forget are leaked on any unmount, including a
full one, for every inode that has one.
Queue both regardless of SB_ACTIVE. On a full unmount, and on an aborted
connection, fuse_conn_destroy() has disconnected the input queue before
inodes are evicted, so both fuse_dev_queue_forget() and
virtio_fs_send_forget() just free the link; fc->chan stays valid until
fuse_free_conn(), well after evict_inodes().
A failed mount is different: sb->s_root is NULL, so fuse_sb_destroy()
never calls fuse_conn_destroy() and the input queue stays connected.
Anything queued on it would be leaked, as the forget list is drained
only by fuse_chan_abort(). Nothing is queued there, though: the only
inode such a mount evicts is the root, which has no submount lookup and,
since commit d34e012c92a4 ("fuse: don't take a lookup count on the root
inode"), no lookup count either. That commit is a prerequisite for this
one.
Fixes: c4d361f66ac9 ("fuse: share lookup state between submount and its parent")
Cc: <stable@vger.kernel.org> # 8ebc672894c3: fuse: don't take a lookup count on the root inode
Cc: <stable@vger.kernel.org>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
fs/fuse/inode.c | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 7849cbbdcab6..a69d6a7701ac 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -141,6 +141,7 @@ static void fuse_cleanup_submount_lookup(struct fuse_conn *fc,
static void fuse_evict_inode(struct inode *inode)
{
struct fuse_inode *fi = get_fuse_inode(inode);
+ struct fuse_conn *fc = get_fuse_conn(inode);
/* Will write inode on close/munmap and in all other dirtiers */
WARN_ON(inode_state_read_once(inode) & I_DIRTY_INODE);
@@ -157,19 +158,30 @@ static void fuse_evict_inode(struct inode *inode)
*/
if (FUSE_IS_VDAX(inode))
fuse_vdax_inode_cleanup(inode);
- if (inode->i_sb->s_flags & SB_ACTIVE) {
- struct fuse_conn *fc = get_fuse_conn(inode);
+ /*
+ * Must be done unconditionally as well: on a submount unmount the
+ * connection stays alive and no FUSE_DESTROY is sent, so without
+ * this the server keeps the lookup counts of every inode in the
+ * submount for the lifetime of the connection. The
+ * fuse_submount_lookup object is freed nowhere else, so skipping it
+ * leaks that too. On a full unmount or an aborted connection the
+ * input queue is already disconnected, so fuse_chan_queue_forget()
+ * just frees the forget. A failed mount does not disconnect the
+ * queue, but the only inode it evicts is the root, which carries
+ * neither a lookup count nor a submount lookup.
+ */
+ if (fi->nlookup) {
+ fuse_chan_queue_forget(fc->chan, fi->forget, fi->nodeid,
+ fi->nlookup);
+ fi->forget = NULL;
+ }
- if (fi->nlookup) {
- fuse_chan_queue_forget(fc->chan, fi->forget, fi->nodeid,
- fi->nlookup);
- fi->forget = NULL;
- }
+ if (fi->submount_lookup) {
+ fuse_cleanup_submount_lookup(fc, fi->submount_lookup);
+ fi->submount_lookup = NULL;
+ }
- if (fi->submount_lookup) {
- fuse_cleanup_submount_lookup(fc, fi->submount_lookup);
- fi->submount_lookup = NULL;
- }
+ if (inode->i_sb->s_flags & SB_ACTIVE) {
/*
* Evict of non-deleted inode may race with outstanding
* LOOKUP/READDIRPLUS requests and result in inconsistency when
--
2.56.1
next prev parent reply other threads:[~2026-12-01 10:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 10:58 [PATCH v3 1/5] virtiofs: fix DAX range leak on unmount Miklos Szeredi
2026-12-01 10:58 ` [PATCH v3 2/5] virtiofs: don't abort DAX removemapping on allocation failure Miklos Szeredi
2026-12-01 15:18 ` German Maglione
2026-12-01 10:58 ` [PATCH v3 3/5] virtiofs: retry request submission from the worker on -ENOMEM Miklos Szeredi
2026-12-01 11:05 ` sashiko-bot
2026-12-01 15:18 ` German Maglione
2026-12-01 10:58 ` [PATCH v3 4/5] fuse: don't take a lookup count on the root inode Miklos Szeredi
2026-12-01 15:18 ` German Maglione
2026-12-02 3:50 ` Li Wang
2026-12-01 10:58 ` Miklos Szeredi [this message]
2026-12-01 13:23 ` [PATCH v3 5/5] virtiofs: fix forget leak on submount unmount Li Wang
2026-12-01 15:18 ` German Maglione
2026-12-01 11:11 ` [PATCH v3 1/5] virtiofs: fix DAX range leak on unmount sashiko-bot
2026-12-01 15:18 ` German Maglione
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201105855.430993-5-mszeredi@redhat.com \
--to=mszeredi@redhat.com \
--cc=fuse-devel@lists.linux.dev \
--cc=gmaglione@redhat.com \
--cc=liwang@kylinos.cn \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox