Skip to content

Commit

Permalink
fast_io_write: acquire fcb exclusively, to avoid deadlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
maharmstone committed Sep 8, 2019
1 parent c8241a6 commit 8ac71ac
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/fastio.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,26 @@ static NTSTATUS __stdcall fast_io_release_for_ccflush(PFILE_OBJECT FileObject, P

_Function_class_(FAST_IO_WRITE)
static BOOLEAN __stdcall fast_io_write(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, ULONG LockKey, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject) {
if (FsRtlCopyWrite(FileObject, FileOffset, Length, Wait, LockKey, Buffer, IoStatus, DeviceObject)) {
fcb* fcb = FileObject->FsContext;
fcb* fcb = FileObject->FsContext;
bool ret;

fcb->inode_item.st_size = fcb->Header.FileSize.QuadPart;
if (!ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, Wait))
return false;

return true;
if (!ExAcquireResourceExclusiveLite(fcb->Header.Resource, Wait)) {
ExReleaseResourceLite(&fcb->Vcb->tree_lock);
return false;
}

return false;
ret = FsRtlCopyWrite(FileObject, FileOffset, Length, Wait, LockKey, Buffer, IoStatus, DeviceObject);

if (ret)
fcb->inode_item.st_size = fcb->Header.FileSize.QuadPart;

ExReleaseResourceLite(fcb->Header.Resource);
ExReleaseResourceLite(&fcb->Vcb->tree_lock);

return ret;
}

_Function_class_(FAST_IO_LOCK)
Expand Down

0 comments on commit 8ac71ac

Please sign in to comment.