From 29000177b94c6c9aaab97b3f3d8ed5123ed7cf44 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Mon, 30 Dec 2024 12:08:41 +0100 Subject: fusefrontend: sharedstorage: lock truncate agains concurrent access Prevent reads and writes concurrent with the truncate operation. It's racy on tmpfs and ext4 ( https://lore.kernel.org/all/18e9fa0f-ec31-9107-459c-ae1694503f87@gmail.com/t/ ) as evident by TestOpenTruncate test failures: === RUN TestOpenTruncate cluster_test.go:209: POSIX compliance issue: non-exlusive create failed with err=file exists doRead 16384215: corrupt block #0: cipher: message authentication failed ino16384215 fh8: RMW read failed: errno=5 cluster_test.go:214: iteration 1: WriteAt: write /tmp/gocryptfs-test-parent-1026/1358464214/TestOpenTruncate.1788296708.mnt2/foo: input/output error --- FAIL: TestOpenTruncate (0.06s) FAIL exit status 1 FAIL github.com/rfjakob/gocryptfs/v2/tests/cluster 7.880s Relates-to: https://github.com/rfjakob/gocryptfs/issues/56 --- internal/fusefrontend/file.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'internal/fusefrontend/file.go') diff --git a/internal/fusefrontend/file.go b/internal/fusefrontend/file.go index 813f992..b7ff032 100644 --- a/internal/fusefrontend/file.go +++ b/internal/fusefrontend/file.go @@ -258,7 +258,7 @@ func (f *File) Read(ctx context.Context, buf []byte, off int64) (resultData fuse if !(f.rootNode.args.SharedStorage && errno == syscall.EIO) { return nil, errno } - blocks := f.contentEnc.ExplodePlainRange(uint64(off), uint64(len(buf))) + blocks := f.rootNode.contentEnc.ExplodePlainRange(uint64(off), uint64(len(buf))) alignedOffset, alignedLength := blocks[0].JointCiphertextRange(blocks) if err := f.LockSharedStorage(unix.F_RDLCK, int64(alignedOffset), int64(alignedLength)); err != nil { tlog.Warn.Printf("ino%d: FUSE Read: LockSharedStorage(F_RDLCK, %d, %d) failed: %v", f.qIno.Ino, alignedOffset, alignedLength, err) -- cgit v1.2.3