]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
fuse2fs: fix race condition in op_destroy
authorDarrick J. Wong <djwong@kernel.org>
Wed, 9 Jul 2025 16:51:52 +0000 (09:51 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 31 Jul 2025 14:41:55 +0000 (10:41 -0400)
On a regular fuse server (i.e. one not running in fuseblk mode), libfuse
synthesizes and dispatches a FUSE_DESTROY command as soon as the event
dispatch loop terminates after the kernel disconnects /dev/fuse.
Unfortunately, this is done without coordinating with any other threads
that may have already received a real FUSE command from the kernel.

In other words, FUSE_DESTROY can run in parallel with other
fuse_operations.  Therefore, we must guard the body of this function
with the BKL just like any other fuse operation or risk races within
libext2fs.  If we're lucky, we trash the ext2_filsys state and
generic/488 will crash.

[23512.452451] [U] fuse: reading device: Software caused connection abort
[23512.453886] [U] fuse: reading device: Software caused connection abort

If we're not lucky, it corrupts the ondisk filesystem resulting in a
e2fsck complaining as well.

Cc: linux-ext4@vger.kernel.org # v1.43
Fixes: 81cbf1ef4f5dab ("misc: add fuse2fs, a FUSE server for e2fsprogs")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Link: https://lore.kernel.org/r/20250709165152.GE2672022@frogsfrogsfrogs
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/fuse2fs.c

index ff8d4668cee21716ffdd982abef92307637d34e9..f0250bd1cec2ec576f2629887b3c8412de482604 100644 (file)
@@ -728,7 +728,10 @@ static void op_destroy(void *p EXT2FS_ATTR((unused)))
                translate_error(global_fs, 0, EXT2_ET_BAD_MAGIC);
                return;
        }
+
+       pthread_mutex_lock(&ff->bfl);
        fs = ff->fs;
+
        dbg_printf(ff, "%s: dev=%s\n", __func__, fs->device_name);
        if (fs->flags & EXT2_FLAG_RW) {
                fs->super->s_state |= EXT2_VALID_FS;
@@ -763,6 +766,8 @@ static void op_destroy(void *p EXT2FS_ATTR((unused)))
                uuid_unparse(fs->super->s_uuid, uuid);
                log_printf(ff, "%s %s.\n", _("unmounting filesystem"), uuid);
        }
+
+       pthread_mutex_unlock(&ff->bfl);
 }
 
 static void *op_init(struct fuse_conn_info *conn