From ba7c798418269e6d496af206bdebd2204a07155f Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 8 May 2016 23:16:40 +0200 Subject: [PATCH] fusefrontend: fix panic due to concurrently unregistered wlock Commit 730291feab properly freed wlock when the file descriptor is closed. However, concurrently running Write and Truncates may still want to lock it. Check if the fd has been closed first. --- internal/fusefrontend/file.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/fusefrontend/file.go b/internal/fusefrontend/file.go index d9588e9..ac00b1d 100644 --- a/internal/fusefrontend/file.go +++ b/internal/fusefrontend/file.go @@ -278,6 +278,10 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) { func (f *file) Write(data []byte, off int64) (uint32, fuse.Status) { f.fdLock.RLock() defer f.fdLock.RUnlock() + if f.fd.Fd() < 0 { + // The file descriptor has been closed concurrently. + return 0, fuse.EBADF + } wlock.lock(f.ino) defer wlock.unlock(f.ino) @@ -337,6 +341,10 @@ func (f *file) Fsync(flags int) (code fuse.Status) { func (f *file) Truncate(newSize uint64) fuse.Status { f.fdLock.RLock() defer f.fdLock.RUnlock() + if f.fd.Fd() < 0 { + // The file descriptor has been closed concurrently. + return fuse.EBADF + } wlock.lock(f.ino) defer wlock.unlock(f.ino)