From 367cb1fff32e9dc315cb775d4974ac288489d13f Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Sat, 26 May 2018 17:12:03 +0200 Subject: [PATCH] [0.4.9] cherry-pick [FASTFAT] Lock DirResource when modifying an entry on disk. Likely not optimal, but fixes some races conditions where the directory is uninit in the middle of the write. (cherry picked from commit fc788cf2fde7551a8e5068f2b061c3cad2004e9a) --- drivers/filesystems/fastfat/finfo.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/filesystems/fastfat/finfo.c b/drivers/filesystems/fastfat/finfo.c index d860cd641be..af2e1ce62a2 100644 --- a/drivers/filesystems/fastfat/finfo.c +++ b/drivers/filesystems/fastfat/finfo.c @@ -1552,6 +1552,7 @@ VfatSetInformation( PVFATFCB FCB; NTSTATUS Status = STATUS_SUCCESS; PVOID SystemBuffer; + BOOLEAN LockDir; /* PRECONDITION */ ASSERT(IrpContext); @@ -1593,7 +1594,14 @@ VfatSetInformation( DPRINT("Can set file size\n"); } - if (FileInformationClass == FileRenameInformation) + LockDir = FALSE; + if (FileInformationClass == FileRenameInformation || FileInformationClass == FileAllocationInformation || + FileInformationClass == FileEndOfFileInformation || FileInformationClass == FileBasicInformation) + { + LockDir = TRUE; + } + + if (LockDir) { if (!ExAcquireResourceExclusiveLite(&((PDEVICE_EXTENSION)IrpContext->DeviceObject->DeviceExtension)->DirResource, BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT))) @@ -1607,7 +1615,7 @@ VfatSetInformation( if (!ExAcquireResourceExclusiveLite(&FCB->MainResource, BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT))) { - if (FileInformationClass == FileRenameInformation) + if (LockDir) { ExReleaseResourceLite(&((PDEVICE_EXTENSION)IrpContext->DeviceObject->DeviceExtension)->DirResource); } @@ -1662,7 +1670,7 @@ VfatSetInformation( ExReleaseResourceLite(&FCB->MainResource); } - if (FileInformationClass == FileRenameInformation) + if (LockDir) { ExReleaseResourceLite(&((PDEVICE_EXTENSION)IrpContext->DeviceObject->DeviceExtension)->DirResource); }