]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commit
fuse2fs: fix lockfile creation, again
authorDarrick J. Wong <djwong@kernel.org>
Tue, 8 Jul 2025 17:33:33 +0000 (10:33 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 31 Jul 2025 14:41:55 +0000 (10:41 -0400)
commit9bdd3c20c1bb2b47fdd7bff59f75110b792bfc13
treefd55c5ca0dd343e769d0cf27f408452419959225
parent5cd55fe0aca3fed5a7ca6f0b4976f0e7b1e4a972
fuse2fs: fix lockfile creation, again

On closer examination of the lockfile code, there is still a fatal flaw
in the locking logic.  This is born out by the fact that you can run:

# truncate -s 300m /tmp/a
# mkfs.ext2 /tmp/a
# fuse2fs -o kernel /tmp/a /mnt -o lockfile=/tmp/fuselock
# fuse2fs -o kernel /tmp/a /mnt -o lockfile=/tmp/fuselock

and the second mount attempt succeeds where it really shouldn't.  This
is due to the use of fopen(..., "w"), because "w" means "truncate or
create".  It does /not/ imply O_CREAT | O_EXCL, which fails if the file
already exists.  Theoretically that could have been done with mode
string "wx", but that's a glibc extension.

Fix this by calling open() directly with the O_ modes that we want.

Cc: linux-ext4@vger.kernel.org # v1.47.3-rc3
Fixes: e50fbaa4d156a6 ("fuse2fs: clean up the lockfile handling")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Link: https://lore.kernel.org/r/20250708173333.GD2672022@frogsfrogsfrogs
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/fuse2fs.c