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 5/5] virtiofs: fix forget leak on submount unmount
Date: Thu, 26 Nov 2026 15:47:18 +0100 [thread overview]
Message-ID: <20261126144719.232329-5-mszeredi@redhat.com> (raw)
In-Reply-To: <20261126144719.232329-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. This is safe on the paths where the
connection is already gone: both fuse_dev_queue_forget() and
virtio_fs_send_forget() just free the link when the queue is
disconnected, and fc->chan stays valid until fuse_free_conn(), well after
evict_inodes().
Fixes: c4d361f66ac9 ("fuse: share lookup state between submount and its parent")
Cc: <stable@vger.kernel.org>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
fs/fuse/inode.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 344fcb55a64b..81ee6c96203c 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,27 @@ 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. If the connection is already gone (full unmount,
+ * failed mount) fuse_chan_queue_forget() just frees the forget.
+ */
+ 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
prev parent reply other threads:[~2026-11-26 14:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 14:47 [PATCH 1/5] virtiofs: fix DAX range leak on unmount Miklos Szeredi
2026-11-26 14:47 ` [PATCH 2/5] virtiofs: don't abort DAX removemapping on allocation failure Miklos Szeredi
2026-11-26 14:47 ` [PATCH 3/5] virtiofs: retry request submission from the worker on -ENOMEM Miklos Szeredi
2026-11-26 14:47 ` [PATCH 4/5] virtiofs: abort the connection if the server fails to unmap a DAX range Miklos Szeredi
2026-11-26 14:47 ` Miklos Szeredi [this message]
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=20261126144719.232329-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