]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
fuse2fs: fix races in statfs
authorDarrick J. Wong <djwong@kernel.org>
Wed, 9 Jul 2025 16:52:40 +0000 (09:52 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 31 Jul 2025 14:41:55 +0000 (10:41 -0400)
Take the BFL in statfs so that we don't expose a torn access to
userspace.  Found via code inspection.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Link: https://lore.kernel.org/r/20250709165240.GF2672022@frogsfrogsfrogs
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/fuse2fs.c

index f0250bd1cec2ec576f2629887b3c8412de482604..bc9fed6f4a85257696ca88f1e45af646612ce23b 100644 (file)
@@ -2743,8 +2743,9 @@ static int op_statfs(const char *path EXT2FS_ATTR((unused)),
        blk64_t overhead, reserved, free;
 
        FUSE2FS_CHECK_CONTEXT(ff);
-       fs = ff->fs;
        dbg_printf(ff, "%s: path=%s\n", __func__, path);
+       fs = ff->fs;
+       pthread_mutex_lock(&ff->bfl);
        buf->f_bsize = fs->blocksize;
        buf->f_frsize = 0;
 
@@ -2777,6 +2778,7 @@ static int op_statfs(const char *path EXT2FS_ATTR((unused)),
        if (fs->flags & EXT2_FLAG_RW)
                buf->f_flag |= ST_RDONLY;
        buf->f_namemax = EXT2_NAME_LEN;
+       pthread_mutex_unlock(&ff->bfl);
 
        return 0;
 }