From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796122745; b=K9WVWBpVDAQ0XOxCCG2CWEfSZz+B9vDfGEmapQ2i1F4X1bSaGDWPctxcv2oo/c8Nkt/D BWNHewfab2eKCjpWUJdWNrZXBiv80e/OSHA7Or/tUTUC9VMH/pYbjgyB+ZFrPAK0MHHwR ngqALEHpWRF+1YpW191vMj+VDEJtIyeOFsDubKNeClnPd9fnvZrHHszK7ch9adc9zZSSw VwVO371lVmOtWhrjHx09+zDkIbPb2krpOgTACu0hDURy4TqEb0w1oXzLbm3kI77hv1VFU lLm6xBmMEZyru92tNbO42VtiAddZTljmHJSRFZ//A7X2m0aRUvnjQE4H2n2z0ByImAw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796122745; h=DMARC-Filter:DKIM-Signature:X-MC-Rep:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: X-Received:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:X-Mimecast-Spam-Score: X-Mimecast-MFC-PROC-ID:X-Mimecast-Originator: Content-Transfer-Encoding:content-type; bh=6ag7nKqzDkoTxE4TaiWJ6NRLy3Btgz9NadTtmxO/9Qg=; b=FmEkg1gIbafvnmJ7nA2VGZo6Nvf/M/4nrKmuAXp8o5xBwdXPcOHRxKyE1qO5774LXKUe +HJVef6lDLJuaxCuSuJQNYqGovmOxZ0Q2MaZ4bfQ4xhtxLSPFoC53KxoenfLymM+/siC0 OUE3Obj3p09+RRTMQYgZFNQS3HXG6wglsTsd+KsibknFaUzS3juGdjay+G1Dr9DA8fcte dxz+EG+73vxum3EKcUQAJ0h/hDJDi+e9QwESOnN847rwdBVo29yUZ9eMUe3KebuBmZpds PxJZSF7pckXue5P33kAGzQNc91cy31BkPnEhjsdSxSE9Uy9wBpz30vKAmeWtjQBDtpA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WuqGgOBD; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3387606A327 for ; Tue, 1 Dec 2026 10:59:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F3387606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WuqGgOBD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796122745; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6ag7nKqzDkoTxE4TaiWJ6NRLy3Btgz9NadTtmxO/9Qg=; b=WuqGgOBDa5UbvyQJqp7WEV6PY94JzkFnMS/yZ3sR4p5OyuvOonbTlkoWK+pBWUuC5j5YsY mFoARVd7D3YSF3GAlte3eUeE6qU/fBjtvSOykcxzknpfK6KWrC1nxQZWVJex0H7dn+ylwP PCtlbacglDtSp4NOU+Nxxnv/xnmtdg4= X-MC-Rep: binary re single Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-J513djZyN3yx4EhS63VK2w-1; Tue, 1 Dec 2026 10:59:02 +0000 X-MC-Unique: J513djZyN3yx4EhS63VK2w-1 X-Mimecast-MFC-AGG-ID: J513djZyN3yx4EhS63VK2w_1796122741 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4c42d1a8d38so1355567f8f.3 for ; Tue, 01 Dec 2026 02:59:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796122741; x=1796727541; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=6ag7nKqzDkoTxE4TaiWJ6NRLy3Btgz9NadTtmxO/9Qg=; b=p/hl/UOC80peiUHPEL8+PxMJ2klckdUeRArDU1NoEN99Ysb3kXskTMCmHNT+hURnmH n/HGf6KATvdCl47TjGJ9fw7LYazWSYdQl8V2ImKzijSKO/d4Tb1ARMHc++8BEo1nRJ6k krkLkMrs7JR5j93QxPxda1GT3BZBb3lNhK/I9LIb+oVo6t49IdLFd+fe8UTmGXOqpWgD LziWzSjBfeZS3b283DeS+dZvM0rzynK3J7zRO9BWFHKRNTMYrssIe5+ktJNR+RvuFeu0 NsY8hlXOEaUXEdDxEAdhtldXeH/uPU97vmwjgDxGXXL4Zq4zq97b24Ke2z2h6pGXj8TX Eo5w== X-Forwarded-Encrypted: i=1; AL+hErFGIxgieX3DKXQr6OI+FpBRIqTz3N43suQYIkAHImV0Rbkr97MeQU7EBKE1iJ+ITCUHHCmP/tIPiND9YyLkuQ==@lists.linux.dev X-Gm-Message-State: APuU4Z+YqxUGIMHIGVU80+jyuRyHJ2poJYdd50Wkl06EQ0wYSCWSWy2j sv6lWQ2sfDJGfOOQz896ahwhwpdObKqvhfcN33q3TnHTnFVhnGREwayqfs5/qEJT9s+76t8J4fQ bLx6TWvvUBMhCe/p6OWAfUb3yJsiFf0RCEOVnweBp9bhwohLbEqUU4lu9mocYTf4SACOp X-Gm-Gg: AZFdTZdZ9WOkI0YM+zgg+IIISjeMKfrWhkv9ipBiQeWJXeiQ0YSU48iDVI7Y6UwnNwG wlFmOrdz70u2C5WJ1XsMqwxUQPOOHqK0LKywn+NDnS5DU5/5wSM1Fud7mNCV/sFfItafCiXJ8nB re+3BVXCzP8gVLEtcDYMokbnxnVNzeynpbitHk/dHtQanr6P3HKWGtWB2WJNi2wMr75gdGeU7GW lx+VoWR2djFzwWdcrd12ECa31XtpJfChsGuy5rX4lNCQaWxX2lIcSC8pw/Hng876gMhYyYyMJAs DIrfPzayCQbOFLkcs4KJW8t6z5jcH3dhMPeT6Hsrr2aKqGKMdEcH/6JQQqhdBAAEUvSqXmb4y7N R8EnGsu6s0kL6sq3pisT4TFnaBEOtJEVepUDUvcIUygNWBk5htvwQeaCfe/wNOOpjgJWaXgsnTD YeXCKM54F33Ajx3yaB1bLV8hImlII1Yviw6kH44lEO X-Received: by 2002:a05:6000:2883:b0:4a4:39bb:970d with SMTP id ffacd0b85a97d-4abab02c469mr69229455f8f.2.1796122741079; Tue, 01 Dec 2026 02:59:01 -0800 (PST) X-Received: by 2002:a05:6000:2883:b0:4a4:39bb:970d with SMTP id ffacd0b85a97d-4abab02c469mr69229413f8f.2.1796122740678; Tue, 01 Dec 2026 02:59:00 -0800 (PST) Received: from mszeredi-thinkpadt14gen6.redhat.corp (193-226-214-34.pool.digikabel.hu. [193.226.214.34]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab69bf685asm72464829f8f.20.2026.12.01.02.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 02:59:00 -0800 (PST) From: Miklos Szeredi To: fuse-devel@lists.linux.dev, virtualization@lists.linux.dev Cc: Li Wang , German Maglione , Stefan Hajnoczi Subject: [PATCH v3 5/5] virtiofs: fix forget leak on submount unmount Date: Tue, 1 Dec 2026 11:58:53 +0100 Message-ID: <20261201105855.430993-5-mszeredi@redhat.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201105855.430993-1-mszeredi@redhat.com> References: <20261201105855.430993-1-mszeredi@redhat.com> X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 56IUYxHkA2mluGfgSoi378sA08DDn_PG0Tp-pNLxkAc_1796122741 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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: # 8ebc672894c3: fuse: don't take a lookup count on the root inode Cc: Signed-off-by: Miklos Szeredi --- 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