sys: IRP_MJ_FLUSH_BUFFERS: fix deadlock when flushing volume

This commit is contained in:
Bill Zissimopoulos 2016-04-04 16:13:04 -07:00
parent 83c59a6f37
commit 8ef10e5992

View File

@ -37,6 +37,7 @@ static NTSTATUS FspFsvolFlushBuffers(
FSP_FILE_DESC *FileDesc = FileObject->FsContext2; FSP_FILE_DESC *FileDesc = FileObject->FsContext2;
FSP_FILE_NODE **FileNodes; FSP_FILE_NODE **FileNodes;
ULONG FileNodeCount, Index; ULONG FileNodeCount, Index;
PIRP TopLevelIrp;
IO_STATUS_BLOCK IoStatus; IO_STATUS_BLOCK IoStatus;
FSP_FSCTL_TRANSACT_REQ *Request; FSP_FSCTL_TRANSACT_REQ *Request;
@ -50,6 +51,10 @@ static NTSTATUS FspFsvolFlushBuffers(
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Result))
return Result; return Result;
/* reset the top-level IRP to avoid deadlock on the FileNodes' resources */
TopLevelIrp = IoGetTopLevelIrp();
IoSetTopLevelIrp(0);
/* /*
* Enumerate in reverse order so that files are flushed before containing directories. * Enumerate in reverse order so that files are flushed before containing directories.
* This would be useful if we ever started flushing directories, but since we do not * This would be useful if we ever started flushing directories, but since we do not
@ -65,6 +70,8 @@ static NTSTATUS FspFsvolFlushBuffers(
FlushResult = Result; FlushResult = Result;
} }
IoSetTopLevelIrp(TopLevelIrp);
FspFileNodeDeleteList(FileNodes, FileNodeCount); FspFileNodeDeleteList(FileNodes, FileNodeCount);
Result = FspIopCreateRequest(Irp, 0, 0, &Request); Result = FspIopCreateRequest(Irp, 0, 0, &Request);