inc,sys,tst: FSP_FSCTL_VOLUME_PARAMS::RejectIrpPriorToTransact

This commit is contained in:
Bill Zissimopoulos 2020-02-03 14:59:23 -08:00
parent 9e32fed598
commit 51350d5a42
No known key found for this signature in database
GPG Key ID: 3D4F95D52C7B3EA3
7 changed files with 54 additions and 6 deletions

View File

@ -101,7 +101,7 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>MEMFS_STANDALONE;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
@ -117,7 +117,7 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>MEMFS_STANDALONE;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
@ -135,7 +135,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>MEMFS_STANDALONE;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
@ -155,7 +155,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>MEMFS_STANDALONE;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>

View File

@ -176,7 +176,8 @@ enum
UINT32 CasePreservedExtendedAttributes:1; /* preserve case of EA (default is UPPERCASE) */\
UINT32 WslFeatures:1; /* support features required for WSLinux */\
UINT32 DirectoryMarkerAsNextOffset:1; /* directory marker is next offset instead of last name */\
UINT32 KmReservedFlags:4;\
UINT32 RejectIrpPriorToTransact:1; /* reject IRP's prior to first FSP_FSCTL_TRANSACT */\
UINT32 KmReservedFlags:3;\
WCHAR Prefix[FSP_FSCTL_VOLUME_PREFIX_SIZE / sizeof(WCHAR)]; /* UNC prefix (\Server\Share) */\
WCHAR FileSystemName[FSP_FSCTL_VOLUME_FSNAME_SIZE / sizeof(WCHAR)];
#define FSP_FSCTL_VOLUME_PARAMS_V1_FIELD_DEFN\

View File

@ -284,6 +284,9 @@ static NTSTATUS FspFsvolCreateNoLock(
return STATUS_SUCCESS;
}
if (!FspFsvolDeviceReadyToAcceptIrp(FsvolDeviceObject))
return STATUS_CANCELLED;
PACCESS_STATE AccessState = IrpSp->Parameters.Create.SecurityContext->AccessState;
ULONG CreateDisposition = (IrpSp->Parameters.Create.Options >> 24) & 0xff;
ULONG CreateOptions = IrpSp->Parameters.Create.Options;

View File

@ -1082,6 +1082,7 @@ typedef struct
FSP_FSEXT_PROVIDER *Provider;
UNICODE_STRING VolumePrefix;
UNICODE_PREFIX_TABLE_ENTRY VolumePrefixEntry;
LONG ReadyToAcceptIrp;
FSP_IOQ *Ioq;
FSP_META_CACHE *SecurityCache;
FSP_META_CACHE *DirInfoCache;
@ -1182,6 +1183,22 @@ BOOLEAN FspFsvolDeviceTryGetVolumeInfo(PDEVICE_OBJECT DeviceObject, FSP_FSCTL_VO
VOID FspFsvolDeviceSetVolumeInfo(PDEVICE_OBJECT DeviceObject, const FSP_FSCTL_VOLUME_INFO *VolumeInfo);
VOID FspFsvolDeviceInvalidateVolumeInfo(PDEVICE_OBJECT DeviceObject);
static inline
BOOLEAN FspFsvolDeviceReadyToAcceptIrp(PDEVICE_OBJECT DeviceObject)
{
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject);
if (!FsvolDeviceExtension->VolumeParams.RejectIrpPriorToTransact)
return TRUE;
return 0 != InterlockedCompareExchange(&FsvolDeviceExtension->ReadyToAcceptIrp, 0, 0);
}
static inline
VOID FspFsvolDeviceSetReadyToAcceptIrp(PDEVICE_OBJECT DeviceObject)
{
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject);
if (!FsvolDeviceExtension->VolumeParams.RejectIrpPriorToTransact)
return;
InterlockedExchange(&FsvolDeviceExtension->ReadyToAcceptIrp, 1);
}
static inline
BOOLEAN FspFsvolDeviceVolumePrefixInString(PDEVICE_OBJECT DeviceObject, PUNICODE_STRING String)
{
return RtlPrefixUnicodeString(&FspFsvolDeviceExtension(DeviceObject)->VolumePrefix, String,

View File

@ -286,6 +286,9 @@ static NTSTATUS FspFsvolQueryVolumeInformation(
{
PAGED_CODE();
if (!FspFsvolDeviceReadyToAcceptIrp(FsvolDeviceObject))
return STATUS_CANCELLED;
NTSTATUS Result;
PUINT8 Buffer = Irp->AssociatedIrp.SystemBuffer;
PUINT8 BufferEnd = Buffer + IrpSp->Parameters.QueryVolume.Length;
@ -414,6 +417,9 @@ static NTSTATUS FspFsvolSetVolumeInformation(
{
PAGED_CODE();
if (!FspFsvolDeviceReadyToAcceptIrp(FsvolDeviceObject))
return STATUS_CANCELLED;
NTSTATUS Result;
FS_INFORMATION_CLASS FsInformationClass = IrpSp->Parameters.SetVolume.FsInformationClass;
PVOID Buffer = Irp->AssociatedIrp.SystemBuffer;

View File

@ -277,6 +277,8 @@ static NTSTATUS FspVolumeCreateNoLock(
RtlInitEmptyUnicodeString(&FsvolDeviceExtension->VolumeName,
FsvolDeviceExtension->VolumeNameBuf, sizeof FsvolDeviceExtension->VolumeNameBuf);
RtlCopyUnicodeString(&FsvolDeviceExtension->VolumeName, &VolumeName);
if (!FsvolDeviceExtension->VolumeParams.RejectIrpPriorToTransact)
FsvolDeviceExtension->ReadyToAcceptIrp = 1;
Result = FspDeviceInitialize(FsvolDeviceObject);
if (NT_SUCCESS(Result))
{
@ -767,6 +769,8 @@ NTSTATUS FspVolumeTransact(
if (!FspDeviceReference(FsvolDeviceObject))
return STATUS_CANCELLED;
FspFsvolDeviceSetReadyToAcceptIrp(FsvolDeviceObject);
NTSTATUS Result;
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(FsvolDeviceObject);
PUINT8 BufferEnd;

View File

@ -34,6 +34,12 @@
FSP_FSCTL_STATIC_ASSERT(MEMFS_MAX_PATH > MAX_PATH,
"MEMFS_MAX_PATH must be greater than MAX_PATH.");
/*
* Define the MEMFS_STANDALONE macro when building MEMFS as a standalone file system.
* This macro should be defined in the Visual Studio project settings, Makefile, etc.
*/
//#define MEMFS_STANDALONE
/*
* Define the MEMFS_NAME_NORMALIZATION macro to include name normalization support.
*/
@ -74,7 +80,15 @@ FSP_FSCTL_STATIC_ASSERT(MEMFS_MAX_PATH > MAX_PATH,
*/
#define MEMFS_WSL
/*
/*
* Define the MEMFS_REJECT_EARLY_IRP macro to reject IRP's sent
* to the file system prior to FSP_FSCTL_TRANSACT.
*/
#if defined(MEMFS_STANDALONE)
#define MEMFS_REJECT_EARLY_IRP
#endif
/*
* Define the DEBUG_BUFFER_CHECK macro on Windows 8 or above. This includes
* a check for the Write buffer to ensure that it is read-only.
*
@ -2387,6 +2401,9 @@ NTSTATUS MemfsCreateFunnel(
VolumeParams.WslFeatures = 1;
#endif
VolumeParams.AllowOpenInKernelMode = 1;
#if defined(MEMFS_REJECT_EARLY_IRP)
VolumeParams.RejectIrpPriorToTransact = 1;
#endif
if (0 != VolumePrefix)
wcscpy_s(VolumeParams.Prefix, sizeof VolumeParams.Prefix / sizeof(WCHAR), VolumePrefix);
wcscpy_s(VolumeParams.FileSystemName, sizeof VolumeParams.FileSystemName / sizeof(WCHAR),