diff options
| author | olegkMS <[email protected]> | 2022-05-18 15:26:38 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-05-18 15:26:38 -0700 |
| commit | b8d3abcd822aafc27af851f7ec6b8938b21e57b5 (patch) | |
| tree | f8f5f305658415db163242a676d3bf0bb4451d8d | |
| parent | ca1f03863feb9b38bac8e0782f3bdf5dc4795ebc (diff) | |
Replaced ExAllocatePoolWithTag to more secure ExAllocatePoolZero in samples of filesystems and filesystem filters; made necessary changes to make solutions buildable under recent Visual Studio (#725)
34 files changed, 1275 insertions, 1269 deletions
diff --git a/filesys/cdfs/cdprocs.h b/filesys/cdfs/cdprocs.h index d2f7db0b..4c2bba14 100644 --- a/filesys/cdfs/cdprocs.h +++ b/filesys/cdfs/cdprocs.h @@ -231,12 +231,12 @@ CdVerifyOrCreateDirStreamFile ( // // Unsafe test to see if call / lock neccessary. // - + if (NULL == Fcb->FileObject) { - + CdCreateInternalStream( IrpContext, Fcb->Vcb, - Fcb, + Fcb, &Fcb->FileNamePrefix.ExactCaseName.FileName); } } @@ -371,8 +371,8 @@ CdHijackIrpAndFlushDevice ( if (NULL == *(UB)) { \ CdRaiseStatus( (IC), STATUS_INSUFFICIENT_RESOURCES); \ } \ - } - + } + #define CdLockUserBuffer(IC,BL,OP) { \ if ((IC)->Irp->MdlAddress == NULL) { \ @@ -809,7 +809,7 @@ CdFindPrefix ( // typedef enum _TYPE_OF_ACQUIRE { - + AcquireExclusive, AcquireShared, AcquireSharedStarveExclusive @@ -944,10 +944,10 @@ CdAcquireResource ( #define CdAcquireCacheForRead( IC) \ ExAcquireResourceSharedLite( &(IC)->Vcb->SectorCacheResource, TRUE) - + #define CdAcquireCacheForUpdate( IC) \ ExAcquireResourceExclusiveLite( &(IC)->Vcb->SectorCacheResource, TRUE) - + #define CdReleaseCache( IC) \ ExReleaseResourceLite( &(IC)->Vcb->SectorCacheResource); @@ -1225,7 +1225,7 @@ CdInitializeStackIrpContext ( // #define CdCreateIrpContextLite(IC) \ - ExAllocatePoolWithTag( CdNonPagedPool, sizeof( IRP_CONTEXT_LITE ), TAG_IRP_CONTEXT_LITE ) + ExAllocatePoolZero( CdNonPagedPool, sizeof( IRP_CONTEXT_LITE ), TAG_IRP_CONTEXT_LITE ) #define CdFreeIrpContextLite(ICL) \ CdFreePool( &(ICL) ) @@ -1372,7 +1372,7 @@ CdOperationIsDasdOpen ( ) { PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( IrpContext->Irp); - + return ((IrpContext->MajorFunction == IRP_MJ_CREATE) && (IrpSp->FileObject->FileName.Length == 0) && (IrpSp->FileObject->RelatedFileObject == NULL)); @@ -1427,7 +1427,7 @@ CdDismountVcb ( #define CdUpdateVcbCondition( V, C) (V)->VcbCondition = (C) #define CdMarkRealDevForVerify( DO) SetFlag( (DO)->Flags, DO_VERIFY_VOLUME) - + #define CdMarkRealDevVerifyOk( DO) ClearFlag( (DO)->Flags, DO_VERIFY_VOLUME) @@ -1577,7 +1577,7 @@ CdOplockComplete ( INLINE ULONG -SectorsFromLlBytes( +SectorsFromLlBytes( ULONGLONG Bytes ) { diff --git a/filesys/cdfs/prefxsup.c b/filesys/cdfs/prefxsup.c index 6a7b6c59..f95814c6 100644 --- a/filesys/cdfs/prefxsup.c +++ b/filesys/cdfs/prefxsup.c @@ -106,13 +106,11 @@ Return Value: if (Fcb->ShortNamePrefix == NULL) { - Fcb->ShortNamePrefix = ExAllocatePoolWithTag( CdPagedPool, - sizeof( PREFIX_ENTRY ), - TAG_PREFIX_ENTRY ); + Fcb->ShortNamePrefix = ExAllocatePoolZero( CdPagedPool, + sizeof( PREFIX_ENTRY ), + TAG_PREFIX_ENTRY ); if (Fcb->ShortNamePrefix == NULL) { return; } - - RtlZeroMemory( Fcb->ShortNamePrefix, sizeof( PREFIX_ENTRY )); } PrefixEntry = Fcb->ShortNamePrefix; @@ -151,9 +149,9 @@ Return Value: if (Name->FileName.Length > BYTE_COUNT_EMBEDDED_NAME) { - NameBuffer = ExAllocatePoolWithTag( CdPagedPool, - Name->FileName.Length * 2, - TAG_PREFIX_NAME ); + NameBuffer = ExAllocatePoolZero( CdPagedPool, + Name->FileName.Length * 2, + TAG_PREFIX_NAME ); // // Exit if no name buffer. @@ -228,9 +226,9 @@ Return Value: { PAGED_CODE(); - + UNREFERENCED_PARAMETER( IrpContext ); - + // // Start with the short name prefix entry. // diff --git a/filesys/cdfs/strucsup.c b/filesys/cdfs/strucsup.c index 5f354ac2..abf56420 100644 --- a/filesys/cdfs/strucsup.c +++ b/filesys/cdfs/strucsup.c @@ -85,7 +85,7 @@ Abstract: CdFreePool( &(F) ) #define CdAllocateFcbNonpaged(IC) \ - ExAllocatePoolWithTag( CdNonPagedPool, sizeof( FCB_NONPAGED ), TAG_FCB_NONPAGED ) + ExAllocatePoolZero( CdNonPagedPool, sizeof( FCB_NONPAGED ), TAG_FCB_NONPAGED ) #define CdDeallocateFcbNonpaged(IC,FNP) \ CdFreePool( &(FNP) ) @@ -311,13 +311,13 @@ Return Value: InitializeListHead( &Vcb->DirNotifyList ); FsRtlNotifyInitializeSync( &Vcb->NotifySync ); - + // // Pick up a VPB right now so we know we can pull this filesystem stack - // off of the storage stack on demand. This can raise - if it does, + // off of the storage stack on demand. This can raise - if it does, // uninitialize the notify structures before returning. // - + try { Vcb->SwapVpb = FsRtlAllocatePoolWithTag( CdNonPagedPool, @@ -327,7 +327,7 @@ Return Value: finally { if (AbnormalTermination()) { - + FsRtlNotifyUninitializeSync( &Vcb->NotifySync ); } } @@ -337,7 +337,7 @@ Return Value: // RtlZeroMemory( Vcb->SwapVpb, sizeof( VPB ) ); - + // // Initialize the resource variable for the Vcb and files. // @@ -493,7 +493,7 @@ Return Value: // // We no longer accept media where blocksize != sector size. // - + if (Vcb->BlockSize != SECTOR_SIZE) { CdRaiseStatus( IrpContext, STATUS_DISK_CORRUPT_ERROR ); @@ -502,7 +502,7 @@ Return Value: Vcb->BlocksPerSector = SECTOR_SIZE / Vcb->BlockSize; Vcb->BlockMask = Vcb->BlockSize - 1; Vcb->BlockInverseMask = ~Vcb->BlockMask; - + Vcb->BlockToSectorShift = 0; Vcb->BlockToByteShift = SECTOR_SHIFT; @@ -656,16 +656,16 @@ Return Value: McbEntry = Vcb->VolumeDasdFcb->Mcb.McbArray; - McbEntry->FileOffset = + McbEntry->FileOffset = McbEntry->DiskOffset = 0; - + McbEntry->ByteCount = Vcb->VolumeDasdFcb->AllocationSize.QuadPart; - + McbEntry->DataBlockByteCount = McbEntry->TotalBlockByteCount = McbEntry->ByteCount; - + Vcb->VolumeDasdFcb->Mcb.CurrentEntryCount = 1; - + CdUnlockFcb( IrpContext, Vcb->VolumeDasdFcb ); // @@ -861,7 +861,7 @@ Return Value: SetFlag( Vcb->VcbState, VCB_STATE_ISO ); } - + } finally { if (UnlockVcb) { CdUnlockVcb( IrpContext, Vcb ); } @@ -898,15 +898,15 @@ Return Value: ASSERT_EXCLUSIVE_CDDATA; ASSERT_EXCLUSIVE_VCB( Vcb ); - + UNREFERENCED_PARAMETER( IrpContext ); - + // // Chuck the backpocket Vpb we kept just in case. // CdFreePool( &Vcb->SwapVpb ); - + // // If there is a Vpb then we must delete it ourselves. // @@ -918,7 +918,7 @@ Return Value: // if (Vcb->TargetDeviceObject != NULL) { - + ObDereferenceObject( Vcb->TargetDeviceObject ); } @@ -1069,7 +1069,7 @@ Return Value: default: -#pragma prefast( suppress: __WARNING_USE_OTHER_FUNCTION, "This is a bug." ) +#pragma prefast( suppress: __WARNING_USE_OTHER_FUNCTION, "This is a bug." ) CdBugCheck( 0, 0, 0 ); } @@ -1108,7 +1108,7 @@ Return Value: // ExInitializeFastMutex( &NewFcb->FcbNonpaged->AdvancedFcbHeaderMutex ); - FsRtlSetupAdvancedHeader( &NewFcb->Header, + FsRtlSetupAdvancedHeader( &NewFcb->Header, &NewFcb->FcbNonpaged->AdvancedFcbHeaderMutex ); if (NodeTypeCode == CDFS_NTC_FCB_DATA) { @@ -1424,7 +1424,7 @@ Return Value: PAGED_CODE(); UNREFERENCED_PARAMETER( IrpContext ); - + // // Allocate and initialize the structure. // @@ -1476,7 +1476,7 @@ Return Value: PAGED_CODE(); UNREFERENCED_PARAMETER( IrpContext ); - + if (Ccb->SearchExpression.FileName.Buffer != NULL) { CdFreePool( &Ccb->SearchExpression.FileName.Buffer ); @@ -1547,7 +1547,7 @@ Return Value: // if (FileLock == NULL) { - + if (RaiseOnError) { NT_ASSERT( ARGUMENT_PRESENT( IrpContext )); @@ -1611,11 +1611,11 @@ Return Value: } NT_ASSERT( IrpSp->FileObject != NULL || - + (IrpSp->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL && IrpSp->MinorFunction == IRP_MN_USER_FS_REQUEST && IrpSp->Parameters.FileSystemControl.FsControlCode == FSCTL_INVALIDATE_VOLUMES) || - + (IrpSp->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL && IrpSp->MinorFunction == IRP_MN_MOUNT_VOLUME ) || @@ -1681,7 +1681,7 @@ Return Value: if (IrpSp->DeviceObject != CdData.FileSystemDeviceObject) { NewIrpContext->Vcb = &((PVOLUME_DEVICE_OBJECT) IrpSp->DeviceObject)->Vcb; - + } // @@ -2168,7 +2168,7 @@ Return Value: PAGED_CODE(); UNREFERENCED_PARAMETER( IrpContext ); - + Fcb = (PFCB) RtlEnumerateGenericTableWithoutSplaying( &Vcb->FcbTable, RestartKey ); if (Fcb != NULL) { @@ -2243,7 +2243,7 @@ Return Value: // Zero the command block. This conveniently corresponds to an // LBA mode READ_TOC request. // - + RtlZeroMemory( &Command, sizeof( Command)); RetryReadToc: @@ -2343,7 +2343,7 @@ RetryReadToc: // Knock 2.5 minutes off the current track to hide the final leadin. // 2.5 min = 150 sec = (x 75) 11250 frames (sectors). // - + SwapCopyUchar4( &Address, &Track->Address); Address -= 11250; SwapCopyUchar4( &Track->Address, &Address); @@ -2557,9 +2557,9 @@ Return Value: PFCB_NONPAGED FcbNonpaged; PAGED_CODE(); - + UNREFERENCED_PARAMETER( IrpContext ); - + // // Allocate the non-paged pool and initialize the various // synchronization objects. @@ -2610,9 +2610,9 @@ Return Value: { PAGED_CODE(); - + UNREFERENCED_PARAMETER( IrpContext ); - + ExDeleteResourceLite( &FcbNonpaged->FcbResource ); CdDeallocateFcbNonpaged( IrpContext, FcbNonpaged ); @@ -2708,7 +2708,7 @@ Return Value: { PAGED_CODE(); - + UNREFERENCED_PARAMETER( FcbTable ); return( FsRtlAllocatePoolWithTag( CdPagedPool, ByteSize, TAG_FCB_TABLE )); @@ -2793,7 +2793,7 @@ Return Value: PAGED_CODE(); UNREFERENCED_PARAMETER( IrpContext ); - + // // Check if there are two tracks or fewer. // @@ -2813,10 +2813,10 @@ Return Value: // while (ThisTrack != LastTrack) { - + SwapCopyUchar4( &Address, ThisTrack->Address); CdLbnToMmSsFf( Address, (PUCHAR)&MsfAddress); - + SerialNumber += MsfAddress; ThisTrack += 1; } diff --git a/filesys/cdfs/workque.c b/filesys/cdfs/workque.c index ee548826..3e80a56d 100644 --- a/filesys/cdfs/workque.c +++ b/filesys/cdfs/workque.c @@ -401,12 +401,14 @@ Return Value: // Send it off..... // -#pragma prefast(suppress:28155, "the function prototype is correct") +#pragma prefast(suppress: 28155, "the function prototype is correct") +#pragma warning(suppress: 4996) ExInitializeWorkItem( &IrpContext->WorkQueueItem, CdFspDispatch, IrpContext ); #pragma prefast(suppress: 28159, "prefast believes this routine is obsolete, but it is ok for CDFS to continue using it") +#pragma warning(suppress: 4996) ExQueueWorkItem( &IrpContext->WorkQueueItem, CriticalWorkQueue ); return; diff --git a/filesys/fastfat/cachesup.c b/filesys/fastfat/cachesup.c index 791a7378..f5a7ec22 100644 --- a/filesys/fastfat/cachesup.c +++ b/filesys/fastfat/cachesup.c @@ -184,7 +184,7 @@ Arguments: } -_Requires_lock_held_(_Global_critical_region_) +_Requires_lock_held_(_Global_critical_region_) VOID FatPrepareWriteVolumeFile ( IN PIRP_CONTEXT IrpContext, @@ -228,7 +228,7 @@ Arguments: Reversible - Supplies TRUE if the specified range of modification should be repinned so that the operation can be reversed in a controlled fashion if errors are encountered. - + Zero - Supplies TRUE if the specified range of bytes should be zeroed --*/ @@ -237,7 +237,7 @@ Arguments: LARGE_INTEGER Vbo; PAGED_CODE(); - + // // Check to see that all references are within the Bios Parameter Block // or the fat(s). @@ -284,7 +284,7 @@ Arguments: try { if (Zero) { - + RtlZeroMemory( *Buffer, ByteCount ); } @@ -349,7 +349,7 @@ Arguments: LARGE_INTEGER Vbo; PAGED_CODE(); - + DebugTrace(+1, Dbg, "FatReadDirectoryFile\n", 0); DebugTrace( 0, Dbg, "Dcb = %p\n", Dcb); DebugTrace( 0, Dbg, "StartingVbo = %08lx\n", StartingVbo); @@ -484,11 +484,11 @@ Arguments: Buffer - Returns a pointer to the sectors, which is valid until unpinned Zero - Supplies TRUE if the specified range of bytes should be zeroed - + Reversible - Supplies TRUE if the specified range of modification should be repinned so that the operation can be reversed in a controlled fashion if errors are encountered. - + Status - Returns the status of the operation. --*/ @@ -503,7 +503,7 @@ Arguments: ULONG MappingGranularity = PAGE_SIZE; PAGED_CODE(); - + DebugTrace(+1, Dbg, "FatPrepareWriteDirectoryFile\n", 0); DebugTrace( 0, Dbg, "Dcb = %p\n", Dcb); DebugTrace( 0, Dbg, "StartingVbo = %08lx\n", (ULONG)StartingVbo); @@ -586,22 +586,22 @@ Arguments: // // We must pin in terms of pages below the boundary of the initial request. // Once we pass the end of the request, we are free to expand the pin size to - // VACB_MAPPING_GRANULARITY. This will prevent Cc from returning OBCBs - // and hence will prevent bugchecks when we then attempt to repin one, yet + // VACB_MAPPING_GRANULARITY. This will prevent Cc from returning OBCBs + // and hence will prevent bugchecks when we then attempt to repin one, yet // allow us to be more efficient by pinning in 256KB chunks instead of 4KB pages. // if (Vbo.QuadPart > StartingVbo + InitialRequest) { - + MappingGranularity = VACB_MAPPING_GRANULARITY; } // - // If the first and final byte are both described by the same page, pin + // If the first and final byte are both described by the same page, pin // the entire range. Note we pin in pages to prevent cache manager from // returning OBCBs, which would result in a bugcheck on CcRepinBcb. // - + if ((Vbo.QuadPart / MappingGranularity) == ((Vbo.QuadPart + ByteCount - 1) / MappingGranularity)) { @@ -619,7 +619,7 @@ Arguments: BooleanFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT), &LocalBcb, &LocalBuffer )) { - + // // Could not read the data without waiting (cache miss). // @@ -630,7 +630,7 @@ Arguments: // // Update our caller with the beginning of their request. // - + if (*Buffer == NULL) { *Buffer = LocalBuffer; @@ -640,13 +640,13 @@ Arguments: DbgDoit( IrpContext->PinCount += 1 ) if (Zero) { - + // // We set this guy dirty right now so that we can raise CANT_WAIT when // it needs to be done. It'd be beautiful if we could noop the read IO // since we know we don't care about it. // - + RtlZeroMemory( LocalBuffer, BytesToPin ); CcSetDirtyPinnedData( LocalBcb, NULL ); } @@ -655,7 +655,7 @@ Arguments: Vbo.QuadPart += BytesToPin; if (*Bcb != LocalBcb) { - + FatRepinBcb( IrpContext, LocalBcb ); FatUnpinBcb( IrpContext, LocalBcb ); } @@ -684,14 +684,14 @@ Arguments: FatUnpinBcb( IrpContext, LocalBcb ); } - + FatUnpinBcb(IrpContext, *Bcb); // // These steps are carefully arranged - FatTruncateFileAllocation can raise. // Make sure we unpin the buffer. If FTFA raises, the effect should be benign. // - + if (UnwindWeAllocatedDiskSpace == TRUE) { // @@ -734,32 +734,32 @@ FatIsCurrentOperationSynchedForDcbTeardown ( ULONG Index = 0; PAGED_CODE(); - + // // While mounting, we're OK without having to own anything. // - + if (Stack->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL && Stack->MinorFunction == IRP_MN_MOUNT_VOLUME) { return TRUE; } - + // // With the Vcb held, the close path is blocked out. // - + if (ExIsResourceAcquiredSharedLite( &Dcb->Vcb->Resource ) || ExIsResourceAcquiredExclusiveLite( &Dcb->Vcb->Resource )) { return TRUE; } - + // // Accept this assertion at face value. It comes from GetDirentForFcbOrDcb, // and is reliable. // - + if (FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_PARENT_BY_CHILD )) { return TRUE; @@ -776,29 +776,29 @@ FatIsCurrentOperationSynchedForDcbTeardown ( } if (Stack->FileObject) { - + ToCheck[Index++] = Stack->FileObject; } ToCheck[Index] = NULL; - + // // If the fileobjects we have are for this dcb or a child of it, we are // also guaranteed that this dcb isn't going anywhere (even without // the Vcb). // - + for (Index = 0; ToCheck[Index] != NULL; Index++) { - + (VOID) FatDecodeFileObject( ToCheck[Index], &Vcb, &Fcb, &Ccb ); while ( Fcb ) { - + if (Fcb == Dcb) { - + return TRUE; } - + Fcb = Fcb->ParentDcb; } } @@ -832,7 +832,7 @@ Return Value: { PAGED_CODE(); - + DebugTrace(+1, Dbg, "FatOpenDirectoryFile\n", 0); DebugTrace( 0, Dbg, "Dcb = %p\n", Dcb); @@ -843,7 +843,7 @@ Return Value: // // I really wish we had a proper Fcb synchronization model (like CDFS/UDFS/NTFS). // - + NT_ASSERT( FatIsCurrentOperationSynchedForDcbTeardown( IrpContext, Dcb )); // @@ -925,7 +925,7 @@ Return Value: InterlockedIncrement( (LONG*)&Dcb->Specific.Dcb.DirectoryFileOpenCount ); Dcb->Specific.Dcb.DirectoryFile = DirectoryFileObject; - + // // Indicate we're happy with the fileobject now. // @@ -940,9 +940,9 @@ Return Value: // // Rip the object up if we couldn't get the close context. // - + if (DirectoryFileObject) { - + ObDereferenceObject( DirectoryFileObject ); } } @@ -1002,7 +1002,7 @@ Return Value: PDEVICE_OBJECT RealDevice; PAGED_CODE(); - + DebugTrace(+1, Dbg, "FatOpenEaFile\n", 0); DebugTrace( 0, Dbg, "EaFcb = %p\n", EaFcb); @@ -1051,7 +1051,7 @@ Return Value: EaFcb ); CcSetAdditionalCacheAttributes( EaFileObject, TRUE, TRUE ); - + } finally { // @@ -1060,9 +1060,9 @@ Return Value: // we lost trying to build the cache map - in which case we're // OK for the close context if we have to. // - + if (AbnormalTermination()) { - + ObDereferenceObject( EaFileObject ); } } @@ -1088,26 +1088,26 @@ Routine Description: This routine shuts down the ea file. Usually this is required when the volume begins to leave the system: after verify, dismount, deletion, pnp. - + Arguments: Vcb - the volume to close the ea file on - + FlushFirst - whether the file should be flushed - + Return Value: None. As a side effect, the EA fileobject in the Vcb is cleared. - + Caller must have the Vcb exclusive. - + --*/ { PFILE_OBJECT EaFileObject = Vcb->VirtualEaFile; PAGED_CODE(); - + DebugTrace(+1, Dbg, "FatCloseEaFile\n", 0); DebugTrace( 0, Dbg, "Vcb = %p\n", Vcb); @@ -1138,12 +1138,12 @@ Return Value: ObDereferenceObject( EaFileObject ); } - + DebugTrace(-1, Dbg, "FatCloseEaFile -> %p\n", EaFileObject); } -_Requires_lock_held_(_Global_critical_region_) +_Requires_lock_held_(_Global_critical_region_) VOID FatSetDirtyBcb ( IN PIRP_CONTEXT IrpContext, @@ -1166,13 +1166,13 @@ Routine Description: Arguments: Bcb - Supplies the Bcb being set dirty - + Vcb - Supplies the volume being marked dirty - + Reversible - Supplies TRUE if the specified range of bcb should be repinned so that the changes can be reversed in a controlled fashion if errors are encountered. - + Return Value: None. @@ -1190,7 +1190,7 @@ Return Value: // if (Reversible) { - + FatRepinBcb( IrpContext, Bcb ); } @@ -1260,7 +1260,7 @@ Return Value: // // We use a shorter volume clean timer for hot plug volumes. // - + CleanVolumeTimer.QuadPart = FlagOn( Vcb->VcbState, VCB_STATE_FLAG_DEFERRED_FLUSH) ? (LONG)-1500*1000*10 : (LONG)-8*1000*1000*10; @@ -1342,7 +1342,7 @@ Return Value: ULONG i; PAGED_CODE(); - + DebugTrace(+1, Dbg, "FatRepinBcb\n", 0 ); DebugTrace( 0, Dbg, "IrpContext = %p\n", IrpContext ); DebugTrace( 0, Dbg, "Bcb = %p\n", Bcb ); @@ -1432,7 +1432,7 @@ Return Value: PFCB FcbOrDcb = NULL; PAGED_CODE(); - + DebugTrace(+1, Dbg, "FatUnpinRepinnedBcbs\n", 0 ); DebugTrace( 0, Dbg, "IrpContext = %p\n", IrpContext ); @@ -1453,21 +1453,21 @@ Return Value: // Extract main FCB pointer from the irp context - we // will need it later to detect new file creation operation. // - + if (IrpContext->MajorFunction == IRP_MJ_CREATE && IrpContext->OriginatingIrp != NULL) { PIO_STACK_LOCATION IrpSp; - + IrpSp = IoGetCurrentIrpStackLocation( IrpContext->OriginatingIrp ); - + if (IrpSp != NULL && IrpSp->FileObject != NULL && IrpSp->FileObject->FsContext != NULL) { - + FcbOrDcb = IrpSp->FileObject->FsContext; } } - + // // If the request is write through or the media is deferred flush, // unpin the bcb's write through. @@ -1496,7 +1496,7 @@ Return Value: IO_STATUS_BLOCK Iosb; - if (WriteThroughToDisk && + if (WriteThroughToDisk && FlagOn(IrpContext->Vcb->VcbState, VCB_STATE_FLAG_DEFERRED_FLUSH)) { FileObject = CcGetFileObjectFromBcb( Repinned->Bcb[i] ); @@ -1524,9 +1524,9 @@ Return Value: (IrpContext->MajorFunction != IRP_MJ_CLEANUP) && (IrpContext->MajorFunction != IRP_MJ_FLUSH_BUFFERS) && (IrpContext->MajorFunction != IRP_MJ_SET_INFORMATION) - + && - + // // WinSE bug #307418 "Occasional data corruption when // standby/resume while copying files to removable FAT @@ -1540,7 +1540,7 @@ Return Value: // Instead FatCommonCreate() will unroll the file creation // changes for these pages. // - + !(IrpContext->MajorFunction == IRP_MJ_CREATE && Iosb.Status == STATUS_VERIFY_REQUIRED && FcbOrDcb != NULL && @@ -1567,26 +1567,26 @@ Return Value: PREPINNED_BCBS RepinnedToPurge = Repinned; while( RepinnedToPurge != NULL ) { - + for (j = k; j < REPINNED_BCBS_ARRAY_SIZE; j++) { if (RepinnedToPurge->Bcb[j] != NULL) { - + if (CcGetFileObjectFromBcb( RepinnedToPurge->Bcb[j] ) == FileObject) { CcUnpinRepinnedBcb( RepinnedToPurge->Bcb[j], FALSE, &Iosb ); - + RepinnedToPurge->Bcb[j] = NULL; } } } - + RepinnedToPurge = RepinnedToPurge->Next; k = 0; } - + CcPurgeCacheSection( FileObject->SectionObjectPointer, NULL, 0, @@ -1644,7 +1644,7 @@ Return Value: if (!FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_DISABLE_RAISE )) { if (IrpContext->OriginatingIrp) { IrpContext->OriginatingIrp->IoStatus = RaiseIosb; - } + } FatNormalizeAndRaiseStatus( IrpContext, RaiseIosb.Status ); } } @@ -1679,7 +1679,7 @@ FatZeroData ( BOOLEAN Finished; PAGED_CODE(); - + SectorSize = (ULONG)Vcb->Bpb.BytesPerSector; ZeroStart.LowPart = (StartingZero + (SectorSize - 1)) & ~(SectorSize - 1); @@ -1688,23 +1688,23 @@ FatZeroData ( // Detect overflow if we were asked to zero in the last sector of the file, // which must be "zeroed" already (or we're in trouble). // - + if (StartingZero != 0 && ZeroStart.LowPart == 0) { - + return TRUE; } // // Note that BeyondZeroEnd can take the value 4gb. // - + BeyondZeroEnd.QuadPart = ((ULONGLONG) StartingZero + ByteCount + (SectorSize - 1)) & (~((LONGLONG) SectorSize - 1)); // // If we were called to just zero part of a sector we are in trouble. // - + if ( ZeroStart.QuadPart == BeyondZeroEnd.QuadPart ) { return TRUE; @@ -1747,7 +1747,7 @@ Return Value: PIO_STACK_LOCATION IrpSp; PAGED_CODE(); - + DebugTrace(+1, Dbg, "FatCompleteMdl\n", 0 ); DebugTrace( 0, Dbg, "IrpContext = %p\n", IrpContext ); DebugTrace( 0, Dbg, "Irp = %p\n", Irp ); @@ -1828,7 +1828,7 @@ Return Value: UNREFERENCED_PARAMETER( IrpContext ); PAGED_CODE(); - + KeInitializeEvent( &UninitializeCompleteEvent.Event, SynchronizationEvent, FALSE); @@ -1884,7 +1884,7 @@ Arguments: LARGE_INTEGER Vbo; PAGED_CODE(); - + DebugTrace(+1, Dbg, "FatPinMappedData\n", 0); DebugTrace( 0, Dbg, "Dcb = %p\n", Dcb); DebugTrace( 0, Dbg, "StartingVbo = %08lx\n", StartingVbo); @@ -1963,9 +1963,9 @@ FatPrefetchPages ( goto Cleanup; } - ReadList = ExAllocatePoolWithTag( PagedPool, - FIELD_OFFSET( READ_LIST, List ) + PageCount * sizeof( FILE_SEGMENT_ELEMENT ), - ' taF' ); + ReadList = ExAllocatePoolZero( PagedPool, + FIELD_OFFSET( READ_LIST, List ) + PageCount * sizeof( FILE_SEGMENT_ELEMENT ), + ' taF' ); if (ReadList == NULL) { diff --git a/filesys/fastfat/deviosup.c b/filesys/fastfat/deviosup.c index 3fae4a28..1010b03d 100644 --- a/filesys/fastfat/deviosup.c +++ b/filesys/fastfat/deviosup.c @@ -180,7 +180,7 @@ FatSingleNonAlignedSync ( #else #define FatUpdateIOCountersPCW(IsAWrite,Count) #endif - + #ifdef ALLOC_PRAGMA #pragma alloc_text(PAGE, FatMultipleAsync) #pragma alloc_text(PAGE, FatSingleAsync) @@ -505,7 +505,7 @@ Return Value: AssocIrp = IoMakeAssociatedIrp( Irp, (CCHAR)(DeviceObject->StackSize + 1) ); } - + if (AssocIrp == NULL) { AssocIrp = Irp; @@ -527,7 +527,7 @@ Return Value: // Note that since we failed to launch this associated Irp, that the completion // code at the bottom will take care of completing the master Irp. // - + if (!NT_SUCCESS(Irp->IoStatus.Status)) { NT_ASSERT( IrpCount ); @@ -535,22 +535,22 @@ Return Value: } } else { - + // // Indicate we used an associated Irp. // IrpCount -= 1; } - + // // With an associated IRP, we must take over the first stack location so // we can have one to put the completion routine on. When re-using the // master IRP, its already there. // - + if (!IrpIsMaster) { - + // // Get the first IRP stack location in the associated Irp // @@ -572,7 +572,7 @@ Return Value: // NextIrpSp->DeviceObject = IrpSp->DeviceObject; - + } else { // @@ -602,7 +602,7 @@ Return Value: // if (IrpIsMaster) { - + IoSetCompletionRoutine( AssocIrp, FatPagingFileCompletionRoutineCatch, &Context, @@ -611,7 +611,7 @@ Return Value: TRUE ); } else { - + IoSetCompletionRoutine( AssocIrp, FatPagingFileCompletionRoutine, Irp, @@ -656,7 +656,7 @@ Return Value: // if (IrpIsMaster) { - + KeWaitForSingleObject( &Context.Event, Executive, KernelMode, FALSE, NULL ); IrpIsMaster = MdlIsReserve = FALSE; @@ -669,7 +669,7 @@ Return Value: // associated Irp, and thus the completion code at the bottom will take care // of that for us. // - + if (!NT_SUCCESS(Irp->IoStatus.Status)) { NT_ASSERT( IrpCount ); @@ -695,14 +695,14 @@ Return Value: // // Advance the Lbo/Vbo if we have more to do in the current run. // - + NextLbo += NextByteCount; NextVbo += NextByteCount; NextByteCount = RemainingByteCount; - + } else { - + CurrentIndex += 1; if ( CurrentIndex <= LastIndex ) { @@ -724,11 +724,11 @@ Return Value: // If we didn't get enough associated Irps going to make this asynchronous, we // twiddle our thumbs and wait for those we did launch to complete. // - + if (IrpCount) { while (Irp->AssociatedIrp.IrpCount != IrpCount) { - + KeDelayExecutionThread (KernelMode, FALSE, &Fat30Milliseconds); } @@ -760,7 +760,7 @@ Arguments: Irp - Supplies the requesting Irp. ByteCount - The lengh of the operation. - + Return Value: None. @@ -862,7 +862,7 @@ Return Value: -_Requires_lock_held_(_Global_critical_region_) +_Requires_lock_held_(_Global_critical_region_) NTSTATUS FatNonCachedIo ( IN PIRP_CONTEXT IrpContext, @@ -871,7 +871,7 @@ FatNonCachedIo ( IN ULONG StartingVbo, IN ULONG ByteCount, IN ULONG UserByteCount, - IN ULONG StreamFlags + IN ULONG StreamFlags ) /*++ @@ -892,7 +892,7 @@ Arguments: StartingVbo - The starting point for the operation. ByteCount - The lengh of the operation. - + UserByteCount - The last byte the user can see, rest to be zeroed. StreamFlags - flag to indicate special attributes for a NonCachedIo. @@ -1107,7 +1107,7 @@ Return Value: Stats->Fat.NonCachedDiskWrites += 1; } } - + DebugTrace( 0, Dbg, "Passing 1 Irp on to Disk Driver\n", 0 ); FatSingleAsync( IrpContext, @@ -1192,7 +1192,7 @@ Return Value: IoRuns[NextRun].Offset = BufferOffset; IoRuns[NextRun].ByteCount = NextByteCount; NextRun += 1; - + // // Now adjust everything for the next pass through the loop. // @@ -1218,7 +1218,7 @@ Return Value: &NextByteCount ); - NT_ASSERT(NextVbo == StartingVbo); + NT_ASSERT(NextVbo == StartingVbo); } @@ -1275,7 +1275,7 @@ Return Value: } -_Requires_lock_held_(_Global_critical_region_) +_Requires_lock_held_(_Global_critical_region_) VOID FatNonCachedNonAlignedRead ( IN PIRP_CONTEXT IrpContext, @@ -1856,7 +1856,7 @@ Return Value: // // For async requests if we acquired locks, transition the lock owners to an - // object, since when we return this thread could go away before request + // object, since when we return this thread could go away before request // completion, and the resource package may try to boost priority. // @@ -1932,7 +1932,7 @@ Return Value: if (!ExceptionExpected) { NT_ASSERT( ExceptionExpected ); -#pragma prefast( suppress:28159, "things are seriously wrong if we get here" ) +#pragma prefast( suppress:28159, "things are seriously wrong if we get here" ) FatBugCheck( 0, 0, 0 ); } @@ -2070,15 +2070,15 @@ Return Value: // // If this I/O requires override verify, bypass the verify logic. // - + if (FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_OVERRIDE_VERIFY )) { - + SetFlag( IrpSp->Flags, SL_OVERRIDE_VERIFY_VOLUME ); } // // For async requests if we acquired locks, transition the lock owners to an - // object, since when we return this thread could go away before request + // object, since when we return this thread could go away before request // completion, and the resource package may try to boost priority. // @@ -2103,7 +2103,7 @@ Return Value: // // Back up a copy of the IrpContext flags for later use in async completion. // - + IrpContext->FatIoContext->IrpContextFlags = IrpContext->Flags; // @@ -2281,9 +2281,9 @@ Return Value: // // If this I/O requires override verify, bypass the verify logic. // - + if (FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_OVERRIDE_VERIFY )) { - + SetFlag( IrpSp->Flags, SL_OVERRIDE_VERIFY_VOLUME ); } @@ -2543,11 +2543,11 @@ Return Value: #endif MasterIrp->IoStatus = Irp->IoStatus; - + } NT_ASSERT( !(NT_SUCCESS( Irp->IoStatus.Status ) && Irp->IoStatus.Information == 0 )); - + if (InterlockedDecrement(&Context->IrpCount) == 0) { FatDoCompletionZero( MasterIrp, Context ); @@ -2569,19 +2569,19 @@ Return Value: IoGetCurrentIrpStackLocation(MasterIrp)->MajorFunction == IRP_MJ_READ ? FO_FILE_FAST_IO_READ : FO_FILE_MODIFIED ); } - + } else { // // Post STATUS_VERIFY_REQUIRED failures. Only post top level IRPs, because recursive I/Os // cannot process volume verification. // - - if (!FlagOn(Context->IrpContextFlags, IRP_CONTEXT_FLAG_RECURSIVE_CALL) && + + if (!FlagOn(Context->IrpContextFlags, IRP_CONTEXT_FLAG_RECURSIVE_CALL) && (MasterIrp->IoStatus.Status == STATUS_VERIFY_REQUIRED)) { PostRequest = TRUE; - } - + } + } // @@ -2612,7 +2612,7 @@ Return Value: } if (Context->Wait.Async.Resource2 != NULL) { - + ExReleaseResourceForThreadLite( Context->Wait.Async.Resource2, Context->Wait.Async.ResourceThreadId ); } @@ -2634,22 +2634,22 @@ Return Value: PIRP_CONTEXT IrpContext = NULL; try { - + IrpContext = FatCreateIrpContext(Irp, TRUE ); ClearFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_RECURSIVE_CALL); FatFsdPostRequest( IrpContext, Irp ); Status = STATUS_MORE_PROCESSING_REQUIRED; - + } except( FatExceptionFilter(NULL, GetExceptionInformation()) ) { // // If we failed to post the IRP, we just have to return the failure // to the user. :( // - + NOTHING; } - } + } } DebugTrace(-1, Dbg, "FatMultiAsyncCompletionRoutine -> SUCCESS\n", 0 ); @@ -2672,36 +2672,36 @@ Routine Description: This routine attempts to guarantee that the media is marked dirty with the surface test bit if a paging file IO fails. - + The work done here has several basic problems - + 1) when paging file writes start failing, this is a good sign that the rest of the system is about to fall down around us - + 2) it has no forward progress guarantee - + With Whistler, it is actually quite intentional that we're rejiggering the paging file write path to make forward progress at all times. This means that the cases where it *does* fail, we're truly seeing media errors and this is probably going to mean the paging file is going to stop working very soon. - + It'd be nice to make this guarantee progress. It would need - + 1) a guaranteed worker thread which can only be used by items which will make forward progress (i.e., not block out this one) - + 2) the virtual volume file's pages containing the boot sector and 1st FAT entry would have to be pinned resident and have a guaranteed mapping address - + 3) mark volume would have to have a stashed irp/mdl and roll the write irp, or use a generalized mechanism to guarantee issue of the irp - + 4) the lower stack would have to guarantee progress - + Of these, 1 and 4 may actually exist shortly. - + Arguments: Irp - Pointer to the associated Irp which is being failed. @@ -2736,7 +2736,7 @@ Return Value: // If we can't get pool, oh well.... // - Packet = ExAllocatePoolWithTag(NonPagedPoolNx, sizeof(CLEAN_AND_DIRTY_VOLUME_PACKET), ' taF'); + Packet = ExAllocatePoolZero(NonPagedPoolNx, sizeof(CLEAN_AND_DIRTY_VOLUME_PACKET), ' taF'); if ( Packet ) { @@ -2744,11 +2744,14 @@ Return Value: Packet->Irp = Irp; Packet->Event = Event; +#pragma prefast( suppress: 28155, "the function prototype is correct" ) +#pragma warning( suppress:4996 ) ExInitializeWorkItem( &Packet->Item, &FatFspMarkVolumeDirtyWithRecover, Packet ); #pragma prefast( suppress:28159, "prefast indicates this is obsolete, but it is ok for fastfat to use it" ) +#pragma warning( suppress:4996 ) ExQueueWorkItem( &Packet->Item, CriticalWorkQueue ); Status = STATUS_MORE_PROCESSING_REQUIRED; @@ -2788,9 +2791,9 @@ Routine Description: worker item to write out the dirty bit so that the next time we run we will do a autochk /r. This is not forward progress guaranteed at the moment. - + Clean up the Mdl used for this partial request. - + Note that if the Irp is failing, the error code is already where we want it. @@ -2815,7 +2818,7 @@ Return Value: UNREFERENCED_PARAMETER( DeviceObject ); DebugTrace(+1, Dbg, "FatPagingFileCompletionRoutineCatch, Context = %p\n", Context ); - + // // Cleanup the existing Mdl, perhaps by returning the reserve. // @@ -2824,7 +2827,7 @@ Return Value: MmPrepareMdlForReuse( Irp->MdlAddress ); KeSetEvent( &FatReserveEvent, 0, FALSE ); - + } else { IoFreeMdl( Irp->MdlAddress ); @@ -2851,7 +2854,7 @@ Return Value: } return STATUS_MORE_PROCESSING_REQUIRED; - + } @@ -3104,7 +3107,7 @@ Return Value: { NTSTATUS Status = STATUS_SUCCESS; - + PFAT_IO_CONTEXT Context = Contxt; BOOLEAN PostRequest = FALSE; @@ -3140,7 +3143,7 @@ Return Value: DbgBreakPoint(); } #endif - + #ifdef SYSCACHE_COMPILE DbgPrint( "FAT SYSCACHE: SingleAsync (IRP %08x) -> %08x\n", Irp, Irp->IoStatus ); #endif @@ -3149,8 +3152,8 @@ Return Value: // Post STATUS_VERIFY_REQUIRED failures. Only post top level IRPs, because recursive I/Os // cannot process volume verification. // - - if (!FlagOn(Context->IrpContextFlags, IRP_CONTEXT_FLAG_RECURSIVE_CALL) && + + if (!FlagOn(Context->IrpContextFlags, IRP_CONTEXT_FLAG_RECURSIVE_CALL) && (Irp->IoStatus.Status == STATUS_VERIFY_REQUIRED)) { PostRequest = TRUE; } @@ -3180,13 +3183,13 @@ Return Value: // if (Context->Wait.Async.Resource != NULL) { - + ExReleaseResourceForThreadLite( Context->Wait.Async.Resource, Context->Wait.Async.ResourceThreadId ); } - + if (Context->Wait.Async.Resource2 != NULL) { - + ExReleaseResourceForThreadLite( Context->Wait.Async.Resource2, Context->Wait.Async.ResourceThreadId ); } @@ -3208,19 +3211,19 @@ Return Value: PIRP_CONTEXT IrpContext = NULL; try { - + IrpContext = FatCreateIrpContext(Irp, TRUE ); - ClearFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_RECURSIVE_CALL); + ClearFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_RECURSIVE_CALL); FatFsdPostRequest( IrpContext, Irp ); Status = STATUS_MORE_PROCESSING_REQUIRED; - + } except( FatExceptionFilter(NULL, GetExceptionInformation()) ) { // // If we failed to post the IRP, we just have to return the failure // to the user. :( // - + NOTHING; } } @@ -3328,7 +3331,7 @@ Routine Description: This routine conditionally maps the user buffer for the current I/O request in the specified mode. If the buffer is already mapped, it just returns its address. - + Note that this is the *input/output* buffer. Arguments: @@ -3354,7 +3357,7 @@ Return Value: if (Irp->MdlAddress == NULL) { return Irp->UserBuffer; - + } else { PVOID Address = MmGetSystemAddressForMdlSafe( Irp->MdlAddress, NormalPagePriority | MdlMappingNoExecute ); @@ -3382,7 +3385,7 @@ Routine Description: This routine conditionally buffers the user buffer for the current I/O request. If the buffer is already buffered, it just returns its address. - + Note that this is the *input* buffer. Arguments: @@ -3390,7 +3393,7 @@ Arguments: Irp - Pointer to the Irp for the request. BufferLength - Length of user buffer. - + Return Value: Buffered address. @@ -3407,12 +3410,12 @@ Return Value: // // Handle the no buffer case. // - + if (BufferLength == 0) { return NULL; } - + // // If there is no system buffer we must have been supplied an Mdl // describing the users input buffer, which we will now snapshot. @@ -3440,15 +3443,15 @@ Return Value: BufferLength ); } except (EXCEPTION_EXECUTE_HANDLER) { - + NTSTATUS Status; - + Status = GetExceptionCode(); FatRaiseStatus( IrpContext, FsRtlIsNtstatusExpected(Status) ? Status : STATUS_INVALID_USER_BUFFER ); } } - + return Irp->AssociatedIrp.SystemBuffer; } @@ -3521,7 +3524,7 @@ Return Value: // We fill in the UserIosb manually below, // So passing NULL for the final parameter is ok in this special case. // -#pragma warning(suppress: 6387) +#pragma warning(suppress: 6387) Irp = IoBuildDeviceIoControlRequest( IOCTL_DISK_MEDIA_REMOVAL, Vcb->TargetDeviceObject, &Prevent, @@ -3560,7 +3563,7 @@ Return Value: Status = IoCallDriver( Vcb->TargetDeviceObject, Irp ); if (Status == STATUS_PENDING) { - + (VOID) KeWaitForSingleObject( &SyncContext.Event, Executive, KernelMode, diff --git a/filesys/fastfat/fatinit.c b/filesys/fastfat/fatinit.c index 446fb0e8..af9b83b1 100644 --- a/filesys/fastfat/fatinit.c +++ b/filesys/fastfat/fatinit.c @@ -194,7 +194,7 @@ Return Value: FatFastIoDispatch.MdlWriteComplete = FsRtlMdlWriteCompleteDev; #pragma prefast( pop ) - + // // Initialize the filter callbacks we use. // @@ -240,7 +240,7 @@ Return Value: InitializeListHead( &FatData.AsyncCloseList ); InitializeListHead( &FatData.DelayedCloseList ); - + FatData.FatCloseItem = IoAllocateWorkItem( FatDiskFileSystemDeviceObject); if (FatData.FatCloseItem == NULL) { @@ -253,13 +253,12 @@ Return Value: // Allocate the zero page // - FatData.ZeroPage = ExAllocatePoolWithTag( NonPagedPoolNx, PAGE_SIZE, 'ZtaF' ); + FatData.ZeroPage = ExAllocatePoolZero( NonPagedPoolNx, PAGE_SIZE, 'ZtaF' ); if (FatData.ZeroPage == NULL) { IoDeleteDevice (FatDiskFileSystemDeviceObject); - IoDeleteDevice (FatCdromFileSystemDeviceObject); + IoDeleteDevice (FatCdromFileSystemDeviceObject); return STATUS_INSUFFICIENT_RESOURCES; } - RtlZeroMemory( FatData.ZeroPage, PAGE_SIZE ); // @@ -286,7 +285,7 @@ Return Value: case MmLargeSystem: default: - + MaxDepth = 16; FatMaxDelayedCloseCount = 16 * FAT_MAX_DELAYED_CLOSES; break; @@ -313,8 +312,8 @@ Return Value: FatData.OurProcess = PsGetCurrentProcess(); - // - // Setup the number of processors we support for statistics as the current number + // + // Setup the number of processors we support for statistics as the current number // running. // @@ -558,9 +557,9 @@ Return Value: RequestLength += 256; KeyValueInformation = (PKEY_VALUE_FULL_INFORMATION) - ExAllocatePoolWithTag(PagedPool, - RequestLength, - ' taF'); + ExAllocatePoolZero(PagedPool, + RequestLength, + ' taF'); if (!KeyValueInformation) { @@ -699,7 +698,7 @@ Return Value: RequestLength += 256; KeyValueInformation = (PKEY_VALUE_FULL_INFORMATION) - ExAllocatePoolWithTag(PagedPool, RequestLength, ' taF'); + ExAllocatePoolZero(PagedPool, RequestLength, ' taF'); if (!KeyValueInformation) { diff --git a/filesys/fastfat/verfysup.c b/filesys/fastfat/verfysup.c index 86fcacdf..85036602 100644 --- a/filesys/fastfat/verfysup.c +++ b/filesys/fastfat/verfysup.c @@ -198,7 +198,7 @@ Return Value: if (FcbCondition == FcbNeedsToBeVerified) { FatResetFcb( IrpContext, Fcb ); } - + } } @@ -300,7 +300,7 @@ Return Value: // DevMarkedForVerify = BooleanFlagOn(Vcb->Vpb->RealDevice->Flags, DO_VERIFY_VOLUME); - + // // We ALWAYS force CREATE requests on unmounted volumes through the // verify path. These requests could have been in limbo between @@ -351,7 +351,7 @@ Return Value: } -_Requires_lock_held_(_Global_critical_region_) +_Requires_lock_held_(_Global_critical_region_) VOID FatVerifyFcb ( IN PIRP_CONTEXT IrpContext, @@ -475,8 +475,8 @@ Return Value: default: DebugDump("Invalid FcbCondition\n", 0, Fcb); - -#pragma prefast( suppress:28159, "things are seriously wrong if we get here" ) + +#pragma prefast( suppress:28159, "things are seriously wrong if we get here" ) FatBugCheck( Fcb->FcbCondition, 0, 0 ); } @@ -545,7 +545,7 @@ Return Value: // #pragma prefast( push ) -#pragma prefast( disable: 28193, "this will always wait" ) +#pragma prefast( disable: 28193, "this will always wait" ) FatAcquireSharedGlobal( &IrpContext ); #pragma prefast( pop ) @@ -695,7 +695,7 @@ Return Value: // If we couldn't get pool, oh well.... // - Packet = ExAllocatePoolWithTag(NonPagedPoolNx, sizeof(CLEAN_AND_DIRTY_VOLUME_PACKET), ' taF'); + Packet = ExAllocatePoolZero(NonPagedPoolNx, sizeof(CLEAN_AND_DIRTY_VOLUME_PACKET), ' taF'); if ( Packet ) { @@ -708,9 +708,12 @@ Return Value: ClearFlag( Packet->Vcb->VcbState, VCB_STATE_FLAG_VOLUME_DIRTY ); +#pragma prefast( suppress: 28155, "the function prototype is correct" ) +#pragma warning( suppress:4996 ) ExInitializeWorkItem( &Packet->Item, &FatDeferredCleanVolume, Packet ); - + #pragma prefast( suppress:28159, "prefast indicates this is an obsolete API, but it is ok for fastfat to keep using it" ) +#pragma warning( suppress:4996 ) ExQueueWorkItem( &Packet->Item, CriticalWorkQueue ); } @@ -718,7 +721,7 @@ Return Value: } -_Requires_lock_held_(_Global_critical_region_) +_Requires_lock_held_(_Global_critical_region_) VOID FatMarkVolume ( IN PIRP_CONTEXT IrpContext, @@ -1408,7 +1411,7 @@ Return Value: PAGED_CODE(); UNREFERENCED_PARAMETER( IrpContext ); - + // // Don't do the two following operations for the Root Dcb // of a non FAT32 volume or paging files. Paging files!? @@ -1570,7 +1573,7 @@ Return Value: if (DirentBcb == NULL) { FatMarkFcbCondition( IrpContext, Fcb, FcbBad, FALSE ); - + return; } @@ -1607,7 +1610,7 @@ Return Value: || !FatMatchFileSize(IrpContext, Dirent, Fcb ) - + || (FirstClusterOfFile != Fcb->FirstClusterOfFile) @@ -1761,12 +1764,12 @@ Return Value: default: DebugDump("Invalid VcbCondition\n", 0, Vcb); -#pragma prefast( suppress:28159, "things are seriously wrong if we get here" ) +#pragma prefast( suppress:28159, "things are seriously wrong if we get here" ) FatBugCheck( Vcb->VcbCondition, 0, 0 ); } } -_Requires_lock_held_(_Global_critical_region_) +_Requires_lock_held_(_Global_critical_region_) NTSTATUS FatPerformVerify ( _In_ PIRP_CONTEXT IrpContext, @@ -1900,7 +1903,7 @@ Return Value: FatReleaseVcb( IrpContext, Vcb); #pragma prefast( push ) -#pragma prefast( disable: 28137, "prefast wants the wait to be a constant, but that isn't possible for the way fastfat is designed" ) +#pragma prefast( disable: 28137, "prefast wants the wait to be a constant, but that isn't possible for the way fastfat is designed" ) #pragma prefast( disable: 28193 ) FatAcquireExclusiveGlobal( IrpContext ); #pragma prefast( pop ) diff --git a/filesys/fastfat/workque.c b/filesys/fastfat/workque.c index cb89b6b6..cd18de68 100644 --- a/filesys/fastfat/workque.c +++ b/filesys/fastfat/workque.c @@ -355,11 +355,14 @@ Return Value: // Send it off..... // +#pragma prefast( suppress: 28155, "the function prototype is correct" ) +#pragma warning( suppress:4996 ) ExInitializeWorkItem( &IrpContext->WorkQueueItem, FatFspDispatch, IrpContext ); #pragma prefast( suppress:28159, "prefast indicates this is an obsolete API but it is ok for fastfat to keep using it." ) +#pragma warning( suppress:4996 ) ExQueueWorkItem( &IrpContext->WorkQueueItem, CriticalWorkQueue ); return; diff --git a/filesys/fastfat/write.c b/filesys/fastfat/write.c index 7668fe08..9a5c594b 100644 --- a/filesys/fastfat/write.c +++ b/filesys/fastfat/write.c @@ -2980,11 +2980,14 @@ Return Value: // Send it off // +#pragma prefast( suppress: 28155, "the function prototype is correct ") +#pragma warning( suppress:4996 ) ExInitializeWorkItem( &FlushContext->Item, FatDeferredFlush, FlushContext ); #pragma prefast( suppress:28159, "prefast indicates this API is obsolete, but it's ok for fastfat to keep using it" ) +#pragma warning( suppress:4996 ) ExQueueWorkItem( &FlushContext->Item, CriticalWorkQueue ); } diff --git a/filesys/miniFilter/MetadataManager/support.c b/filesys/miniFilter/MetadataManager/support.c index 075acc3c..c96ac0a6 100644 --- a/filesys/miniFilter/MetadataManager/support.c +++ b/filesys/miniFilter/MetadataManager/support.c @@ -62,9 +62,9 @@ Return Value: { PAGED_CODE(); - String->Buffer = ExAllocatePoolWithTag( PagedPool, - String->MaximumLength, - FMM_STRING_TAG ); + String->Buffer = ExAllocatePoolZero( PagedPool, + String->MaximumLength, + FMM_STRING_TAG ); if (String->Buffer == NULL) { @@ -119,7 +119,7 @@ FmmTargetIsVolumeOpen ( Routine Description: This routine returns if the target object in this callback datastructure - is a volume. If the file object is NULL then assume this is NOT a volume + is a volume. If the file object is NULL then assume this is NOT a volume file object Arguments: @@ -147,7 +147,7 @@ Return Value: } NTSTATUS -FmmIsImplicitVolumeLock( +FmmIsImplicitVolumeLock( _In_ PFLT_CALLBACK_DATA Cbd, _Out_ PBOOLEAN IsLock ) @@ -158,17 +158,17 @@ Routine Description: This routine determines if an open is a implicit volume lock. Arguments - - Cbd - Supplies a pointer to the callbackData which + + Cbd - Supplies a pointer to the callbackData which declares the requested operation. IsLock - Supplies a pointer to a user allocated boolean which is used to tell the user whether the operation is an implied volume lock. Return Value: - + Returns STATUS_SUCCESS if the the function determined whether or not - the operation was a volume lock. On STATUS_SUCCESS it is safe to check + the operation was a volume lock. On STATUS_SUCCESS it is safe to check IsLock to get the answer. Otherwise, the check failed and we don't know if it is a lock or not. STATUS_INVALID_PARAMETER indicates that the volume's file system type is unrecognized by the check function. This is @@ -183,13 +183,13 @@ Return Value: PAGED_CODE(); // - // Get the instance context so we know + // Get the instance context so we know // which file system we are attached to. // status = FltGetInstanceContext( Cbd->Iopb->TargetInstance, &instanceContext ); - + if (!NT_SUCCESS( status )) { DebugTrace( DEBUG_TRACE_ERROR | DEBUG_TRACE_METADATA_OPERATIONS, @@ -208,6 +208,8 @@ Return Value: shareAccess = Cbd->Iopb->Parameters.Create.ShareAccess; +#pragma warning( push ) +#pragma warning( disable: 4061 ) switch (instanceContext->FilesystemType) { case FLT_FSTYPE_REFS: @@ -221,6 +223,7 @@ Return Value: status = STATUS_INVALID_PARAMETER; break; } +#pragma warning( pop ) FmmIsImplicitVolumeLockCleanup: diff --git a/filesys/miniFilter/NameChanger/nc.c b/filesys/miniFilter/NameChanger/nc.c index f28da557..9bcdc094 100644 --- a/filesys/miniFilter/NameChanger/nc.c +++ b/filesys/miniFilter/NameChanger/nc.c @@ -394,7 +394,7 @@ Logic: // // User mapping vars // - + NC_MAPPING_PATH UserPath; HANDLE UserParentHandle = 0; PFILE_OBJECT UserParentFileObj = NULL; @@ -402,23 +402,23 @@ Logic: IO_STATUS_BLOCK UserParentStatusBlock; PFILE_NAMES_INFORMATION FinalComponentQueryBuffer = NULL; ULONG FinalComponentQueryLength; - + // // Real Mapping vars // - + NC_MAPPING_PATH RealPath; HANDLE RealParentHandle = 0; PFILE_OBJECT RealParentFileObj = NULL; OBJECT_ATTRIBUTES RealParentAttributes; IO_STATUS_BLOCK RealParentStatusBlock; - + // // Context Vars // - + PNC_INSTANCE_CONTEXT InstanceContext = NULL; - + // // Temp vars // @@ -451,7 +451,7 @@ Logic: // We actually return here, rather than goto cleanup, because // we have not yet zeroed out the buffers in the mappings. // - + return STATUS_FLT_DO_NOT_ATTACH; } @@ -513,9 +513,9 @@ Logic: FinalComponentQueryLength = sizeof(FILE_NAMES_INFORMATION) + AlignToSize( max( NcGlobalData.UserMappingFinalComponentLong.Length, NcGlobalData.UserMappingFinalComponentShort.Length ), 8 ); - FinalComponentQueryBuffer = ExAllocatePoolWithTag( PagedPool, - FinalComponentQueryLength, - NC_NORMALIZE_NAME_TAG ); + FinalComponentQueryBuffer = ExAllocatePoolZero( PagedPool, + FinalComponentQueryLength, + NC_NORMALIZE_NAME_TAG ); if (FinalComponentQueryBuffer == NULL) { @@ -755,7 +755,7 @@ Logic: NcInitMapping( &InstanceContext->Mapping ); - + Status = NcBuildMapping( UserParentFileObj, RealParentFileObj, &NcGlobalData.UserMappingFinalComponentShort, @@ -933,14 +933,14 @@ Return Value: PAGED_CODE(); UNREFERENCED_PARAMETER( Flags ); - Status = FltGetInstanceContext( FltObjects->Instance, + Status = FltGetInstanceContext( FltObjects->Instance, &InstanceContext ); if (!NT_SUCCESS( Status )) { goto NcInstanceTeardownStartCleanup; } - + NcInstanceTeardownStartCleanup: if (InstanceContext) { @@ -985,7 +985,7 @@ Return Value: // // Import routines // - + NcCompatInit( ); Status = NcInitializeMapping( RegistryPath ); @@ -1230,19 +1230,19 @@ Return Value: // Obtain our handle context. We should only be called here // if we really have one. // - + Status = FltGetStreamHandleContext( FltObjects->Instance, FltObjects->FileObject, &HandleContext ); - + if (!NT_SUCCESS( Status )) { - + goto NcPostCleanupCallbackCleanup; - + } - + FLT_ASSERT( HandleContext != NULL ); - + NcStreamHandleContextNotCleanup( HandleContext ); } @@ -1407,7 +1407,7 @@ Return Value: break; case FSCTL_FIND_FILES_BY_SID: - + Status = NcPostFindFilesBySid( Data, FltObjects, CompletionContext, @@ -1416,12 +1416,12 @@ Return Value: break; #if FLT_MGR_WIN7 case FSCTL_LOOKUP_STREAM_FROM_CLUSTER: - + Status = NcPostLookupStreamFromCluster( Data, FltObjects, CompletionContext, Flags ); - + break; #endif @@ -1627,7 +1627,7 @@ Return Value: FLT_PREOP_CALLBACK_STATUS result; PAGED_CODE(); - + switch( Data->Iopb->Parameters.SetFileInformation.FileInformationClass ) { case FileDispositionInformation: @@ -1662,13 +1662,13 @@ Return Value: FltObjects, CompletionContext ); - break; + break; default: result = FLT_PREOP_SUCCESS_NO_CALLBACK; break; } - + return result; } @@ -1828,7 +1828,7 @@ Return Value: // TODO We need to pipe these through the existing create path if // possible. // - + return FLT_PREOP_DISALLOW_FASTIO; } @@ -1851,23 +1851,23 @@ Routine Description: Arguments: Instance - Instance pointer for the minifilter instance that this - callback routine is registered for. + callback routine is registered for. FileObject - Pointer to a file object for the file whose name is being - requested. + requested. Data - Pointer to the callback data structure for the operation during - which this name is being requested. + which this name is being requested. NameOptions - FLT_FILE_NAME_OPTIONS value that specifies the name format, - query method, and flags for this file name information query. + query method, and flags for this file name information query. CacheFileNameInformation - Pointer to a Boolean value specifying whether this name can be cached. Set to TRUE on output if the name can be - cached; set to FALSE otherwise. + cached; set to FALSE otherwise. OutputNameControl - Pointer to a Filter Manager-allocated FLT_NAME_CONTROL - structure to receive the file name on output. + structure to receive the file name on output. Return Value: @@ -1908,31 +1908,31 @@ Routine Description: Arguments: Instance - Instance pointer for the minifilter instance that this callback - routine is registered for. + routine is registered for. FileObject - Optionally points to a file object that the name query is taking place on. We can use this to flow transaction information to any recursive requests. ParentDirectory - Pointer to a UNICODE_STRING structure that contains the - name of the parent directory for this name component. + name of the parent directory for this name component. DeviceNameLength - Length, in bytes, of the parent directory name stored - in the structure that the ParentDirectory parameter points to. + in the structure that the ParentDirectory parameter points to. Component - Pointer to a UNICODE_STRING structure that contains the name - component to be expanded. + component to be expanded. ExpandComponentName - Pointer to a FILE_NAMES_INFORMATION structure that receives the expanded (normalized) file name information for the name - component. + component. ExpandComponentNameLength - Length, in bytes, of the buffer that the - ExpandComponentName parameter points to. + ExpandComponentName parameter points to. NormalizationContext - Pointer to minifilter-provided context information to be passed in any subsequent calls to this callback routine that are - made to normalize the remaining components in the same file name path. + made to normalize the remaining components in the same file name path. Return Value: @@ -1975,27 +1975,27 @@ Routine Description: Arguments: Instance - Instance pointer for the minifilter instance that this callback - routine is registered for. + routine is registered for. ParentDirectory - Pointer to a UNICODE_STRING structure that contains the - name of the parent directory for this name component. + name of the parent directory for this name component. DeviceNameLength - Length, in bytes, of the parent directory name stored - in the structure that the ParentDirectory parameter points to. + in the structure that the ParentDirectory parameter points to. Component - Pointer to a UNICODE_STRING structure that contains the name - component to be expanded. + component to be expanded. ExpandComponentName - Pointer to a FILE_NAMES_INFORMATION structure that receives the expanded (normalized) file name information for the name - component. + component. ExpandComponentNameLength - Length, in bytes, of the buffer that the - ExpandComponentName parameter points to. + ExpandComponentName parameter points to. NormalizationContext - Pointer to minifilter-provided context information to be passed in any subsequent calls to this callback routine that are - made to normalize the remaining components in the same file name path. + made to normalize the remaining components in the same file name path. Return Value: @@ -2006,11 +2006,11 @@ Return Value: PAGED_CODE(); - return NcNormalizeNameComponentEx( Instance, + return NcNormalizeNameComponentEx( Instance, NULL, - ParentDirectory, - DeviceNameLength, - Component, + ParentDirectory, + DeviceNameLength, + Component, ExpandComponentName, ExpandComponentNameLength, Flags, diff --git a/filesys/miniFilter/NameChanger/nccompat.c b/filesys/miniFilter/NameChanger/nccompat.c index 204b10fe..fe07e6c8 100644 --- a/filesys/miniFilter/NameChanger/nccompat.c +++ b/filesys/miniFilter/NameChanger/nccompat.c @@ -121,7 +121,7 @@ Return Value: STATUS_SUCCESS otherwise. --*/ -{ +{ PWSTR Buffer; PUNICODE_STRING FileName; USHORT NewMaxLength; @@ -138,14 +138,15 @@ Return Value: if (FileNameLength <= FileName->MaximumLength) { + RtlZeroMemory( FileName->Buffer, FileName->MaximumLength ); goto CopyAndReturn; } NewMaxLength = FileNameLength; - Buffer = ExAllocatePoolWithTag( PagedPool, - NewMaxLength, - NC_FILE_NAME_TAG ); + Buffer = ExAllocatePoolZero( PagedPool, + NewMaxLength, + NC_FILE_NAME_TAG ); if (!Buffer) { @@ -162,8 +163,6 @@ Return Value: CopyAndReturn: - RtlZeroMemory(FileName->Buffer, FileName->MaximumLength); - FileName->Length = FileNameLength; RtlCopyMemory(FileName->Buffer, NewFileName, FileNameLength); @@ -307,9 +306,9 @@ NcCreateFileEx2Alternate ( // // Zero out output parameters. // - + *FileHandle = INVALID_HANDLE_VALUE; - + if (ARGUMENT_PRESENT( FileObject )) { *FileObject = NULL; @@ -390,7 +389,7 @@ NcCreateFileEx2Cleanup: if (!NT_SUCCESS( Status )) { if (*FileHandle != INVALID_HANDLE_VALUE) { - + FltClose( *FileHandle ); } @@ -401,16 +400,16 @@ NcCreateFileEx2Cleanup: ObDereferenceObject( *FileObject ); } } - } + } return Status; -} +} // // Helper routines which manage importing the functions. // -VOID +VOID NcCompatInit( ) { UNICODE_STRING FuncName; @@ -419,7 +418,7 @@ NcCompatInit( ) // // Default to NonPagedPoolNx for non paged pool allocations where supported. // - + ExInitializeDriverRuntime( DrvRtPoolNxOptIn ); // diff --git a/filesys/miniFilter/NameChanger/ncdirenum.c b/filesys/miniFilter/NameChanger/ncdirenum.c index 7594894f..e508292e 100644 --- a/filesys/miniFilter/NameChanger/ncdirenum.c +++ b/filesys/miniFilter/NameChanger/ncdirenum.c @@ -84,8 +84,8 @@ Return Value: BOOLEAN Single = BooleanFlagOn( Data->Iopb->OperationFlags, SL_RETURN_SINGLE_ENTRY ); BOOLEAN IgnoreCase = !BooleanFlagOn( FltObjects->FileObject->Flags, FO_OPENED_CASE_SENSITIVE ); - - FILE_INFORMATION_CLASS InformationClass = + + FILE_INFORMATION_CLASS InformationClass = Data->Iopb->Parameters.DirectoryControl.QueryDirectory.FileInformationClass; PVOID UserBuffer; @@ -141,7 +141,7 @@ Return Value: NULL, NULL, FLT_FILE_NAME_OPENED | FLT_FILE_NAME_QUERY_DEFAULT, - &FileNameInformation ); + &FileNameInformation ); if (!NT_SUCCESS( Status )) { @@ -207,7 +207,7 @@ Return Value: // // Before looking at the context, we have to acquire the lock. // - + NcLockStreamHandleContext( HandleContext ); Unlock = TRUE; @@ -239,7 +239,7 @@ Return Value: // // Now we need to initialize or clear the cache and query options. // - + Status = NcStreamHandleContextEnumSetup( DirCtx, InstanceContext, &Offsets, @@ -314,9 +314,9 @@ Return Value: break; } - if (NcSkipName( &Offsets, - DirCtx, - RealOverlap, + if (NcSkipName( &Offsets, + DirCtx, + RealOverlap, &InstanceContext->Mapping, IgnoreCase )) { @@ -357,7 +357,7 @@ Return Value: }// end of "we are copying entry" - } while (MoreRoom && + } while (MoreRoom && (Single ? (NumEntriesCopied < 1) : TRUE)); if (NumEntriesCopied > 0) { @@ -370,7 +370,7 @@ Return Value: try { NcSetNextEntryOffset( Add2Ptr(UserBuffer, LastEntryStart), - &Offsets, + &Offsets, TRUE ); } except (NcExceptionFilter( GetExceptionInformation(), TRUE )) { @@ -409,32 +409,32 @@ Return Value: NcEnumerateDirectoryCleanup: if (ReturnValue == FLT_PREOP_COMPLETE) { - + // // We need to write back results of query. // - + Data->IoStatus.Status = Status; - + if (NT_SUCCESS( Status )) { - + //success Data->IoStatus.Information = UserBufferOffset; } else { - + //failure Data->IoStatus.Information = 0; } } - + if (InstanceContext != NULL) { FltReleaseContext( InstanceContext ); } - + if (DirCtx != NULL) { - + if (!Unlock) { NcLockStreamHandleContext( HandleContext ); Unlock = TRUE; @@ -450,16 +450,16 @@ NcEnumerateDirectoryCleanup: } FLT_ASSERT( !Unlock ); - + if (FileNameInformation != NULL) { FltReleaseFileNameInformation( FileNameInformation ); } - + return ReturnValue; } -NTSTATUS +NTSTATUS NcEnumerateDirectorySetupInjection ( _Inout_ PNC_DIR_QRY_CONTEXT DirQryCtx, _In_ PCFLT_RELATED_OBJECTS FltObjects, @@ -479,7 +479,7 @@ Arguments: DirQryCtx - Pointer to directory query context (on the stream handle.) FltObjects - FltObjects structure for this operation. - + InstanceContext - Instance Context for this operation. Offsets - Offsets structure for this information class. @@ -566,7 +566,7 @@ Return Value: 0, // EA Length IO_IGNORE_SHARE_ACCESS_CHECK, // Flags FltObjects->FileObject ); // Transaction state - + if (!NT_SUCCESS( Status )) { goto NcEnumerateDirectorySetupCleanup; @@ -581,7 +581,7 @@ Return Value: QueryBufferLength = Offsets->FileNameDist + NameLength; - QueryBuffer = ExAllocatePoolWithTag( PagedPool, QueryBufferLength, NC_DIR_QRY_CACHE_TAG ); + QueryBuffer = ExAllocatePoolZero( PagedPool, QueryBufferLength, NC_DIR_QRY_CACHE_TAG ); if (QueryBuffer == NULL) { @@ -625,7 +625,7 @@ Return Value: // goto NcEnumerateDirectorySetupCleanup; - + } else { // @@ -680,7 +680,7 @@ NcEnumerateDirectorySetupCleanup: VOID NcEnumerateDirectoryReset ( - _Inout_ PNC_DIR_QRY_CONTEXT DirCtx + _Inout_ PNC_DIR_QRY_CONTEXT DirCtx ) /*++ @@ -713,7 +713,7 @@ Return Value: BOOLEAN NcSkipName ( _In_ PDIRECTORY_CONTROL_OFFSETS Offsets, - _In_ PNC_DIR_QRY_CONTEXT Context, + _In_ PNC_DIR_QRY_CONTEXT Context, _In_ NC_PATH_OVERLAP RealOverlap, _In_ PNC_MAPPING Mapping, _In_ BOOLEAN IgnoreCase @@ -767,7 +767,7 @@ Return Value: CacheString.MaximumLength = CacheString.Length; - if (RtlCompareUnicodeString( &CacheString, + if (RtlCompareUnicodeString( &CacheString, IgnoreString, IgnoreCase ) == 0) { @@ -799,7 +799,7 @@ Return Value: Context->Cache.CurrentOffset += ElementSize; } - } + } } return Result; @@ -864,7 +864,7 @@ Return Value: SearchString = NULL; } - Buffer = ExAllocatePoolWithTag( PagedPool, BufferLength, NC_DIR_QRY_CACHE_TAG ); + Buffer = ExAllocatePoolZero( PagedPool, BufferLength, NC_DIR_QRY_CACHE_TAG ); if (Buffer == NULL) { @@ -917,8 +917,8 @@ Return Value: } PNC_CACHE_ENTRY -NcDirEnumSelectNextEntry( - _Inout_ PNC_DIR_QRY_CONTEXT Context, +NcDirEnumSelectNextEntry( + _Inout_ PNC_DIR_QRY_CONTEXT Context, _In_ PDIRECTORY_CONTROL_OFFSETS Offsets, _In_ BOOLEAN IgnoreCase ) @@ -957,7 +957,7 @@ Return Value: // Figure out which name comes first // - if ((Context->Cache.Buffer == NULL) && + if ((Context->Cache.Buffer == NULL) && (Context->InjectionEntry.Buffer == NULL)) { // @@ -1037,7 +1037,7 @@ NcCopyDirEnumEntry ( _In_ ULONG UserSize, _Inout_ PNC_CACHE_ENTRY Entry, _In_ PDIRECTORY_CONTROL_OFFSETS Offsets, - _Out_ PBOOLEAN Copied + _Out_ PBOOLEAN Copied ) /*++ @@ -1128,8 +1128,8 @@ Return Value: return UserOffset; } -NTSTATUS -NcStreamHandleContextDirEnumCreate ( +NTSTATUS +NcStreamHandleContextDirEnumCreate ( _Out_ PNC_DIR_QRY_CONTEXT Context ) /*++ @@ -1220,10 +1220,10 @@ Return Value: PAGED_CODE(); // - // This context could be in its first use. If it is, then we need to - // setup the search string and information class. + // This context could be in its first use. If it is, then we need to + // setup the search string and information class. // - + if (DirContext->InUse == FALSE) { // @@ -1233,16 +1233,16 @@ Return Value: if (SearchString != NULL) { - DirContext->SearchString.Buffer = ExAllocatePoolWithTag( PagedPool, - SearchString->Length, - NC_DIR_QRY_SEARCH_STRING ); + DirContext->SearchString.Buffer = ExAllocatePoolZero( PagedPool, + SearchString->Length, + NC_DIR_QRY_SEARCH_STRING ); if (DirContext->SearchString.Buffer == NULL) { Status = STATUS_INSUFFICIENT_RESOURCES; goto NcStreamHandleContextEnumSetupCleanup; } - + DirContext->SearchString.MaximumLength = SearchString->Length; if (IgnoreCase) { @@ -1280,7 +1280,7 @@ Return Value: *FirstUsage = FALSE; // - // This is not the first query. Lets make sure that our data + // This is not the first query. Lets make sure that our data // is consistent. If the information classes don't line up // then our cache might be inconsistant. We should fail this // operation. @@ -1299,12 +1299,12 @@ Return Value: // // Either this is the first use of the context, - // or they are reseting the enumeration. We + // or they are reseting the enumeration. We // should clear the cache either way. // if (DirContext->Cache.Buffer != NULL) { - + ExFreePoolWithTag( DirContext->Cache.Buffer, NC_TAG ); DirContext->Cache.Buffer = NULL; DirContext->Cache.CurrentOffset = 0; @@ -1330,19 +1330,19 @@ Return Value: FltObjects, InstanceContext, Offsets, - InformationClass ); + InformationClass ); if (!NT_SUCCESS( Status )) { - + goto NcStreamHandleContextEnumSetupCleanup; } } } - // + // // Now we know that the entry is setup. // Mark it as in use. // - + DirContext->InUse = TRUE; Status = STATUS_SUCCESS; @@ -1370,9 +1370,9 @@ NcStreamHandleContextEnumSetupCleanup: return Status; } -VOID +VOID NcStreamHandleContextEnumClose ( - _In_ PNC_DIR_QRY_CONTEXT DirContext + _In_ PNC_DIR_QRY_CONTEXT DirContext ) /*++ diff --git a/filesys/miniFilter/NameChanger/ncdirnotify.c b/filesys/miniFilter/NameChanger/ncdirnotify.c index 480f647f..f3a4403e 100644 --- a/filesys/miniFilter/NameChanger/ncdirnotify.c +++ b/filesys/miniFilter/NameChanger/ncdirnotify.c @@ -164,7 +164,7 @@ NcReissueNotifyRequestWorkerRoutine ( FLT_ASSERT( (US)->Length > 0 ); \ if ( (US)->Buffer[(US)->Length/sizeof(WCHAR) - 1] == NC_SEPARATOR) { \ (US)->Length -= sizeof(WCHAR); \ - } + } NTSTATUS @@ -181,7 +181,7 @@ NcDirNotifyTranslateBuffers ( _Out_ PULONG OutputBufferWritten, _In_ BOOLEAN ReturnRealMappingPaths, _In_ BOOLEAN ReturnInMappingOnly - ) + ) /*++ Routine Description: @@ -369,9 +369,9 @@ Return Value: NcFreeUnicodeString( &NameString ); } - NameString.Buffer = ExAllocatePoolWithTag( PagedPool, - EntryLength, - NC_TAG ); + NameString.Buffer = ExAllocatePoolZero( PagedPool, + EntryLength, + NC_TAG ); if (NameString.Buffer == NULL) { @@ -475,9 +475,9 @@ Return Value: EntryLengthExact = FIELD_OFFSET( FILE_NOTIFY_INFORMATION, FileName ); EntryLengthExact += (ReturnName->Length - UserRequestName->Length - sizeof(WCHAR)); - + EntryLength = AlignToSize( EntryLengthExact, 8); - + // // We've done all we can. Return now to let our caller deal // with the remaining buffer. @@ -498,7 +498,7 @@ Return Value: DestEntry = NULL; break; } - + // // Copy the relative path name, taking care to exclude the // initial slash. @@ -513,7 +513,7 @@ Return Value: ReturnName->Length - UserRequestName->Length - sizeof(WCHAR)); DestEntry->Action = SourceEntry->Action; DestEntry->NextEntryOffset = EntryLength; - + // // Advance the destination that we're writing new entries by // however much we just consumed. @@ -522,7 +522,7 @@ Return Value: PrevDestEntry = DestEntry; *OutputBufferWritten += EntryLength; DestEntry = Add2Ptr( DestEntry, EntryLength ); - + if (MungedName.Buffer != NULL) { ExFreePoolWithTag( MungedName.Buffer, NC_GENERATE_NAME_TAG ); MungedName.Buffer = NULL; @@ -540,7 +540,7 @@ Return Value: // SourceEntry->NextEntryOffset is untrusted, since it may have been // copied from a user-provided buffer. // - + EntryLength = SourceEntry->NextEntryOffset; PointerResult = Add2Ptr( SourceEntry, EntryLength ); @@ -556,7 +556,7 @@ Return Value: // 2) We wrapped when advancing SourceEntry // 3) PointerResult is not within InputSystemBuffer // - + if (!NT_SUCCESS( Status ) || (PointerResult < (PVOID)SourceEntry) || (PointerResult < Add2Ptr( InputSystemBuffer, sizeof(FILE_NOTIFY_INFORMATION) ))) { @@ -566,7 +566,7 @@ Return Value: Status = STATUS_INVALID_USER_BUFFER; goto NcDirNotifyTranslateBuffersCleanup; } - + SourceEntry = (PFILE_NOTIFY_INFORMATION)PointerResult; if ((EntryLength == 0)) { @@ -585,7 +585,7 @@ Return Value: // structure, terminate the loop by setting SourceEntry to NULL so // we can at least return the valid entries we have. // - + FLT_ASSERT( *InputBufferConsumed <= InputBufferLength ); if ((SourceEntry != NULL) && @@ -601,7 +601,7 @@ Return Value: *InputBufferConsumed = InputBufferLength; SourceEntry = NULL; - } + } } } except (NcExceptionFilter( GetExceptionInformation(), TRUE )) { @@ -678,9 +678,9 @@ Return Value: PAGED_CODE(); - RequestContext = ExAllocatePoolWithTag( PagedPool, - sizeof(NC_NOTIFY_REQUEST_CONTEXT), - NC_TAG ); + RequestContext = ExAllocatePoolZero( PagedPool, + sizeof(NC_NOTIFY_REQUEST_CONTEXT), + NC_TAG ); if (RequestContext == NULL) { return STATUS_INSUFFICIENT_RESOURCES; @@ -737,7 +737,7 @@ Return Value: FltReleaseContext( NotifyRequestContext->UserHandleContext ); ExFreePoolWithTag( NotifyRequestContext, NC_TAG ); - + } NTSTATUS @@ -805,11 +805,11 @@ Return Value: // MDL now so we can copy to system address space rather than // back to the originating usermode process. // - + Status = FltLockUserBuffer( PrimaryRequest ); if (!NT_SUCCESS( Status )) { - + return Status; } @@ -823,12 +823,12 @@ Return Value: // #pragma warning(suppress: 6014) - MyBuffer = ExAllocatePoolWithTag( PagedPool, - BufferLength, - NC_TAG ); - + MyBuffer = ExAllocatePoolZero( PagedPool, + BufferLength, + NC_TAG ); + if (MyBuffer == NULL) { - + Status = STATUS_INSUFFICIENT_RESOURCES; return Status; } @@ -1176,7 +1176,7 @@ Return Value: NULL, NULL, FLT_FILE_NAME_OPENED | FLT_FILE_NAME_QUERY_DEFAULT, - &FileNameInformation ); + &FileNameInformation ); if (!NT_SUCCESS( Status )) { @@ -1272,7 +1272,7 @@ Return Value: // // Before looking at the context, we have to acquire the lock. // - + NcLockStreamHandleContext( HandleContext ); UnlockContext = TRUE; @@ -1306,9 +1306,9 @@ Return Value: if (NotCtx->UserRequestName.Buffer == NULL) { - NotCtx->UserRequestName.Buffer = ExAllocatePoolWithTag( PagedPool, - FileNameInformation->Name.Length, - NC_TAG ); + NotCtx->UserRequestName.Buffer = ExAllocatePoolZero( PagedPool, + FileNameInformation->Name.Length, + NC_TAG ); if (NotCtx->UserRequestName.Buffer == NULL) { @@ -1683,13 +1683,13 @@ Return Value: // the parent specifically so that a caller can monitor changes // to the mapping itself. // - + InitializeObjectAttributes( &MappingParentAttributes, &InstanceContext->Mapping.RealMapping.LongNamePath.ParentPath, OBJ_KERNEL_HANDLE | (IgnoreCase?OBJ_CASE_INSENSITIVE:0), NULL, NULL); - + Status = NcCreateFileHelper( NcGlobalData.FilterHandle, // Filter FltObjects->Instance, // InstanceOffsets &MappingParentHandle, // Returned Handle @@ -1706,7 +1706,7 @@ Return Value: 0, // EA Length IO_IGNORE_SHARE_ACCESS_CHECK, // Flags FltObjects->FileObject ); // Transaction info - + if (!NT_SUCCESS( Status )) { // @@ -1750,9 +1750,9 @@ Return Value: goto NcPreNotifyDirectoryCleanup; } - MappingParentName = ExAllocatePoolWithTag( PagedPool, - FileInfoInternalHandle->Name.Length, - NC_TAG ); + MappingParentName = ExAllocatePoolZero( PagedPool, + FileInfoInternalHandle->Name.Length, + NC_TAG ); if (MappingParentName == NULL) { @@ -1838,7 +1838,7 @@ Return Value: // // The only way to be here is if a cleanup request has // occurred and we're aborting. - // + // FLT_ASSERT( NotCtx->CleanupSeen ); @@ -2054,20 +2054,20 @@ Return Value: NcPreNotifyDirectoryCleanup: if (ReturnValue == FLT_PREOP_COMPLETE) { - + // // We need to write back results of query. // - + Data->IoStatus.Status = Status; - + if (NT_SUCCESS( Status )) { - + //success Data->IoStatus.Information = SizeWeReturn; } else { - + //failure Data->IoStatus.Information = 0; @@ -2136,14 +2136,14 @@ NcPreNotifyDirectoryCleanup: NcCleanupSubNotifyRequest( NewMappingParentRequest ); NotCtx->MappingRequest = NewMappingParentRequest = NULL; } - + if (InstanceContext != NULL) { FltReleaseContext( InstanceContext ); } - + if (UnlockContext) { - + FLT_ASSERT( HandleContext != NULL ); NcUnlockStreamHandleContext( HandleContext ); } @@ -2160,12 +2160,12 @@ NcPreNotifyDirectoryCleanup: if (MappingParentRequestContext) { NcFreeNotifyRequestContext( MappingParentRequestContext ); } - + if (HandleContext != NULL) { FltReleaseContext( HandleContext ); } - + if (FileNameInformation != NULL) { FltReleaseFileNameInformation( FileNameInformation ); @@ -2237,7 +2237,7 @@ Return Value: // // Before looking at the context, we have to acquire the lock. // - + NcLockStreamHandleContext( HandleContext ); UnlockContext = TRUE; @@ -2300,7 +2300,7 @@ Return Value: // note to tell the app that it must rescan as soon as it // asks us again. // - + NotCtx->InsufficientBufferSeen = TRUE; } } @@ -2332,7 +2332,7 @@ Return Value: // // If this assumption is wrong, we need to be smarter about whether // we want to complete the user's request in this path or not. - // + // FLT_ASSERT( Data == NotCtx->UserRequest ); goto NcPostNotifyDirectoryRealCleanup; @@ -2356,16 +2356,16 @@ Return Value: // // Allocate a new buffer and copy the contents. Note that this is - // particularly important with this call, since it's not always + // particularly important with this call, since it's not always // system buffered; the contents are free to change underneath us. // This allocation protects us against that, but we still must be // paranoid touching the buffer, since we cannot trust that it has // any integrity at this point. // - SourceBuffer = ExAllocatePoolWithTag( PagedPool, - SizeActuallyReturned, - NC_TAG ); + SourceBuffer = ExAllocatePoolZero( PagedPool, + SizeActuallyReturned, + NC_TAG ); if (SourceBuffer == NULL) { @@ -2457,17 +2457,17 @@ Return Value: // process the data now because we won't know which call // generated the data later. // - - NotCtx->BufferToFree = ExAllocatePoolWithTag( PagedPool, - BufferSize, - NC_TAG ); - + + NotCtx->BufferToFree = ExAllocatePoolZero( PagedPool, + BufferSize, + NC_TAG ); + if (NotCtx->BufferToFree == NULL) { - + Status = STATUS_INSUFFICIENT_RESOURCES; goto NcPostNotifyDirectoryRealCleanup; } - + } DestBuffer = NotCtx->BufferToFree; @@ -2558,7 +2558,7 @@ Return Value: // request but we filtered out all the contents. We certainly // don't want to tell the caller nothing whatsoever happened, so we // try to reissue this request. - // + // if (SizeWeReturn == 0) { @@ -2651,7 +2651,7 @@ Return Value: } else { - // + // // If the filesystem returned something less than one single // entry, return nothing. // @@ -2688,7 +2688,7 @@ NcPostNotifyDirectoryRealCleanup: // // This routine will free the FLT_CALLBACK_DATA. // - + NcCleanupSubNotifyRequest( Data ); } } @@ -2708,12 +2708,12 @@ NcPostNotifyDirectoryRealCleanup: NotCtx->UserRequest->IoStatus.Status = Status; if (NT_SUCCESS( Status )) { - + //success NotCtx->UserRequest->IoStatus.Information = SizeWeReturn; } else { - + //failure NotCtx->UserRequest->IoStatus.Information = 0; } @@ -2756,9 +2756,9 @@ NcPostNotifyDirectoryRealCleanup: ExFreePoolWithTag( SourceBuffer, NC_TAG ); } - + if (UnlockContext) { - + FLT_ASSERT( HandleContext != NULL ); NcUnlockStreamHandleContext( HandleContext ); } @@ -2770,7 +2770,7 @@ NcPostNotifyDirectoryRealCleanup: if (!ReissuedRequest) { NcFreeNotifyRequestContext( RequestContext ); } - + } FLT_POSTOP_CALLBACK_STATUS @@ -3059,7 +3059,7 @@ Return Value: // is owned by the filesystem, so we leave the filesystem to deal with this // when it gets the cleanup request. // - // Cancel any outstanding requests we have issued (if any.) + // Cancel any outstanding requests we have issued (if any.) // if ((NotCtx->Mode == Filter) || @@ -3215,7 +3215,7 @@ Return Value: // // Before looking at the context, we have to acquire the lock. // - + NcLockStreamHandleContext( HandleContext ); UnlockContext = TRUE; @@ -3223,7 +3223,7 @@ Return Value: // We should only ever be called on the user's request. // It follows that this is a Merge or Filter operation. // - + FLT_ASSERT( Data == NotCtx->UserRequest ); FLT_ASSERT( NotCtx->Mode == Filter || NotCtx->Mode == Merge ); @@ -3250,7 +3250,7 @@ Return Value: // if (NotCtx->BufferToFree != NULL) { - + ExFreePoolWithTag( NotCtx->BufferToFree, NC_TAG ); NotCtx->BufferToFree = NULL; NotCtx->BufferLength = 0; @@ -3272,8 +3272,8 @@ Return Value: FltReleaseContext( HandleContext ); } -NTSTATUS -NcStreamHandleContextNotCreate( +NTSTATUS +NcStreamHandleContextNotCreate( _Out_ PNC_DIR_NOT_CONTEXT Context ) /*++ @@ -3321,9 +3321,9 @@ Return Value: return Status; } -VOID +VOID NcStreamHandleContextNotCleanup( - _In_ PNC_STREAM_HANDLE_CONTEXT HandleContext + _In_ PNC_STREAM_HANDLE_CONTEXT HandleContext ) /*++ @@ -3392,17 +3392,17 @@ Return Value: // Although requests may remain, if we've been through cleanup our post // routine will ensure they can't do squat. // - + if (NotCtx->UserRequestName.Buffer != NULL) { NcFreeUnicodeString( &NotCtx->UserRequestName ); } - + if (NotCtx->MappingParentName.Buffer != NULL) { NcFreeUnicodeString( &NotCtx->MappingParentName ); } - + if (NotCtx->BufferToFree != NULL) { - + ExFreePoolWithTag( NotCtx->BufferToFree, NC_TAG ); NotCtx->BufferToFree = NULL; NotCtx->BufferLength = 0; @@ -3412,16 +3412,16 @@ Return Value: FltReleaseContext( NotCtx->InstanceContext ); NotCtx->InstanceContext = NULL; } - + NotCtx->Mode = Uninitialized; NcUnlockStreamHandleContext( HandleContext ); UnlockContext = FALSE; } -VOID +VOID NcStreamHandleContextNotClose( - _In_ PNC_DIR_NOT_CONTEXT Context + _In_ PNC_DIR_NOT_CONTEXT Context ) /*++ diff --git a/filesys/miniFilter/NameChanger/ncfileinfo.c b/filesys/miniFilter/NameChanger/ncfileinfo.c index 13314126..758ec6c8 100644 --- a/filesys/miniFilter/NameChanger/ncfileinfo.c +++ b/filesys/miniFilter/NameChanger/ncfileinfo.c @@ -9,7 +9,7 @@ Module Name: Abstract: Contains routines to process user-initiated query file and set file - information requests. + information requests. Environment: @@ -121,7 +121,7 @@ Return Value: // // Find the name in the user buffer. // - + if (InfoClass == FileAllInformation) { NameInfo = & ((PFILE_ALL_INFORMATION) UserBuffer)->NameInformation; @@ -160,7 +160,7 @@ Return Value: // a buffer overflow in the filter even if the file system succeeded. // - if (InstanceContext->Mapping.UserMapping.LongNamePath.VolumelessName.Length > + if (InstanceContext->Mapping.UserMapping.LongNamePath.VolumelessName.Length > InstanceContext->Mapping.RealMapping.LongNamePath.VolumelessName.Length) { NameInfo->FileNameLength += InstanceContext->Mapping.UserMapping.LongNamePath.VolumelessName.Length - @@ -174,9 +174,9 @@ Return Value: } ReturnedName.Buffer = NameInfo->FileName; - ReturnedName.MaximumLength = + ReturnedName.MaximumLength = ReturnedName.Length = (USHORT)NameInfo->FileNameLength; - + // // Check if the name being returned is within the real mapping. // If not, we have no translation to perform. @@ -256,7 +256,7 @@ Return Value: // } else { - + NameLengthAvailable = NameInfo->FileNameLength; Status = STATUS_SUCCESS; @@ -272,9 +272,9 @@ Return Value: FLT_ASSERT( Remainder.Length > 0 ); - RemainderCopy.Buffer = ExAllocatePoolWithTag( PagedPool, - Remainder.Length, - NC_TAG ); + RemainderCopy.Buffer = ExAllocatePoolZero( PagedPool, + Remainder.Length, + NC_TAG ); if (RemainderCopy.Buffer == NULL) { @@ -294,8 +294,8 @@ Return Value: // Firstly, copy back the name to our mapping. // - RtlCopyMemory( &NameInfo->FileName, - InstanceContext->Mapping.UserMapping.LongNamePath.VolumelessName.Buffer, + RtlCopyMemory( &NameInfo->FileName, + InstanceContext->Mapping.UserMapping.LongNamePath.VolumelessName.Buffer, min(InstanceContext->Mapping.UserMapping.LongNamePath.VolumelessName.Length, NameLengthAvailable) ); @@ -304,7 +304,7 @@ Return Value: NameLengthAvailable -= InstanceContext->Mapping.UserMapping.LongNamePath.VolumelessName.Length; } else { - + NameLengthAvailable = 0; } @@ -327,7 +327,7 @@ Return Value: // // We have finished the query, complete operation. // - + NcPostQueryNameInformationCleanup: Data->IoStatus.Status = Status; @@ -431,12 +431,12 @@ Return Value: // Get the file's name. // - Status = NcGetFileNameInformation( Data, + Status = NcGetFileNameInformation( Data, NULL, NULL, - FLT_FILE_NAME_OPENED | - FLT_FILE_NAME_QUERY_DEFAULT | - FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, + FLT_FILE_NAME_OPENED | + FLT_FILE_NAME_QUERY_DEFAULT | + FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, &FileInfo ); if (!NT_SUCCESS( Status )) { @@ -530,8 +530,8 @@ Return Value: // Copy back the name to our mapping. // - RtlCopyMemory( &NameInfo->FileName, - FinalComponentToReturn->Buffer, + RtlCopyMemory( &NameInfo->FileName, + FinalComponentToReturn->Buffer, FinalComponentToReturn->Length ); NameInfo->FileNameLength = FinalComponentToReturn->Length; @@ -539,7 +539,7 @@ Return Value: // // We have finished the query, complete operation. // - + Status = STATUS_SUCCESS; ReturnValue = FLT_PREOP_COMPLETE; @@ -686,7 +686,7 @@ Return Value: if (SizeActuallyReturned <= (ULONG)FIELD_OFFSET( FILE_LINKS_INFORMATION, Entry ) || !NT_SUCCESS( Data->IoStatus.Status )) { - + BytesWritten = SizeActuallyReturned; Status = Data->IoStatus.Status; @@ -708,13 +708,13 @@ Return Value: // // Open the mapping parents and query IDs. // - + InitializeObjectAttributes( &MappingParentAttributes, &InstanceContext->Mapping.RealMapping.LongNamePath.ParentPath, OBJ_KERNEL_HANDLE | (IgnoreCase?OBJ_CASE_INSENSITIVE:0), NULL, NULL); - + Status = NcCreateFileHelper( NcGlobalData.FilterHandle, // Filter Data->Iopb->TargetInstance, // Instance &MappingParentHandle, // Returned Handle @@ -731,7 +731,7 @@ Return Value: 0, // EA Length IO_IGNORE_SHARE_ACCESS_CHECK, // Flags Data->Iopb->TargetFileObject ); // Transaction info. - + if (!NT_SUCCESS( Status )) { FLT_ASSERT( Status != STATUS_OBJECT_PATH_NOT_FOUND && @@ -763,7 +763,7 @@ Return Value: OBJ_KERNEL_HANDLE | (IgnoreCase?OBJ_CASE_INSENSITIVE:0), NULL, NULL); - + Status = NcCreateFileHelper( NcGlobalData.FilterHandle, // Filter Data->Iopb->TargetInstance, // Instance &MappingParentHandle, // Returned Handle @@ -780,7 +780,7 @@ Return Value: 0, // EA Length IO_IGNORE_SHARE_ACCESS_CHECK, // Flags Data->Iopb->TargetFileObject ); // Transaction info. - + if (!NT_SUCCESS( Status )) { FLT_ASSERT( Status != STATUS_OBJECT_PATH_NOT_FOUND && @@ -811,9 +811,9 @@ Return Value: // Take a copy of the results of the call from the filesystem. // - OriginalBuffer = ExAllocatePoolWithTag( PagedPool, - SizeActuallyReturned, - NC_TAG ); + OriginalBuffer = ExAllocatePoolZero( PagedPool, + SizeActuallyReturned, + NC_TAG ); if (OriginalBuffer == NULL) { @@ -1028,7 +1028,7 @@ Return Value: { FLT_PREOP_CALLBACK_STATUS ReturnValue; NTSTATUS Status; - PFILE_NAME_INFORMATION NameInfo = + PFILE_NAME_INFORMATION NameInfo = Data->Iopb->Parameters.SetFileInformation.InfoBuffer; PFLT_FILE_NAME_INFORMATION FileInfo = NULL; PNC_INSTANCE_CONTEXT InstanceContext = NULL; @@ -1068,12 +1068,12 @@ Return Value: // Get the file's name. // - Status = NcGetFileNameInformation( Data, + Status = NcGetFileNameInformation( Data, NULL, NULL, - FLT_FILE_NAME_OPENED | - FLT_FILE_NAME_QUERY_DEFAULT | - FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, + FLT_FILE_NAME_OPENED | + FLT_FILE_NAME_QUERY_DEFAULT | + FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, &FileInfo ); if (!NT_SUCCESS( Status )) { @@ -1196,7 +1196,7 @@ NcPreSetDisposition ( Routine Description: Fltmgr callback which manages setting the delete disposition on a file. - We must disallow setting the delete disposition on an ancestor of either + We must disallow setting the delete disposition on an ancestor of either mapping because otherwise we would have to maintain the mapping's short/long name pairings. @@ -1265,8 +1265,8 @@ Return Value: Status = NcGetFileNameInformation( Data, NULL, NULL, - FLT_FILE_NAME_OPENED | - FLT_FILE_NAME_QUERY_DEFAULT | + FLT_FILE_NAME_OPENED | + FLT_FILE_NAME_QUERY_DEFAULT | FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, &FileInfo); @@ -1290,7 +1290,7 @@ Return Value: &InstanceContext ); if (!NT_SUCCESS( Status )) { - + goto NcPreSetDispositionCleanup; } @@ -1406,7 +1406,7 @@ Return Value: { FLT_PREOP_CALLBACK_STATUS ReturnValue; NTSTATUS Status; - PFILE_LINK_INFORMATION LinkInfo = + PFILE_LINK_INFORMATION LinkInfo = Data->Iopb->Parameters.SetFileInformation.InfoBuffer; PFILE_LINK_INFORMATION MungedLinkInfo = NULL; ULONG MungedLinkInfoSize; @@ -1537,7 +1537,7 @@ Return Value: // // We need to build a new path to link on. // - + Status = NcConstructPath( &InstanceContext->Mapping.RealMapping, &UserRemainder, TRUE, @@ -1551,12 +1551,12 @@ Return Value: // // Create our own link structure. - // - + // + MungedLinkInfoSize = sizeof(FILE_LINK_INFORMATION) + MungedName.Length - sizeof(WCHAR); - MungedLinkInfo = ExAllocatePoolWithTag( PagedPool, - MungedLinkInfoSize, - NC_SET_LINK_BUFFER_TAG ); + MungedLinkInfo = ExAllocatePoolZero( PagedPool, + MungedLinkInfoSize, + NC_SET_LINK_BUFFER_TAG ); if (MungedLinkInfo == NULL) { @@ -1574,7 +1574,7 @@ Return Value: // // Issue our own request. // - + Status = FltSetInformationFile( FltObjects->Instance, FltObjects->FileObject, MungedLinkInfo, @@ -1584,7 +1584,7 @@ Return Value: // // Because we issued the IO, we will pass complete this ourselves. // - + ReturnValue = FLT_PREOP_COMPLETE; NcPreSetLinkInformationCleanup: @@ -1651,55 +1651,55 @@ Return Value: // // Return Values // - + NTSTATUS Status; FLT_PREOP_CALLBACK_STATUS ReturnValue; // // Contexts // - + PNC_INSTANCE_CONTEXT InstanceContext = NULL; - + // // Data // - - PFILE_RENAME_INFORMATION RenameInfo = + + PFILE_RENAME_INFORMATION RenameInfo = Data->Iopb->Parameters.SetFileInformation.InfoBuffer; - + // // FileInformation // - + PFLT_FILE_NAME_INFORMATION TargetInfo = NULL; PFLT_FILE_NAME_INFORMATION SrcInfo = NULL; - + // // Target Real Overlap // - + NC_PATH_OVERLAP TargetRealOverlap; UNICODE_STRING TargetRealRemainder; - + // // Target User Overlap // - + NC_PATH_OVERLAP TargetUserOverlap; UNICODE_STRING TargetUserRemainder; // // Src Real Overlap // - + NC_PATH_OVERLAP SrcRealOverlap; NC_PATH_OVERLAP SrcUserOverlap; - + // // Munge Data // - + UNICODE_STRING MungedTargetName = EMPTY_UNICODE_STRING; PFILE_RENAME_INFORMATION MungedRenameInfo = NULL; ULONG MungedRenameLength; @@ -1713,7 +1713,7 @@ Return Value: ReplaceIfExists = (fileInformationClass == FileRenameInformationEx) ? BooleanFlagOn( RenameInfo->Flags, FILE_RENAME_REPLACE_IF_EXISTS ) : RenameInfo->ReplaceIfExists; - + PAGED_CODE(); @@ -1725,7 +1725,7 @@ Return Value: (fileInformationClass == FileRenameInformationEx) ); // - // Get Instance Context + // Get Instance Context // Status = FltGetInstanceContext( FltObjects->Instance, @@ -1740,12 +1740,12 @@ Return Value: // // Find out the src file's name. // - + Status = NcGetFileNameInformation( Data, NULL, NULL, - FLT_FILE_NAME_OPENED | - FLT_FILE_NAME_QUERY_DEFAULT | + FLT_FILE_NAME_OPENED | + FLT_FILE_NAME_QUERY_DEFAULT | FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, &SrcInfo); @@ -1766,7 +1766,7 @@ Return Value: // // Find the src's overlap with the real and user mappings. // - + NcComparePath( &SrcInfo->Name, &InstanceContext->Mapping.RealMapping, NULL, @@ -1785,7 +1785,7 @@ Return Value: // If the src is an ancestor of either the user or real mappings we can // fail the request. // - + if (SrcUserOverlap.Ancestor || SrcRealOverlap.Ancestor) { ReturnValue = FLT_PREOP_COMPLETE; @@ -1796,7 +1796,7 @@ Return Value: // // Find out the target file's name. // - + Status = FltGetDestinationFileNameInformation( FltObjects->Instance, FltObjects->FileObject, RenameInfo->RootDirectory, @@ -1816,7 +1816,7 @@ Return Value: Status = FltParseFileNameInformation( TargetInfo ); if( !NT_SUCCESS( Status ) ) { - + FLT_ASSERT( NT_SUCCESS( Status ) ); ReturnValue = FLT_PREOP_COMPLETE; @@ -1826,7 +1826,7 @@ Return Value: // // Find the target's overlap with the real and user mappings. // - + NcComparePath( &TargetInfo->Name, &InstanceContext->Mapping.RealMapping, &TargetRealRemainder, @@ -1850,14 +1850,14 @@ Return Value: if (TargetRealOverlap.InMapping) { Status = STATUS_ACCESS_DENIED; - ReturnValue = FLT_PREOP_COMPLETE; + ReturnValue = FLT_PREOP_COMPLETE; goto NcPreRenameCleanup; } else if ((TargetRealOverlap.Ancestor || TargetUserOverlap.Ancestor) && ReplaceIfExists) { Status = STATUS_ACCESS_DENIED; - ReturnValue = FLT_PREOP_COMPLETE; + ReturnValue = FLT_PREOP_COMPLETE; goto NcPreRenameCleanup; } @@ -1896,9 +1896,9 @@ Return Value: sizeof(WCHAR) + MungedTargetName.Length; - MungedRenameInfo = ExAllocatePoolWithTag( PagedPool, - MungedRenameLength, - NC_RENAME_BUFFER_TAG ); + MungedRenameInfo = ExAllocatePoolZero( PagedPool, + MungedRenameLength, + NC_RENAME_BUFFER_TAG ); if (MungedRenameInfo == NULL) { @@ -1914,8 +1914,8 @@ Return Value: MungedRenameInfo->Flags = RenameInfo->Flags; MungedRenameInfo->RootDirectory = NULL; MungedRenameInfo->FileNameLength = MungedTargetName.Length; - RtlCopyMemory( &MungedRenameInfo->FileName, - MungedTargetName.Buffer, + RtlCopyMemory( &MungedRenameInfo->FileName, + MungedTargetName.Buffer, MungedTargetName.Length ); // @@ -1941,7 +1941,7 @@ Return Value: } else { // - // The target was outside the mapping. The rename does not have + // The target was outside the mapping. The rename does not have // to be munged. Pass through. // diff --git a/filesys/miniFilter/NameChanger/ncfsctrl.c b/filesys/miniFilter/NameChanger/ncfsctrl.c index 32752810..0baf4a5e 100644 --- a/filesys/miniFilter/NameChanger/ncfsctrl.c +++ b/filesys/miniFilter/NameChanger/ncfsctrl.c @@ -187,7 +187,7 @@ NcFindFilesBySidTranslateBuffers ( _Out_ PULONG InputBufferConsumed, _Out_ PULONG OutputBufferWritten, _In_ BOOLEAN ReturnRealMappingPaths - ) + ) /*++ Routine Description: @@ -222,7 +222,7 @@ Arguments: Note however that the contents of the buffer may have originated from a user buffer (e.g. via a memcpy), so although the contents are non-volatile, they are not to be trusted. - + OutputUserBuffer - The buffer we are returning munged results into. This buffer is expected to have been probed, and this function will catch and return any invalid buffer exceptions. @@ -299,7 +299,7 @@ Return Value: FLT_ASSERT( InputBufferLength && OutputBufferLength ); try { - + while( SourceEntry ) { // @@ -364,9 +364,9 @@ Return Value: NcFreeUnicodeString( &NameString ); } - NameString.Buffer = ExAllocatePoolWithTag( PagedPool, - EntryLength, - NC_TAG ); + NameString.Buffer = ExAllocatePoolZero( PagedPool, + EntryLength, + NC_TAG ); if (NameString.Buffer == NULL) { @@ -459,10 +459,10 @@ Return Value: ReturnName->Buffer[ReturnName->Length/sizeof(WCHAR) - 1] == NC_SEPARATOR) { ReturnName->Length -= sizeof(WCHAR); - } - + } + EntryLength = AlignToSize( FIELD_OFFSET( FILE_NAME_INFORMATION, FileName ) + ReturnName->Length - UserRequestName->Length - sizeof(WCHAR), 8); - + // // We've done all we can. Return now to let our caller deal // with the remaining buffer. @@ -479,7 +479,7 @@ Return Value: DestEntry = NULL; break; } - + // // Copy the relative path name, taking care to exclude the // initial slash. @@ -489,7 +489,7 @@ Return Value: RtlCopyMemory( DestEntry->FileName, Add2Ptr( ReturnName->Buffer, UserRequestName->Length + sizeof(WCHAR)), ReturnName->Length - UserRequestName->Length - sizeof(WCHAR)); - + // // Advance the destination that we're writing new entries by // however much we just consumed. @@ -497,7 +497,7 @@ Return Value: *OutputBufferWritten += EntryLength; DestEntry = Add2Ptr( DestEntry, EntryLength ); - + if (MungedName.Buffer != NULL) { ExFreePoolWithTag( MungedName.Buffer, NC_GENERATE_NAME_TAG ); MungedName.Buffer = NULL; @@ -511,7 +511,7 @@ Return Value: // EntryLength = AlignToSize( FIELD_OFFSET( FILE_NAME_INFORMATION, FileName ) + SourceEntry->FileNameLength, 8 ); - + PointerResult = Add2Ptr( SourceEntry, EntryLength ); Status = RtlULongAdd( *InputBufferConsumed, @@ -525,7 +525,7 @@ Return Value: // 2) We wrapped when advancing SourceEntry // 3) PointerResult is not within InputSystemBuffer // - + if (!NT_SUCCESS( Status ) || (PointerResult < (PVOID)SourceEntry) || (PointerResult < Add2Ptr( InputSystemBuffer, sizeof(FILE_NAME_INFORMATION) ))) { @@ -535,7 +535,7 @@ Return Value: Status = STATUS_INVALID_USER_BUFFER; goto NcFindFilesBySidTranslateBuffersCleanup; } - + SourceEntry = (PFILE_NAME_INFORMATION)PointerResult; // @@ -544,7 +544,7 @@ Return Value: // structure, terminate the loop by setting SourceEntry to NULL so // we can at least return the valid entries we have. // - + FLT_ASSERT( *InputBufferConsumed <= InputBufferLength ); if ((*InputBufferConsumed >= InputBufferLength) || @@ -693,12 +693,12 @@ Return Value: // Get the file's name. // - Status = NcGetFileNameInformation( Data, + Status = NcGetFileNameInformation( Data, NULL, NULL, - FLT_FILE_NAME_OPENED | - FLT_FILE_NAME_QUERY_DEFAULT | - FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, + FLT_FILE_NAME_OPENED | + FLT_FILE_NAME_QUERY_DEFAULT | + FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, &FileInfo ); if (!NT_SUCCESS( Status )) { @@ -725,7 +725,7 @@ Return Value: FLT_ASSERT( UserRequestName.Length > 0 ); if (UserRequestName.Buffer[UserRequestName.Length/sizeof(WCHAR) - 1] == NC_SEPARATOR) { UserRequestName.Length -= sizeof(WCHAR); - } + } // // As an optimization, check if the handle queried on is an ancestor of @@ -796,7 +796,7 @@ Return Value: // // We only really need this if BufferToFree != NULL, but this may // change as soon as we drop the lock. - // + // if (FindBySidCtx->RealFileObject == NULL) { @@ -814,41 +814,41 @@ Return Value: // // In dropping the lock, it is possible that the FileObject to go // to NULL. However, since we know it was non-NULL, the only - // possibility if this occurs is that we are done with the + // possibility if this occurs is that we are done with the // enumeration. // ObReferenceObject( RealFileObject ); NcUnlockStreamHandleContext( HandleContext ); UnlockContext = FALSE; - - Status = NcGetFileNameInformation( NULL, + + Status = NcGetFileNameInformation( NULL, RealFileObject, FltObjects->Instance, - FLT_FILE_NAME_OPENED | - FLT_FILE_NAME_QUERY_DEFAULT | - FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, + FLT_FILE_NAME_OPENED | + FLT_FILE_NAME_QUERY_DEFAULT | + FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, &FileInfoInternalHandle ); - + if (!NT_SUCCESS( Status )) { - + ObDereferenceObject( RealFileObject ); goto NcPreFindFilesBySidCleanup; } - + Status = FltParseFileNameInformation( FileInfoInternalHandle ); - + if (!NT_SUCCESS( Status )) { - + ObDereferenceObject( RealFileObject ); goto NcPreFindFilesBySidCleanup; } - + OpenedName = FileInfoInternalHandle->Name; FLT_ASSERT( OpenedName.Length > 0 ); if (OpenedName.Buffer[OpenedName.Length/sizeof(WCHAR) - 1] == NC_SEPARATOR) { OpenedName.Length -= sizeof(WCHAR); - } + } // // This may trigger a close, and must be done before we acquire the @@ -1215,7 +1215,7 @@ Return Value: // if (!NT_SUCCESS( Data->IoStatus.Status )) { - + Status = Data->IoStatus.Status; goto NcPostFindFilesBySidCleanup; } @@ -1248,12 +1248,12 @@ Return Value: // construct names by combining these values. // - Status = NcGetFileNameInformation( Data, + Status = NcGetFileNameInformation( Data, NULL, NULL, - FLT_FILE_NAME_OPENED | - FLT_FILE_NAME_QUERY_DEFAULT | - FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, + FLT_FILE_NAME_OPENED | + FLT_FILE_NAME_QUERY_DEFAULT | + FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, &FileInfo ); if (!NT_SUCCESS( Status )) { @@ -1327,7 +1327,7 @@ Return Value: FLT_ASSERT( UserRequestName.Length > 0 ); if (UserRequestName.Buffer[UserRequestName.Length/sizeof(WCHAR) - 1] == NC_SEPARATOR) { UserRequestName.Length -= sizeof(WCHAR); - } + } if (UserOverlap.Ancestor && !RealOverlap.Ancestor) { @@ -1429,12 +1429,12 @@ NcPostFindFilesBySidMungeBuffer: FLT_ASSERT( FileInfoInternalHandle == NULL ); - Status = NcGetFileNameInformation( NULL, + Status = NcGetFileNameInformation( NULL, FindBySidCtx->RealFileObject, FltObjects->Instance, - FLT_FILE_NAME_OPENED | - FLT_FILE_NAME_QUERY_DEFAULT | - FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, + FLT_FILE_NAME_OPENED | + FLT_FILE_NAME_QUERY_DEFAULT | + FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, &FileInfoInternalHandle ); if (!NT_SUCCESS( Status )) { @@ -1453,10 +1453,10 @@ NcPostFindFilesBySidMungeBuffer: FLT_ASSERT( OpenedName.Length > 0 ); if (OpenedName.Buffer[OpenedName.Length/sizeof(WCHAR) - 1] == NC_SEPARATOR) { OpenedName.Length -= sizeof(WCHAR); - } + } } - + if (!UnlockContext) { NcLockStreamHandleContext( HandleContext ); UnlockContext = TRUE; @@ -1507,9 +1507,9 @@ NcPostFindFilesBySidMungeBuffer: } #pragma warning(suppress: __WARNING_MEMORY_LEAK) - SourceBuffer = ExAllocatePoolWithTag( PagedPool, - SourceBufferSize, - NC_TAG ); + SourceBuffer = ExAllocatePoolZero( PagedPool, + SourceBufferSize, + NC_TAG ); if (SourceBuffer == NULL) { @@ -1643,7 +1643,7 @@ NcPostFindFilesBySidMungeBuffer: FindBySidCtx->CurrentEntry += InputConsumed; FLT_ASSERT( FindBySidCtx->CurrentEntry <= FindBySidCtx->BufferSize ); - + if (FindBySidCtx->CurrentEntry >= FindBySidCtx->BufferSize) { // @@ -1717,7 +1717,7 @@ NcPostFindFilesBySidMungeBuffer: // need to enumerate from the mapping. At this point, the // mapping has not been set up yet, so we do that now. // - // Because we can't hold a lock doing this, we do so + // Because we can't hold a lock doing this, we do so // speculatively: two threads may end up doing this work, and // one may be thrown away. // @@ -1736,13 +1736,13 @@ NcPostFindFilesBySidMungeBuffer: // Open the mapping. We're done returning data on the user's // handle, but we still need to return data from the mapping. // - + InitializeObjectAttributes( &MappingAttributes, &InstanceContext->Mapping.RealMapping.LongNamePath.FullPath, OBJ_KERNEL_HANDLE | (IgnoreCase?OBJ_CASE_INSENSITIVE:0), NULL, NULL); - + Status = NcCreateFileHelper( NcGlobalData.FilterHandle, // Filter FltObjects->Instance, // Instance &MappingHandle, // Returned Handle @@ -1759,7 +1759,7 @@ NcPostFindFilesBySidMungeBuffer: 0, // EA Length IO_IGNORE_SHARE_ACCESS_CHECK, // Flags FltObjects->FileObject ); // Transaction info. - + if (!NT_SUCCESS( Status )) { if ( Status == STATUS_OBJECT_PATH_NOT_FOUND || @@ -1960,7 +1960,7 @@ Return Value: // if (!NT_SUCCESS( Data->IoStatus.Status ) || SizeActuallyReturned == 0) { - + Status = Data->IoStatus.Status; goto NcPostLookupStreamFromClusterCleanup; } @@ -1984,9 +1984,9 @@ Return Value: // buffer with our modified data. // - SourceBuffer = ExAllocatePoolWithTag( PagedPool, - SizeActuallyReturned, - NC_TAG ); + SourceBuffer = ExAllocatePoolZero( PagedPool, + SizeActuallyReturned, + NC_TAG ); if (SourceBuffer == NULL) { @@ -2161,7 +2161,7 @@ NcUsnTranslateBuffers ( _In_ ULONG OutputBufferLength, _Out_ PULONG InputBufferConsumed, _Out_ PULONG OutputBufferWritten - ) + ) /*++ Routine Description: @@ -2193,7 +2193,7 @@ Arguments: Note however that the contents of the buffer may have originated from a user buffer (via a memcpy), so although the contents are non-volatile, they are not to be trusted. - + OutputUserBuffer - The buffer we are returning munged results into. This buffer is expected to have been probed, and this function will catch and return any invalid buffer exceptions. @@ -2259,7 +2259,7 @@ Return Value: FLT_ASSERT( InputBufferLength && OutputBufferLength ); try { - + while (SourceEntry) { // @@ -2400,7 +2400,7 @@ FailedBufferCheck: break; } - + // // If we're not transforming (the common case) copy the entire // record blindly from source to destination. If we are @@ -2461,7 +2461,7 @@ FailedBufferCheck: // 2) We wrapped when advancing SourceEntry // 3) PointerResult is not within InputSystemBuffer // - + if (!NT_SUCCESS( Status ) || (PointerResult < (PVOID)SourceEntry) || (PointerResult < Add2Ptr( InputSystemBuffer, sizeof(USN_RECORD) ))) { @@ -2477,13 +2477,13 @@ FailedBufferCheck: // would not overflow our output buffer, meaning advancing DestEntry // by EntryLength bytes is also safe. // - + *OutputBufferWritten += EntryLength; DestEntry = Add2Ptr( DestEntry, EntryLength ); SourceEntry = (PUSN_RECORD)PointerResult; - + // // If we've just advanced our next location beyond the end of the // input buffer, or there isn't enough room in it for even a USN_RECORD @@ -2605,7 +2605,7 @@ Return Value: // if (!NT_SUCCESS( Data->IoStatus.Status )) { - + Status = Data->IoStatus.Status; goto NcPostReadFileUsnDataCleanup; } @@ -2631,12 +2631,12 @@ Return Value: // processing calls destined to the mapping. // - Status = NcGetFileNameInformation( Data, + Status = NcGetFileNameInformation( Data, NULL, NULL, - FLT_FILE_NAME_OPENED | + FLT_FILE_NAME_OPENED | FLT_FILE_NAME_QUERY_DEFAULT | - FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, + FLT_FILE_NAME_REQUEST_FROM_CURRENT_PROVIDER, &FileInfo ); if (!NT_SUCCESS( Status )) { @@ -2710,13 +2710,13 @@ Return Value: // // Open the mapping parents and query IDs. // - + InitializeObjectAttributes( &MappingParentAttributes, &InstanceContext->Mapping.RealMapping.LongNamePath.ParentPath, OBJ_KERNEL_HANDLE | (IgnoreCase?OBJ_CASE_INSENSITIVE:0), NULL, NULL); - + Status = NcCreateFileHelper( NcGlobalData.FilterHandle, // Filter FltObjects->Instance, // Instance &MappingParentHandle, // Returned Handle @@ -2733,7 +2733,7 @@ Return Value: 0, // EA Length IO_IGNORE_SHARE_ACCESS_CHECK, // Flags FltObjects->FileObject ); // Transaction info. - + if (!NT_SUCCESS( Status )) { FLT_ASSERT( Status != STATUS_OBJECT_PATH_NOT_FOUND && @@ -2765,7 +2765,7 @@ Return Value: OBJ_KERNEL_HANDLE | (IgnoreCase?OBJ_CASE_INSENSITIVE:0), NULL, NULL); - + Status = NcCreateFileHelper( NcGlobalData.FilterHandle, // Filter FltObjects->Instance, // Instance &MappingParentHandle, // Returned Handle @@ -2782,7 +2782,7 @@ Return Value: 0, // EA Length IO_IGNORE_SHARE_ACCESS_CHECK, // Flags FltObjects->FileObject ); // Transaction info. - + if (!NT_SUCCESS( Status )) { FLT_ASSERT( Status != STATUS_OBJECT_PATH_NOT_FOUND && @@ -2818,9 +2818,9 @@ Return Value: // any integrity at this point. // - SourceBuffer = ExAllocatePoolWithTag( PagedPool, - SizeActuallyReturned, - NC_TAG ); + SourceBuffer = ExAllocatePoolZero( PagedPool, + SizeActuallyReturned, + NC_TAG ); if (SourceBuffer == NULL) { @@ -2984,7 +2984,7 @@ Return Value: // if (!NT_SUCCESS( Data->IoStatus.Status )) { - + Status = Data->IoStatus.Status; goto NcPostEnumUsnDataCleanup; } @@ -3051,13 +3051,13 @@ Return Value: // // Open the mapping parents and query IDs. // - + InitializeObjectAttributes( &MappingParentAttributes, &InstanceContext->Mapping.RealMapping.LongNamePath.ParentPath, OBJ_KERNEL_HANDLE | (IgnoreCase?OBJ_CASE_INSENSITIVE:0), NULL, NULL); - + Status = NcCreateFileHelper( NcGlobalData.FilterHandle, // Filter FltObjects->Instance, // Instance &MappingParentHandle, // Returned Handle @@ -3074,7 +3074,7 @@ Return Value: 0, // EA Length IO_IGNORE_SHARE_ACCESS_CHECK, // Flags FltObjects->FileObject ); // Transaction info. - + if (!NT_SUCCESS( Status )) { FLT_ASSERT( Status != STATUS_OBJECT_PATH_NOT_FOUND && @@ -3106,7 +3106,7 @@ Return Value: OBJ_KERNEL_HANDLE | (IgnoreCase?OBJ_CASE_INSENSITIVE:0), NULL, NULL); - + Status = NcCreateFileHelper( NcGlobalData.FilterHandle, // Filter FltObjects->Instance, // Instance &MappingParentHandle, // Returned Handle @@ -3123,7 +3123,7 @@ Return Value: 0, // EA Length IO_IGNORE_SHARE_ACCESS_CHECK, // Flags FltObjects->FileObject ); // Transaction info. - + if (!NT_SUCCESS( Status )) { FLT_ASSERT( Status != STATUS_OBJECT_PATH_NOT_FOUND && @@ -3159,9 +3159,9 @@ Return Value: // any integrity at this point. // - SourceBuffer = ExAllocatePoolWithTag( PagedPool, - SizeActuallyReturned, - NC_TAG ); + SourceBuffer = ExAllocatePoolZero( PagedPool, + SizeActuallyReturned, + NC_TAG ); if (SourceBuffer == NULL) { @@ -3317,7 +3317,7 @@ Return Value: // if (!NT_SUCCESS( Data->IoStatus.Status )) { - + Status = Data->IoStatus.Status; goto NcPostReadUsnJournalSafeCleanup; } @@ -3384,13 +3384,13 @@ Return Value: // // Open the mapping parents and query IDs. // - + InitializeObjectAttributes( &MappingParentAttributes, &InstanceContext->Mapping.RealMapping.LongNamePath.ParentPath, OBJ_KERNEL_HANDLE | (IgnoreCase?OBJ_CASE_INSENSITIVE:0), NULL, NULL); - + Status = NcCreateFileHelper( NcGlobalData.FilterHandle, // Filter Data->Iopb->TargetInstance, // Instance &MappingParentHandle, // Returned Handle @@ -3407,7 +3407,7 @@ Return Value: 0, // EA Length IO_IGNORE_SHARE_ACCESS_CHECK, // Flags Data->Iopb->TargetFileObject ); // Transaction info. - + if (!NT_SUCCESS( Status )) { FLT_ASSERT( Status != STATUS_OBJECT_PATH_NOT_FOUND && @@ -3439,7 +3439,7 @@ Return Value: OBJ_KERNEL_HANDLE | (IgnoreCase?OBJ_CASE_INSENSITIVE:0), NULL, NULL); - + Status = NcCreateFileHelper( NcGlobalData.FilterHandle, // Filter Data->Iopb->TargetInstance, // Instance &MappingParentHandle, // Returned Handle @@ -3456,7 +3456,7 @@ Return Value: 0, // EA Length IO_IGNORE_SHARE_ACCESS_CHECK, // Flags Data->Iopb->TargetFileObject ); // Transaction info. - + if (!NT_SUCCESS( Status )) { FLT_ASSERT( Status != STATUS_OBJECT_PATH_NOT_FOUND && @@ -3492,9 +3492,9 @@ Return Value: // any integrity at this point. // - SourceBuffer = ExAllocatePoolWithTag( PagedPool, - SizeActuallyReturned, - NC_TAG ); + SourceBuffer = ExAllocatePoolZero( PagedPool, + SizeActuallyReturned, + NC_TAG ); if (SourceBuffer == NULL) { diff --git a/filesys/miniFilter/NameChanger/nchelper.c b/filesys/miniFilter/NameChanger/nchelper.c index 72443de4..489c435e 100644 --- a/filesys/miniFilter/NameChanger/nchelper.c +++ b/filesys/miniFilter/NameChanger/nchelper.c @@ -26,13 +26,13 @@ Environment: _When_(Data == NULL, _Pre_satisfies_(FileObject != NULL && Instance != NULL)) _When_(FileObject == NULL || Instance == NULL, _Pre_satisfies_(Data != NULL)) -NTSTATUS +NTSTATUS NcGetFileNameInformation( _In_opt_ PFLT_CALLBACK_DATA Data, _In_opt_ PFILE_OBJECT FileObject, _In_opt_ PFLT_INSTANCE Instance, _In_ FLT_FILE_NAME_OPTIONS NameOptions, - _Outptr_ PFLT_FILE_NAME_INFORMATION *FileNameInformation + _Outptr_ PFLT_FILE_NAME_INFORMATION *FileNameInformation ) /*++ @@ -102,7 +102,7 @@ Return Value: NTSTATUS NcAllocateEResource( - _Out_ PERESOURCE * OutputLock + _Out_ PERESOURCE * OutputLock ) /*++ @@ -126,12 +126,12 @@ Return Value: PERESOURCE Lock = NULL; BOOLEAN DeleteLock = FALSE; - + PAGED_CODE(); - Lock = ExAllocatePoolWithTag( NonPagedPool, - sizeof(ERESOURCE), - NC_LOCK_TAG ); + Lock = ExAllocatePoolZero( NonPagedPool, + sizeof(ERESOURCE), + NC_LOCK_TAG ); if (Lock == NULL) { @@ -155,7 +155,7 @@ NcAllocateEResourceCleanup: if (!NT_SUCCESS( Status )) { if (Lock) { - + if (DeleteLock) { ExDeleteResourceLite( Lock ); diff --git a/filesys/miniFilter/NameChanger/ncinit.c b/filesys/miniFilter/NameChanger/ncinit.c index b61f76d9..d34dc0f0 100644 --- a/filesys/miniFilter/NameChanger/ncinit.c +++ b/filesys/miniFilter/NameChanger/ncinit.c @@ -46,7 +46,7 @@ NcLoadRegistryString ( // // Query the length of the registry value. // - + RtlInitUnicodeString( &ValueString, valueName ); NcLoadRegistryStringRetry: @@ -74,11 +74,11 @@ NcLoadRegistryStringRetry: if (TempMappingBuffer != NULL) { ExFreePoolWithTag( TempMappingBuffer, NC_TAG ); - } + } - TempMappingBuffer = ExAllocatePoolWithTag( PagedPool, - TempMappingKeyLength, - NC_TAG ); + TempMappingBuffer = ExAllocatePoolZero( PagedPool, + TempMappingKeyLength, + NC_TAG ); if (TempMappingBuffer == NULL) { @@ -131,13 +131,13 @@ NcLoadRegistryStringRetry: // // Allocate a buffer for the target string. Note that we - // allocate one fewer WCHAR, as we have no need for the + // allocate one fewer WCHAR, as we have no need for the // NULL terminator in our UNICODE_STRING. // - OutputStringBuffer = ExAllocatePoolWithTag( NonPagedPool, - TempMappingBuffer->DataLength - sizeof(WCHAR), - NC_TAG ); + OutputStringBuffer = ExAllocatePoolZero( NonPagedPool, + TempMappingBuffer->DataLength - sizeof(WCHAR), + NC_TAG ); if (OutputStringBuffer == NULL) { @@ -278,7 +278,7 @@ NcIs8DOT3Compatible ( } -NTSTATUS +NTSTATUS NcInitializeMapping( _In_ PUNICODE_STRING RegistryPath ) @@ -429,7 +429,7 @@ Return Value: if (!NcIs8DOT3Compatible( &NcGlobalData.UserMappingFinalComponentShort, &NcGlobalData.UserMappingFinalComponentLong )) { - + Status = STATUS_INVALID_PARAMETER; goto NcInitializeMappingCleanup; } @@ -443,7 +443,7 @@ Return Value: // if (!NcIs8DOT3Compatible( &NcGlobalData.RealMappingFinalComponent, NULL )) { - + Status = STATUS_INVALID_PARAMETER; goto NcInitializeMappingCleanup; } diff --git a/filesys/miniFilter/NameChanger/ncmapping.c b/filesys/miniFilter/NameChanger/ncmapping.c index 3dd05135..2e10c74a 100644 --- a/filesys/miniFilter/NameChanger/ncmapping.c +++ b/filesys/miniFilter/NameChanger/ncmapping.c @@ -99,7 +99,7 @@ NcIsMappingPathZeroed( if (Path->VolumePath.Buffer != NULL || Path->VolumePath.Length != 0 || Path->VolumePath.MaximumLength != 0) { - + return FALSE; } @@ -133,7 +133,7 @@ NcInitMappingPath ( ) /*++ -Routine Description: +Routine Description: Routine to initialize a mapping path. @@ -162,11 +162,11 @@ Routine Description: Frees the allocations in a NC_MAPPING_PATH. Arguments: - + Path - The mapping which you want to clean up. Return Value: - + None. --*/ @@ -203,7 +203,7 @@ Routine Description: Arguments: - VolumeName - Name of the volume. + VolumeName - Name of the volume. ParentPath - string for the parent of mapping. @@ -257,9 +257,9 @@ Return Value: NameLength = VolumeName->Length + ParentPath->Length + SeparatorLength + FinalComponent->Length; - NameBuffer = ExAllocatePoolWithTag( PagedPool, - NameLength, - NC_MAPPING_TAG ); + NameBuffer = ExAllocatePoolZero( PagedPool, + NameLength, + NC_MAPPING_TAG ); if (NameBuffer == NULL) { @@ -292,7 +292,7 @@ Return Value: // if (SeparatorLength != 0) { - + NameString.Buffer[NameString.Length/SeparatorLength] = NC_SEPARATOR; NameString.Length = NameString.Length + SeparatorLength; FLT_ASSERT( NameString.Length <= NameString.MaximumLength ); @@ -317,11 +317,11 @@ Return Value: Path->VolumePath.MaximumLength = VolumeName->Length; Path->ParentPath.Buffer = NameString.Buffer; - Path->ParentPath.Length = SeparatorLength == sizeof(WCHAR) ? - VolumeName->Length+ParentPath->Length : + Path->ParentPath.Length = SeparatorLength == sizeof(WCHAR) ? + VolumeName->Length+ParentPath->Length : VolumeName->Length+ParentPath->Length-sizeof(WCHAR); - Path->ParentPath.MaximumLength = SeparatorLength == sizeof(WCHAR) ? - VolumeName->Length+ParentPath->Length : + Path->ParentPath.MaximumLength = SeparatorLength == sizeof(WCHAR) ? + VolumeName->Length+ParentPath->Length : VolumeName->Length+ParentPath->Length-sizeof(WCHAR); Path->FinalComponentName.Buffer = (PWSTR)Add2Ptr( NameString.Buffer, @@ -355,7 +355,7 @@ Return Value: // // We reached the end without incident. // - + Status = STATUS_SUCCESS; NcBuildMappingPathCleanup: @@ -421,7 +421,7 @@ Return Value: if (!NT_SUCCESS( Status ) && Status != STATUS_BUFFER_TOO_SMALL) { goto NcBuildPathCleanup; - } + } // // Allocate a buffer for the name. @@ -429,9 +429,9 @@ Return Value: Status = STATUS_SUCCESS; - VolumeNameBuffer = ExAllocatePoolWithTag( PagedPool, - VolumeNameLength, - NC_MAPPING_TAG ); + VolumeNameBuffer = ExAllocatePoolZero( PagedPool, + VolumeNameLength, + NC_MAPPING_TAG ); if (VolumeNameBuffer == NULL) { @@ -509,7 +509,7 @@ Arguments: Path - Pointer to a user allocated NC_MAPPING_PATH which will be populated. -Return Value +Return Value On success, returns STATUS_SUCCESS, otherwise returns an error code. @@ -538,7 +538,7 @@ Return Value // Get File parent's name info. // - Status = NcGetFileNameInformation( NULL, + Status = NcGetFileNameInformation( NULL, Parent, Instance, NameFlags, @@ -557,7 +557,7 @@ Return Value } - FLT_ASSERT( ParentNameInfo->Format == FLT_FILE_NAME_NORMALIZED || + FLT_ASSERT( ParentNameInfo->Format == FLT_FILE_NAME_NORMALIZED || ParentNameInfo->Format == FLT_FILE_NAME_OPENED ); @@ -685,7 +685,7 @@ NcInitMapping ( } VOID -NcTeardownMapping ( +NcTeardownMapping ( _Inout_ PNC_MAPPING Mapping ) { diff --git a/filesys/miniFilter/NameChanger/ncnameprov.c b/filesys/miniFilter/NameChanger/ncnameprov.c index 1d746388..c2b70eb4 100644 --- a/filesys/miniFilter/NameChanger/ncnameprov.c +++ b/filesys/miniFilter/NameChanger/ncnameprov.c @@ -44,26 +44,26 @@ NcGenerateFileName ( // // Contexts // - + PNC_INSTANCE_CONTEXT InstanceContext = NULL; // // Overlap // - + NC_PATH_OVERLAP RealOverlap; UNICODE_STRING RealRemainder = EMPTY_UNICODE_STRING; // // Temp storage // - + UNICODE_STRING MungedName = EMPTY_UNICODE_STRING; - + // // Temp pointer // - + PUNICODE_STRING Name = NULL; // Pointer to the name we are going to use. PAGED_CODE(); @@ -86,7 +86,7 @@ NcGenerateFileName ( RealOverlap.EntireFlags = 0; // - // To prevent infinite recursion, calls to FltGetFileNameInformation + // To prevent infinite recursion, calls to FltGetFileNameInformation // from generate file name callbacks should not target current provider. // @@ -96,7 +96,7 @@ NcGenerateFileName ( // Fetch the instance context. // - Status = FltGetInstanceContext( Instance, &InstanceContext ); + Status = FltGetInstanceContext( Instance, &InstanceContext ); if (!NT_SUCCESS( Status )) { @@ -135,12 +135,12 @@ NcGenerateFileName ( // Issues With Pre-open path: // // 1) Poison name cache below name provider: - // If a filter above a name provider calls FltGetFileNameInformation on a - // file object in his precreate callback, fltmgr will call the name + // If a filter above a name provider calls FltGetFileNameInformation on a + // file object in his precreate callback, fltmgr will call the name // provider's generate name callback before the name provider's pre create // callback is invoked. Name providers by their nature change names in their - // pre-create. Because the name provider has not had the opportunity to - // modify the name yet, we need to make sure that fltmgr does not cache the name we + // pre-create. Because the name provider has not had the opportunity to + // modify the name yet, we need to make sure that fltmgr does not cache the name we // return below us, so we set the FLT_FILE_NAME_DO_NOT_CACHE flag. // //TODO: TRY TO GET ACROSS THAT THIS IS A NAME CHANGER PROBLEM, NOT ALL NAME PROVIDERS NEED TO. // @@ -153,7 +153,7 @@ NcGenerateFileName ( // // NT supports case sensitive and non-case sensitive naming in file systems. - // This is handled on a per-open basis. Weather an open is case senstive is + // This is handled on a per-open basis. Weather an open is case senstive is // determined by the FO_OPENED_CASE_SENSITIVE flag on the file object. // In pre-create the SL_CASE_SENSITIVE flag on the create IRP specifies the mode. // @@ -270,7 +270,7 @@ NcGenerateFileName ( Status = NcGetFileNameInformation( Data, FileObject, Instance, - FLT_FILE_NAME_SHORT | + FLT_FILE_NAME_SHORT | NameQueryMethod | NameFlags, &ShortInfo ); @@ -395,7 +395,7 @@ NcNormalizeNameComponentEx ( &Remainder, IgnoreCase, TRUE, - &ParentOverlap ); + &ParentOverlap ); // // We need to figure out which path we are going to open. @@ -404,13 +404,13 @@ NcNormalizeNameComponentEx ( if (ParentOverlap.InMapping) { // - // The parent is in the mapping, so it has to be + // The parent is in the mapping, so it has to be // munged in order to be opened. // MungedBufferLength = Remainder.Length + InstanceContext->Mapping.RealMapping.LongNamePath.FullPath.Length; - - MungedBuffer = ExAllocatePoolWithTag( PagedPool, MungedBufferLength, NC_NORMALIZE_NAME_TAG ); + + MungedBuffer = ExAllocatePoolZero( PagedPool, MungedBufferLength, NC_NORMALIZE_NAME_TAG ); if (MungedBuffer == NULL) { @@ -428,7 +428,7 @@ NcNormalizeNameComponentEx ( RtlCopyUnicodeString( &MungedParentPath, &InstanceContext->Mapping.RealMapping.LongNamePath.FullPath ); - + RtlAppendUnicodeStringToString( &MungedParentPath, &Remainder); @@ -436,7 +436,7 @@ NcNormalizeNameComponentEx ( // // The parent is the parent of the user mapping. - // That means we need to see if the final component is + // That means we need to see if the final component is // the mapping path itself. // @@ -468,10 +468,10 @@ NcNormalizeNameComponentEx ( } else { //ParentOverlap is not within or parent of mapping. MungedParentPath = *ParentDirectory; - } + } // - // We should open MungedParentPath and enumerate it. + // We should open MungedParentPath and enumerate it. // InitializeObjectAttributes( &ParentAttributes, @@ -496,7 +496,7 @@ NcNormalizeNameComponentEx ( 0, IO_IGNORE_SHARE_ACCESS_CHECK, FileObject ); - + if (!NT_SUCCESS( Status )) { goto NcNormalizeNameComponentExCleanup; @@ -542,10 +542,10 @@ NcNormalizeNameComponentEx ( RtlCopyMemory( ExpandComponentName->FileName, InstanceContext->Mapping.UserMapping.LongNamePath.FinalComponentName.Buffer, InstanceContext->Mapping.UserMapping.LongNamePath.FinalComponentName.Length ); - + } - //TODO THIS NEEDS TO + //TODO THIS NEEDS TO NcNormalizeNameComponentExCleanup: diff --git a/filesys/miniFilter/NameChanger/ncpath.c b/filesys/miniFilter/NameChanger/ncpath.c index 4f892e36..524f6ad1 100644 --- a/filesys/miniFilter/NameChanger/ncpath.c +++ b/filesys/miniFilter/NameChanger/ncpath.c @@ -30,7 +30,7 @@ Arguments: Mapping - The mapping path we are comparing against. - Remainder - If the string matches the mapping, then Remainder will be + Remainder - If the string matches the mapping, then Remainder will be the portion of the name after the mapping to the end of the string. @@ -170,7 +170,7 @@ Return Value: // // If the paths we are comparing against have - // both ether run out or hit the end of their + // both ether run out or hit the end of their // respective components, then we need to break. // @@ -237,7 +237,7 @@ Return Value: } // - // Loop if there is still chance of match + // Loop if there is still chance of match // } while(LongMatch || ShortMatch);// end of character scan. @@ -245,7 +245,7 @@ Return Value: // // We scanned until we had 2 mismatches or we ran off the end of the name, // or we ran off the end of the long and short names. - // We should scan everyone forward until they are all off the end of their + // We should scan everyone forward until they are all off the end of their // buffer, or it the end of their component. // @@ -288,9 +288,9 @@ Return Value: // LongMatch = FALSE; - LongIndex++; + LongIndex++; } - + while( ShortIndex < ShortLength && ShortBuff[ShortIndex] != '\\' ) { // @@ -298,7 +298,7 @@ Return Value: // So it cannot be a match. // Scan forward until we find the end. // - + ShortMatch = FALSE; ShortIndex++; } @@ -336,7 +336,7 @@ Return Value: } // - // Keep looping if name's last component matched either + // Keep looping if name's last component matched either // the long or short's component and name and the mapping // have more components. // @@ -505,9 +505,9 @@ Return Value: // Allocate space for combined name. // - NameBuffer = ExAllocatePoolWithTag( PagedPool, - NameLength, - NC_GENERATE_NAME_TAG ); + NameBuffer = ExAllocatePoolZero( PagedPool, + NameLength, + NC_GENERATE_NAME_TAG ); if (NameBuffer == NULL) { @@ -516,7 +516,7 @@ Return Value: } // - // Zero out destination + // Zero out destination // NewName->Buffer = NameBuffer; @@ -623,18 +623,18 @@ NcParseFinalComponent( return STATUS_INVALID_PARAMETER; } - ParentStringBuffer = ExAllocatePoolWithTag( NonPagedPool, - ParentLength, - NC_TAG ); + ParentStringBuffer = ExAllocatePoolZero( NonPagedPool, + ParentLength, + NC_TAG ); if (ParentStringBuffer == NULL) { Status = STATUS_INSUFFICIENT_RESOURCES; goto NcParseFinalComponentCleanup; } - FinalStringBuffer = ExAllocatePoolWithTag( NonPagedPool, - FinalComponentLength, - NC_TAG ); + FinalStringBuffer = ExAllocatePoolZero( NonPagedPool, + FinalComponentLength, + NC_TAG ); if (FinalStringBuffer == NULL) { Status = STATUS_INSUFFICIENT_RESOURCES; @@ -644,7 +644,7 @@ NcParseFinalComponent( RtlCopyMemory( ParentStringBuffer, EntirePath->Buffer, ParentLength ); ParentPath->Buffer = ParentStringBuffer; - ParentPath->MaximumLength = + ParentPath->MaximumLength = ParentPath->Length = ParentLength; RtlCopyMemory( FinalStringBuffer, &EntirePath->Buffer[Index + 1], FinalComponentLength ); diff --git a/filesys/miniFilter/avscan/filter/communication.c b/filesys/miniFilter/avscan/filter/communication.c index a38effb7..91dc3c07 100644 --- a/filesys/miniFilter/avscan/filter/communication.c +++ b/filesys/miniFilter/avscan/filter/communication.c @@ -9,7 +9,7 @@ Module Name: Abstract: Communication module implementation. - This module contains the routines that involves the communication + This module contains the routines that involves the communication between kernel mode and user mode. Environment: @@ -28,12 +28,12 @@ AvConnectNotifyCallback ( _In_ ULONG SizeOfContext, _Outptr_result_maybenull_ PVOID *ConnectionCookie ); - + VOID AvDisconnectNotifyCallback( _In_opt_ PVOID ConnectionCookie ); - + NTSTATUS AvMessageNotifyCallback ( _In_ PVOID ConnectionCookie, @@ -53,13 +53,13 @@ AvGetScanCtxSynchronized ( _In_ LONGLONG ScanId, _Out_ PAV_SCAN_CONTEXT *ScanCtx ); - + NTSTATUS AvGetInstanceContextByVolume ( _In_ PFLT_VOLUME volumeObject, _Out_ PAV_INSTANCE_CONTEXT *InstanceContext ); - + NTSTATUS AvGetInstanceContextByFileHandle ( _In_ HANDLE Handle, @@ -78,25 +78,25 @@ AvUpdateStreamContextWithScanResult ( _In_ PAV_SCAN_CONTEXT ScanContext, _In_ AVSCAN_RESULT ScanResult ); - + NTSTATUS AvHandleCmdCreateSectionForDataScan ( _Inout_ PAV_SCAN_CONTEXT ScanContext, _Out_ PHANDLE SectionHandle ); - + NTSTATUS AvHandleCmdCloseSectionForDataScan ( _Inout_ PAV_SCAN_CONTEXT ScanContext, _In_ AVSCAN_RESULT ScanResult ); - + #ifdef ALLOC_PRAGMA #pragma alloc_text(PAGE, AvMessageNotifyCallback) #pragma alloc_text(PAGE, AvConnectNotifyCallback) #pragma alloc_text(PAGE, AvDisconnectNotifyCallback) #pragma alloc_text(PAGE, AvPrepareServerPort) - + #pragma alloc_text(PAGE, AvGetInstanceContextByVolume) #pragma alloc_text(PAGE, AvGetInstanceContextByFileHandle) #pragma alloc_text(PAGE, AvGetStreamContextByHandle) @@ -126,14 +126,14 @@ Routine Description Arguments ClientPort - This is the client connection port that will be used to send messages from the filter - + ServerPortCookie - Unused - - ConnectionContext - The connection context passed from the user. This is to recognize which type + + ConnectionContext - The connection context passed from the user. This is to recognize which type connection the user is trying to connect. - + SizeofContext - The size of the connection context. - + ConnectionCookie - Propagation of the connection context to disconnection callback. Return Value @@ -145,26 +145,26 @@ Return Value { PAV_CONNECTION_CONTEXT connectionCtx = (PAV_CONNECTION_CONTEXT) ConnectionContext; PAVSCAN_CONNECTION_TYPE connectionCookie = NULL; - + PAGED_CODE(); UNREFERENCED_PARAMETER( ServerPortCookie ); UNREFERENCED_PARAMETER( SizeOfContext ); - + if (NULL == connectionCtx) { - + return STATUS_INVALID_PARAMETER_3; } - + // // ConnectionContext passed in may be deleted. We need to make a copy of it. // - - connectionCookie = ExAllocatePoolWithTag( PagedPool, - sizeof(AVSCAN_CONNECTION_TYPE), - AV_CONNECTION_CTX_TAG ); + + connectionCookie = ExAllocatePoolZero( PagedPool, + sizeof(AVSCAN_CONNECTION_TYPE), + AV_CONNECTION_CTX_TAG ); if (NULL == connectionCookie) { - + return STATUS_INSUFFICIENT_RESOURCES; } @@ -190,10 +190,10 @@ Return Value *ConnectionCookie = NULL; return STATUS_INVALID_PARAMETER_3; } - + AV_DBG_PRINT( AVDBG_TRACE_DEBUG, ("[AV]: AvConnectNotifyCallback entered. type: %d \n", connectionCtx->Type) ); - + return STATUS_SUCCESS; } @@ -209,7 +209,7 @@ Routine Description This is called when user-mode disconnects the server port. Arguments - + ConnectionCookie - The cookie set in AvConnectNotifyCallback(...). It is connection context. Return Value @@ -218,11 +218,11 @@ Return Value --*/ { PAVSCAN_CONNECTION_TYPE connectionType = (PAVSCAN_CONNECTION_TYPE) ConnectionCookie; - + PAGED_CODE(); if (NULL == connectionType) { - + return; } // @@ -246,10 +246,10 @@ Return Value ("[AV]: AvDisconnectNotifyCallback: No such connection type. \n") ); return; } - + AV_DBG_PRINT( AVDBG_TRACE_DEBUG, ("[AV]: AvDisconnectNotifyCallback entered. type: %d \n", *connectionType) ); - + ExFreePoolWithTag( connectionType, AV_CONNECTION_CTX_TAG ); @@ -265,10 +265,10 @@ AvGetScanCtxSynchronized ( Routine Description A helper function to retrieve the scan context from its scan context id. - It is synchronized by a lock. + It is synchronized by a lock. Arguments - + ScanId - The scan id to be found. ScanCtx - The output scan context. NULL if not found @@ -276,52 +276,52 @@ Return Value STATUS_SUCCESS - if found. Otherwise - Error, or if not found. - + --*/ { PLIST_ENTRY link; NTSTATUS status = STATUS_SUCCESS; BOOLEAN found = FALSE; PAV_SCAN_CONTEXT scanCtx = NULL; - + // // We only 'read' the scan context when we traversing the list // - + AvAcquireResourceShared( &Globals.ScanCtxListLock ); - + for (link = Globals.ScanCtxListHead.Flink; link != &Globals.ScanCtxListHead; link = link->Flink) { scanCtx = CONTAINING_RECORD( link, AV_SCAN_CONTEXT, List ); - + if (scanCtx->ScanId == ScanId) { found = TRUE; AvReferenceScanContext( scanCtx ); break; } - + } - + AvReleaseResource( &Globals.ScanCtxListLock ); - + if (found) { - + *ScanCtx = scanCtx; return STATUS_SUCCESS; } - + AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("[AV] AvGetScanCtxSynchronized: scan context not found. \n") ); - + *ScanCtx = NULL; - + if (NT_SUCCESS( status )){ - + status = STATUS_UNSUCCESSFUL; } - + return status; } @@ -335,12 +335,12 @@ AvGetInstanceContextByVolume ( Routine Description A helper function to retrieve the instance context from its volume object. - - The caller is responsible for dereference InstanceContext via calling + + The caller is responsible for dereference InstanceContext via calling FltReleaseContext(...) if success. Arguments - + VolumeObject - The volume object. InstanceContext - The output instance context. NULL if not found @@ -356,62 +356,62 @@ Return Value PFLT_INSTANCE *instArray = NULL; ULONG instCnt = 0; PAV_INSTANCE_CONTEXT instCtx = NULL; - + PAGED_CODE(); - + status = AvEnumerateInstances ( &instArray, &instCnt ); - + if ( !NT_SUCCESS(status) ) { - + AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("[AV] AvGetInstanceContextByVolume: Failed to enumerate instances. \n") ); return status; } - + for (i = 0; i < instCnt; i++) { - + status = FltGetInstanceContext( instArray[i], &instCtx ); - + if ( !NT_SUCCESS(status) ) { AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("[AV] AvGetInstanceContextByVolume: Failed to get instance context. \n") ); break; } - + if (instCtx->Volume == VolumeObject) { - + // // When found, we do not release the reference of instance context // because the caller is responsible for releasing it. // - + found = TRUE; break; } - + FltReleaseContext( instCtx ); } AvFreeInstances( instArray, instCnt ); instArray = NULL; - + if (found) { - + *InstanceContext = instCtx; return STATUS_SUCCESS; } - + AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("[AV] AvGetInstanceContextByVolume: instance context not found. \n") ); - + if ( NT_SUCCESS( status ) ){ - + status = STATUS_UNSUCCESSFUL; } - + instCtx = NULL; - + return status; } @@ -425,12 +425,12 @@ AvGetInstanceContextByFileHandle ( Routine Description A helper function to retrieve the instance context from file handle. - - The caller is responsible for dereference InstanceContext via calling + + The caller is responsible for dereference InstanceContext via calling FltReleaseContext(...) if success. Arguments - + Handle - The file handle of interest. InstanceContext - The output instance context. NULL if not found @@ -443,13 +443,13 @@ Return Value NTSTATUS status = STATUS_SUCCESS; PFILE_OBJECT fileObject = NULL; PFLT_VOLUME volumeObject = NULL; - + PAGED_CODE(); - + // // Get file object by handle // - + status = ObReferenceObjectByHandle ( Handle, 0, @@ -457,37 +457,37 @@ Return Value KernelMode, (PVOID *)&fileObject, NULL - ); + ); if (!NT_SUCCESS(status)) { - + AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("[AV] AvGetInstanceContextByFileHandle: Failed to get file object by handle. \n") ); return status; } - + try { - + status = FltGetVolumeFromFileObject( Globals.Filter, fileObject, &volumeObject ); - + if (!NT_SUCCESS(status)) { AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("[AV] AvGetInstanceContextByFileHandle: Failed to get volume by file object. \n") ); leave; } - + status = AvGetInstanceContextByVolume(volumeObject, InstanceContext); - + FltObjectDereference( volumeObject ); - + } finally { - + ObDereferenceObject( fileObject ); } - + return status; -} +} NTSTATUS AvGetStreamContextByHandle ( @@ -498,15 +498,15 @@ AvGetStreamContextByHandle ( Routine Description - A helper function to retrieve the stream context from a file handle at message - callback routine. This function will increment the reference count of the + A helper function to retrieve the stream context from a file handle at message + callback routine. This function will increment the reference count of the output stream context. - + The caller is responsible for dereference it via calling FltReleaseContext(...) if success. Arguments - + Handle - The file handle of interest. StreamContext - The output stream context. NULL if not found @@ -519,19 +519,19 @@ Return Value NTSTATUS status; PFILE_OBJECT fileObject = NULL; PAV_INSTANCE_CONTEXT instanceContext = NULL; - + PAGED_CODE(); - + status = AvGetInstanceContextByFileHandle( Handle, &instanceContext); - + if (!NT_SUCCESS(status)) { - + AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("[AV]: ***AvGetInstanceContextByFileHandle FAILED. \n") ); return status; } try { - + status = ObReferenceObjectByHandle ( Handle, 0, @@ -539,22 +539,22 @@ Return Value KernelMode, (PVOID *)&fileObject, NULL - ); + ); if (!NT_SUCCESS(status)) { - + AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("[AV] AvGetStreamContextByHandle: Failed to get file object by handle. \n") ); leave; } - + status = FltGetStreamContext( instanceContext->Instance, fileObject, StreamContext ); ObDereferenceObject( fileObject ); - + } finally { - + FltReleaseContext( instanceContext ); } return status; @@ -570,9 +570,9 @@ AvHandleCmdCreateSectionForDataScan ( Routine Description: This function handles CmdCreateSectionForDataScan message. - This function will create and return the section handle to the caller. + This function will create and return the section handle to the caller. If any error occurs, it will trigger events to release the waiting threads. - + NOTE: this function does not check the buffer size etc. It must be checked before passing into this function. @@ -592,37 +592,37 @@ Return Value: PAV_STREAM_CONTEXT streamContext = NULL; PAV_SECTION_CONTEXT sectionContext = NULL; HANDLE sectionHandle = NULL; - + PAGED_CODE(); - status = FltGetStreamContext ( ScanContext->FilterInstance, - ScanContext->FileObject, + status = FltGetStreamContext ( ScanContext->FilterInstance, + ScanContext->FileObject, &streamContext ); if (!NT_SUCCESS( status )) { AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("[AV] AvHandleCmdCreateSectionForDataScan: failed to get stream context.\n") ); - + goto Cleanup; } // // It should be impossible for the stream state to change from - // uknown to clean since we kicked off this scan. + // uknown to clean since we kicked off this scan. // - + ASSERT(IS_FILE_NEED_SCAN( streamContext )); - - status = AvCreateSectionContext( ScanContext->FilterInstance, - ScanContext->FileObject, + + status = AvCreateSectionContext( ScanContext->FilterInstance, + ScanContext->FileObject, §ionContext); - + if (!NT_SUCCESS( status )) { AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("[AV] AvHandleCmdCreateSectionForDataScan: failed to create section context.\n") ); - + goto Cleanup; } @@ -631,14 +631,14 @@ Return Value: // it means that the thread is trying to cancel this scan, and thus we don't want the scan to proceed anymore. // if (ScanContext->IoWaitOnScanCompleteNotificationAborted) { - + status = STATUS_CANCELLED; AV_DBG_PRINT( AVDBG_TRACE_DEBUG, ("[AV] AvHandleCmdCreateSectionForDataScan: Before FltCreateSectionForDataScan, it found Io is trying to abort the wait.\n") ); - + goto Cleanup; } - + sectionContext->ScanContext = ScanContext; sectionContext->CancelableOnConflictingIo = (ScanContext->IOMajorFunctionAtScan == IRP_MJ_CLEANUP); @@ -648,7 +648,7 @@ Return Value: // passed to the callback won't have the SectionHandle and // SectionObject fields set yet. // - + status = FltCreateSectionForDataScan( ScanContext->FilterInstance, ScanContext->FileObject, sectionContext, @@ -663,9 +663,9 @@ Return Value: NULL ); sectionHandle = sectionContext->SectionHandle; - + if (!NT_SUCCESS( status )) { - + #if DBG NTSTATUS sta = STATUS_SUCCESS; PFLT_VOLUME volumeObject = NULL; @@ -700,58 +700,58 @@ Return Value: goto Cleanup; } - + // // Before scanning, we set the file status as scanning. - // This is important when another thread is writing to this file while we are scanning + // This is important when another thread is writing to this file while we are scanning // this file. // - + SET_FILE_SCANNING_EX( ScanContext->IsFileInTxWriter, streamContext ); - + // // Only after the section object is successfully created, we put a section context pointer - // into the scan context. + // into the scan context. // - + FltReferenceContext( sectionContext ); ScanContext->SectionContext = sectionContext; *SectionHandle = sectionHandle; - + Cleanup: // // The I/O request thread is waiting for this event. // If any error occurs, we have to release the waiting thread. - // if status is a success code, the thread will get released when + // if status is a success code, the thread will get released when // the user send message to close the section object. // - + if (!NT_SUCCESS( status )) { - + KeSetEvent( &ScanContext->ScanCompleteNotification, 0, FALSE ); } - + if (streamContext) { // // On error signal the event to release any threads waiting to - // scan the same file. On success it will get released when the + // scan the same file. On success it will get released when the // message is sent to close the section object. // - + if (!NT_SUCCESS( status )) { - + SET_FILE_MODIFIED_EX( ScanContext->IsFileInTxWriter, streamContext ); } - + FltReleaseContext( streamContext ); streamContext = NULL; } - + if (sectionContext) { - + FltReleaseContext( sectionContext ); sectionContext = NULL; } @@ -764,25 +764,25 @@ Cleanup: // if (NT_SUCCESS( status ) && ScanContext->IoWaitOnScanCompleteNotificationAborted) { - + status = STATUS_CANCELLED; AV_DBG_PRINT( AVDBG_TRACE_DEBUG, ("[AV] AvHandleCmdCreateSectionForDataScan: After FltCreateSectionForDataScan, it found Io is trying to abort the wait.\n") ); // - // We explicitly call NtClose() instead of ZwClose() so that PreviousMode() will be User. - // This prevents accidental closing of a kernel handle and also will not bugcheck the + // We explicitly call NtClose() instead of ZwClose() so that PreviousMode() will be User. + // This prevents accidental closing of a kernel handle and also will not bugcheck the // system if the handle value is no longer valid // NtClose( sectionHandle ); - + // // This user mode handle is supposed to be closed in the user mode program. // We close in the context of the same process context. // AvFinalizeScanAndSection( ScanContext ); } - + return status; } @@ -794,73 +794,73 @@ AvUpdateStreamContextWithScanResult ( _In_ AVSCAN_RESULT ScanResult ) /*++ - + Routine Description: This function updates StreamContex according to ScanResult. e.g. Set the stream as modified, infected, etc. - + Arguments: StreamContext - The stream context to be updated. ScanContext - The scan context. - + ScanResult - The scan result. Please see the definition of AVSCAN_RESULT. Return Value: Returns STATUS_SUCCESS. - + --*/ { NTSTATUS status = STATUS_SUCCESS; PAGED_CODE(); - + switch( ScanResult ) { - + case AvScanResultUndetermined: AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("***[AV] AvUpdateScanResult: the caller did not specify the scan result.\n") ); // - // If for some reason, the scan result returns undetermined, we have to + // If for some reason, the scan result returns undetermined, we have to // set the file state back to AvFileModifed. // - + SET_FILE_MODIFIED_EX( ScanContext->IsFileInTxWriter, StreamContext); break; case AvScanResultInfected: // - // If after the scan and before setting this file as clean, the file gets modified, + // If after the scan and before setting this file as clean, the file gets modified, // then we have to leave it as modified. // - + if (ScanContext->IsFileInTxWriter) { - + InterlockedCompareExchange( &StreamContext->TxState, AvFileInfected, AvFileScanning ); - + } else { - + InterlockedCompareExchange( &StreamContext->State, AvFileInfected, AvFileScanning ); } break; case AvScanResultClean: - + // - // If after the scan and before setting this file as clean, the file gets modified, + // If after the scan and before setting this file as clean, the file gets modified, // then we have to leave it as modified. // - + if (ScanContext->IsFileInTxWriter) { - + InterlockedCompareExchange( &StreamContext->TxState, AvFileNotInfected, AvFileScanning ); - + } else { - + InterlockedCompareExchange( &StreamContext->State, AvFileNotInfected, AvFileScanning ); } - + break; default: FLT_ASSERTMSG( "No such scan result.\n", FALSE); @@ -875,13 +875,13 @@ AvFinalizeScanAndSection ( _Inout_ PAV_SCAN_CONTEXT ScanContext ) /*++ - + Routine Description: This function is a wrapper function to finalize scan context and section context. Normally, you should call this function if you don't need to use section context before closing it. - + Arguments: ScanContext - The scan context. @@ -889,21 +889,21 @@ Arguments: Return Value: Returns the status code from FltCloseSectionForDataScan. - + --*/ { NTSTATUS status = STATUS_SUCCESS; PAV_SECTION_CONTEXT sectionContext = NULL; PAGED_CODE(); - + AvFinalizeScanContext( ScanContext, §ionContext ); - + // // This thread won the race, and is responsible for finalizing the section context // if (sectionContext != NULL) { - + status = AvFinalizeSectionContext( sectionContext ); } return status; @@ -915,27 +915,27 @@ AvFinalizeScanContext ( _Outptr_result_maybenull_ PAV_SECTION_CONTEXT *SectionContext ) /*++ - + Routine Description: - This function interlocked-exchange the section context inside the scan context and + This function interlocked-exchange the section context inside the scan context and release the waiting I/O request thread. - The caller is responsible for releasing the reference count of SectionContext + The caller is responsible for releasing the reference count of SectionContext when it successfully exchanges a non-NULL section context. - + Arguments: ScanContext - The scan context. - SectionContext - Receives the sectioncontext address indicating the caller is - responsible for tearing down the sectioncontext. + SectionContext - Receives the sectioncontext address indicating the caller is + responsible for tearing down the sectioncontext. Receives NULL if the context is already being torn down by another thread. Return Value: None. - + --*/ { PAV_SECTION_CONTEXT oldSectionCtx = NULL; @@ -952,7 +952,7 @@ Return Value: oldSectionCtx = InterlockedExchangePointer( &ScanContext->SectionContext, NULL ); // - // If sectionContext is NULL, it means that another thread has + // If sectionContext is NULL, it means that another thread has // already begun teardown of the section. // @@ -976,12 +976,12 @@ AvFinalizeSectionContext ( _Inout_ PAV_SECTION_CONTEXT SectionContext ) /*++ - + Routine Description: This function is a wrapper function to finalize section context. It closes the section context/object and release its reference. - + Arguments: SectionContext - The section context. @@ -989,18 +989,18 @@ Arguments: Return Value: Returns the status code from FltCloseSectionForDataScan. - + --*/ { NTSTATUS status = STATUS_SUCCESS; PAGED_CODE(); - + status = AvCloseSectionForDataScan( SectionContext ); if (!NT_SUCCESS(status)) { - + AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("***[AV]: AvFinalizeSectionContext: Close section failed.\n") ); } @@ -1019,7 +1019,7 @@ Routine Description: This function handles AvCmdCloseSectionForDataScan message. This function will - + 1) close the section object 2) Set the file clean or infected. 3) trigger events to release the waiting threads. @@ -1027,7 +1027,7 @@ Routine Description: Arguments: ScanContext - The scan context. - + ScanResult - The scan result. Please see the definition of AVSCAN_RESULT. Return Value: @@ -1038,11 +1038,11 @@ Return Value: { NTSTATUS status = STATUS_SUCCESS; PAV_STREAM_CONTEXT streamContext = NULL; - + PAGED_CODE(); - - status = FltGetStreamContext ( ScanContext->FilterInstance, - ScanContext->FileObject, + + status = FltGetStreamContext ( ScanContext->FilterInstance, + ScanContext->FileObject, &streamContext ); if (!NT_SUCCESS( status )) { @@ -1052,28 +1052,28 @@ Return Value: goto Cleanup; } - + // // Update stream context will succeed. // - AvUpdateStreamContextWithScanResult(streamContext, ScanContext, ScanResult); + AvUpdateStreamContextWithScanResult(streamContext, ScanContext, ScanResult); Cleanup: status = AvFinalizeScanAndSection( ScanContext ); - + // // Either the above operations are successful, or any error occur, // we have to release the stream context. // if ( streamContext ) { - + FltReleaseContext( streamContext ); } return status; - + } NTSTATUS @@ -1091,9 +1091,9 @@ Routine Description: This routine is called whenever the user program sends message to filter via FilterSendMessage(...). - + The user space scanner sends message to - + 1) Create the section for data scan 2) Close the section for data scan 3) Set a certain file to be infected @@ -1129,22 +1129,22 @@ Return Value: AVSCAN_RESULT scanResult = AvScanResultUndetermined; PAV_STREAM_CONTEXT streamContext; HANDLE sectionHandle; - + PAGED_CODE(); UNREFERENCED_PARAMETER( ConnectionCookie ); - + AV_DBG_PRINT( AVDBG_TRACE_ROUTINES, ("[AV]: AvMessageNotifyCallback entered. \n") ); - - + + if ((InputBuffer == NULL) || (InputBufferSize < (FIELD_OFFSET(COMMAND_MESSAGE, Command) + sizeof(AVSCAN_COMMAND)))) { return STATUS_INVALID_PARAMETER; } - + try { // @@ -1159,20 +1159,20 @@ Return Value: return GetExceptionCode(); } - + // - // Only + // Only // AvCmdCreateSectionForDataScan // AvCmdCloseSectionForDataScan // require the check of scanCtxId // // We also check the output buffer size, and its alignment here. // - + switch (command) { case AvCmdCreateSectionForDataScan: - + if ((OutputBufferSize < sizeof (HANDLE)) || (OutputBuffer == NULL)) { @@ -1183,41 +1183,41 @@ Return Value: return STATUS_DATATYPE_MISALIGNMENT; } - + status = AvGetScanCtxSynchronized( scanId, &scanContext ); - + if (!NT_SUCCESS( status )) { - + return STATUS_NOT_FOUND; } status = AvHandleCmdCreateSectionForDataScan( scanContext, §ionHandle ); - + if (NT_SUCCESS(status)) { // - // We succesfully created a section object/handle. + // We succesfully created a section object/handle. // Try to set the handle in the OutputBuffer // try { - + (*(PHANDLE)OutputBuffer) = sectionHandle; *ReturnOutputBufferLength = sizeof(HANDLE); - + } except (AvExceptionFilter( GetExceptionInformation(), TRUE )) { // // We cannot depend on user service program to close this handle for us. - // We explicitly call NtClose() instead of ZwClose() so that PreviousMode() will be User. - // This prevents accidental closing of a kernel handle and also will not bugcheck the + // We explicitly call NtClose() instead of ZwClose() so that PreviousMode() will be User. + // This prevents accidental closing of a kernel handle and also will not bugcheck the // system if the handle value is no longer valid // NtClose( sectionHandle ); - + // // Close section and release the waiting I/O request thread // We treat invalid user buffer as an exception and remove - // section object inside scan context. You can also design a protocol + // section object inside scan context. You can also design a protocol // that have user program to re-try for section creation failure. // AvFinalizeScanAndSection( scanContext ); @@ -1229,13 +1229,13 @@ Return Value: // AvGetScanCtxSynchronized incremented the ref count of scan context // AvReleaseScanContext( scanContext ); - + break; - + case AvCmdCloseSectionForDataScan: - + try { - + scanResult = ((PCOMMAND_MESSAGE) InputBuffer)->ScanResult; if (scanResult == AvScanResultInfected) { @@ -1247,12 +1247,12 @@ Return Value: return GetExceptionCode(); } - + status = AvGetScanCtxSynchronized( scanId, &scanContext ); - + if (!NT_SUCCESS( status )) { - + return STATUS_NOT_FOUND; } @@ -1266,20 +1266,20 @@ Return Value: // AvGetScanCtxSynchronized incremented the ref count of scan context // AvReleaseScanContext( scanContext ); - + break; - + case AvIsFileModified: - + try { - + hFile = ((PCOMMAND_MESSAGE) InputBuffer)->FileHandle; - + } except (AvExceptionFilter( GetExceptionInformation(), TRUE )) { return GetExceptionCode(); } - + if ((OutputBufferSize < sizeof (BOOLEAN)) || (OutputBuffer == NULL)) { @@ -1294,23 +1294,23 @@ Return Value: // // Get file object by file handle // Get PFLT_VOLUME by file object - // Get instance context by PFLT_VOLUME + // Get instance context by PFLT_VOLUME // Get filter instance in instance context // Get stream context by file object and instance context // Return if the file was previously modified // - + status = AvGetStreamContextByHandle( hFile, &streamContext ); - + if (!NT_SUCCESS(status)) { - + AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("[AV]: **************************AvGetStreamContextByHandle FAILED. \n") ); break; } try { - + (*(PBOOLEAN) OutputBuffer) = (BOOLEAN) IS_FILE_MODIFIED( streamContext ); *ReturnOutputBufferLength = (ULONG) sizeof( BOOLEAN ); @@ -1318,21 +1318,21 @@ Return Value: status = GetExceptionCode(); } - + FltReleaseContext( streamContext ); - + break; - + default: return STATUS_INVALID_PARAMETER; } - + return status; } NTSTATUS -AvPrepareServerPort( +AvPrepareServerPort( _In_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ AVSCAN_CONNECTION_TYPE ConnectionType ) @@ -1360,12 +1360,12 @@ Return Value: LONG maxConnections = 1; PCWSTR portName = NULL; PFLT_PORT *pServerPort = NULL; - + PAGED_CODE(); - + AV_DBG_PRINT( AVDBG_TRACE_DEBUG, ("[AV]: AvPrepareServerPort entered. \n") ); - + switch( ConnectionType ) { case AvConnectForScan: portName = AV_SCAN_PORT_NAME; @@ -1400,7 +1400,7 @@ Return Value: AvDisconnectNotifyCallback, AvMessageNotifyCallback, maxConnections ); - + return status; } diff --git a/filesys/miniFilter/avscan/filter/context.c b/filesys/miniFilter/avscan/filter/context.c index 8977014d..82270c94 100644 --- a/filesys/miniFilter/avscan/filter/context.c +++ b/filesys/miniFilter/avscan/filter/context.c @@ -21,7 +21,7 @@ Environment: // // Local function prototypes. // - + VOID AvStreamContextCleanup ( _In_ PFLT_CONTEXT Context, @@ -45,7 +45,7 @@ AvInstanceContextCleanup( _In_ PFLT_CONTEXT Context, _In_ FLT_CONTEXT_TYPE ContextType ); - + #ifdef ALLOC_PRAGMA #pragma alloc_text(PAGE, AvCreateStreamContext) #pragma alloc_text(PAGE, AvCreateStreamHandleContext) @@ -59,8 +59,8 @@ AvInstanceContextCleanup( #pragma alloc_text(PAGE, AvReferenceScanContext) #pragma alloc_text(PAGE, AvReleaseScanContext) #endif - - + + // // Context registration structure // @@ -78,13 +78,13 @@ const FLT_CONTEXT_REGISTRATION ContextRegistration[] = { NULL, AV_STREAMHANDLE_CONTEXT_SIZE, AV_STREAMHANDLE_CONTEXT_TAG }, - + { FLT_TRANSACTION_CONTEXT, 0, AvTransactionContextCleanup, AV_TRANSACTION_CONTEXT_SIZE, AV_TRANSACTION_CONTEXT_TAG }, - + { FLT_SECTION_CONTEXT, 0, AvSectionContextCleanup, @@ -96,7 +96,7 @@ const FLT_CONTEXT_REGISTRATION ContextRegistration[] = { AvInstanceContextCleanup, AV_INSTANCE_CONTEXT_SIZE, AV_INSTANCE_CONTEXT_TAG }, - + { FLT_CONTEXT_END } }; @@ -110,17 +110,17 @@ AvStreamContextCleanup ( Routine Description: - This function is called by the filter manager before freeing any of the minifilter + This function is called by the filter manager before freeing any of the minifilter driver's contexts of that type. - - In this routine, the driver has to perform any needed cleanup, such as freeing + + In this routine, the driver has to perform any needed cleanup, such as freeing additional memory that the minifilter driver allocated inside the context structure - + Arguments: Context - Pointer to the minifilter driver's portion of the context. ContextType - Supposed to be FLT_STREAM_CONTEXT. - + Return Value: None @@ -129,12 +129,12 @@ Return Value: { PAV_STREAM_CONTEXT streamContext = (PAV_STREAM_CONTEXT) Context; UNREFERENCED_PARAMETER( ContextType ); - + PAGED_CODE(); - - FLT_ASSERTMSG( "[AV]: Stream context is not supposed to be in the transaction context list at cleanup.!\n", + + FLT_ASSERTMSG( "[AV]: Stream context is not supposed to be in the transaction context list at cleanup.!\n", NULL == streamContext->TxContext ); - + AvFreeKevent( streamContext->ScanSynchronizationEvent ); } @@ -147,19 +147,19 @@ AvTransactionContextCleanup ( Routine Description: - This function is called by the filter manager before freeing any of the minifilter + This function is called by the filter manager before freeing any of the minifilter driver's contexts of that type. - - In this routine, the driver has to perform any needed cleanup, such as freeing + + In this routine, the driver has to perform any needed cleanup, such as freeing additional memory that the minifilter driver allocated inside the context structure - + We delete the stream context list in transaction context here. - + Arguments: Context - Pointer to the minifilter driver's portion of the context. ContextType - Supposed to be FLT_TRANSACTION_CONTEXT. - + Return Value: None @@ -167,14 +167,14 @@ Return Value: --*/ { PAV_TRANSACTION_CONTEXT transactionContext = (PAV_TRANSACTION_CONTEXT) Context; - + UNREFERENCED_PARAMETER( ContextType ); - + PAGED_CODE(); AV_DBG_PRINT( AVDBG_TRACE_DEBUG, ("[Av]: AvTransactionContextCleanup context cleanup entered.\n") ); - + ExDeleteResourceLite( transactionContext->Resource ); AvFreeResource( transactionContext->Resource ); transactionContext->Resource = NULL; @@ -191,17 +191,17 @@ AvSectionContextCleanup( Routine Description: - This function is called by the filter manager before freeing any of the minifilter + This function is called by the filter manager before freeing any of the minifilter driver's contexts of that type. - - In this routine, the driver has to perform any needed cleanup, such as freeing + + In this routine, the driver has to perform any needed cleanup, such as freeing additional memory that the minifilter driver allocated inside the context structure - + Arguments: Context - Pointer to the minifilter driver's portion of the context. ContextType - Supposed to be FLT_SECTION_CONTEXT (win8 or later). - + Return Value: None @@ -210,14 +210,14 @@ Return Value: { PAGED_CODE(); - UNREFERENCED_PARAMETER( Context ); + UNREFERENCED_PARAMETER( Context ); UNREFERENCED_PARAMETER( ContextType ); - - FLT_ASSERTMSG( "[AV] AvSectionContextCleanup: Section handle should be NULL at cleanup.\n", + + FLT_ASSERTMSG( "[AV] AvSectionContextCleanup: Section handle should be NULL at cleanup.\n", ((PAV_SECTION_CONTEXT) Context)->SectionHandle == NULL ); - FLT_ASSERTMSG( "[AV] AvSectionContextCleanup: Section object should be NULL at cleanup.\n", + FLT_ASSERTMSG( "[AV] AvSectionContextCleanup: Section object should be NULL at cleanup.\n", ((PAV_SECTION_CONTEXT) Context)->SectionObject == NULL ); - + } VOID @@ -229,19 +229,19 @@ AvInstanceContextCleanup( Routine Description: - This function is called by the filter manager before freeing any of the minifilter + This function is called by the filter manager before freeing any of the minifilter driver's contexts of that type. - - In this routine, the driver has to perform any needed cleanup, such as freeing + + In this routine, the driver has to perform any needed cleanup, such as freeing additional memory that the minifilter driver allocated inside the context structure. - + We delete the cache table if the file system supports one. - + Arguments: Context - Pointer to the minifilter driver's portion of the context. ContextType - Supposed to be FLT_INSTANCE_CONTEXT (win8 or later). - + Return Value: None @@ -253,15 +253,15 @@ Return Value: UNREFERENCED_PARAMETER( Context ); UNREFERENCED_PARAMETER( ContextType ); - + PAGED_CODE(); - + AV_DBG_PRINT( AVDBG_TRACE_ROUTINES, ( "[Av]: AvInstanceContextCleanup context cleanup entered\n") ); - + if (FS_SUPPORTS_FILE_STATE_CACHE( instanceContext->VolumeFSType )) { - - FLT_ASSERTMSG( "[AV] AvInstanceContextCleanup: The generic table should be empty at cleanup.\n", + + FLT_ASSERTMSG( "[AV] AvInstanceContextCleanup: The generic table should be empty at cleanup.\n", RtlIsGenericTableEmpty( &instanceContext->FileStateCacheTable ) ); ExDeleteResourceLite( &instanceContext->Resource ); } @@ -290,9 +290,9 @@ Return Value: { NTSTATUS status; PAV_STREAMHANDLE_CONTEXT streamHandleContext; - + PAGED_CODE(); - + // // Allocate a streamhandle context // @@ -314,7 +314,7 @@ Return Value: // // Initialize the newly created context // - + RtlZeroMemory(streamHandleContext, AV_STREAMHANDLE_CONTEXT_SIZE); *StreamHandleContext = streamHandleContext; @@ -345,20 +345,20 @@ Return Value: NTSTATUS status; PKEVENT event = NULL; PAV_STREAM_CONTEXT streamContext; - + PAGED_CODE(); - + // // Allocate the kernel event object // - + event = AvAllocateKevent(); if (NULL == event) { - + return STATUS_INSUFFICIENT_RESOURCES; } - + // // Allocate a stream context // @@ -381,10 +381,10 @@ Return Value: // // Initialize the newly created context // - + RtlZeroMemory(streamContext, AV_STREAM_CONTEXT_SIZE); streamContext->ScanSynchronizationEvent = event; - KeInitializeEvent( streamContext->ScanSynchronizationEvent, SynchronizationEvent, TRUE ); + KeInitializeEvent( streamContext->ScanSynchronizationEvent, SynchronizationEvent, TRUE ); SET_FILE_MODIFIED( streamContext ); SET_FILE_TX_MODIFIED( streamContext ); *StreamContext = streamContext; @@ -402,61 +402,61 @@ AvFindOrCreateTransactionContext( Routine Description This routine finds the transaction context, if not found, it will - try to create a new one. The caller is responsible for calling + try to create a new one. The caller is responsible for calling FltReleaseContext to decrement its reference count. - + Arguments FltObjects - Contains parameters required to enlist in a transaction. - + TransactionContext - Returns the transaction context Return value - Returns STATUS_SUCCESS if we were able to successfully find/create + Returns STATUS_SUCCESS if we were able to successfully find/create a transaction context. Returns an appropriate error code on a failure. - + --*/ { NTSTATUS status; PAV_TRANSACTION_CONTEXT transactionContext = NULL; PAV_TRANSACTION_CONTEXT oldTransactionContext = NULL; PERESOURCE pResource = NULL; - + PAGED_CODE(); - + AV_DBG_PRINT( AVDBG_TRACE_DEBUG, ("[Av]: AvFindOrCreateTransactionContext entered. \n") ); - + status = FltGetTransactionContext( FltObjects->Instance, FltObjects->Transaction, &transactionContext ); - + if (NT_SUCCESS( status )) { - + *TransactionContext = transactionContext; return STATUS_SUCCESS; } - + if (status != STATUS_NOT_FOUND) { - + AV_DBG_PRINT( AVDBG_TRACE_ERROR, ("[AV]: Failed to get transaction context with status 0x%x \n", status) ); return status; } - + // // Allocate the resource // - + pResource = AvAllocateResource(); - + if ( NULL == pResource ) { - + return STATUS_INSUFFICIENT_RESOURCES; } - + // // Allocate a transaction context. // @@ -475,30 +475,30 @@ Return value AvFreeResource( pResource ); return status; } - + FLT_ASSERTMSG( "[AV]: Transaction object pointer is not supposed to be NULL !\n", FltObjects->Transaction != NULL); - + // // Initialization of transaction context. - // The reason we allocate eResource seperately is because + // The reason we allocate eResource seperately is because // eResource has to be allocated in the non-paged pool. // - + RtlZeroMemory(transactionContext, AV_TRANSACTION_CONTEXT_SIZE); transactionContext->Resource = pResource; ObReferenceObject( FltObjects->Transaction ); transactionContext->Transaction = FltObjects->Transaction; InitializeListHead( &transactionContext->ScListHead ); ExInitializeResourceLite( transactionContext->Resource ); - + status = FltSetTransactionContext( FltObjects->Instance, FltObjects->Transaction, FLT_SET_CONTEXT_KEEP_IF_EXISTS, transactionContext, &oldTransactionContext ); - + if (NT_SUCCESS( status )) { - + *TransactionContext = transactionContext; return STATUS_SUCCESS; } @@ -513,7 +513,7 @@ Return value return status; } - + if (NULL == oldTransactionContext) { AV_DBG_PRINT( AVDBG_TRACE_ERROR, @@ -543,9 +543,9 @@ Routine Description: Arguments: Instance - Opaque instance pointer for the caller. This parameter is required and cannot be NULL. - + FileObject - File object pointer for the file. This parameter is required and cannot be NULL. - + SectionContext - Returns the section context Return Value: @@ -557,9 +557,9 @@ Return Value: NTSTATUS status; LONGLONG fileSize; PAV_SECTION_CONTEXT sectionContext = NULL; - + PAGED_CODE(); - + status = FltAllocateContext( Globals.Filter, FLT_SECTION_CONTEXT, AV_SECTION_CONTEXT_SIZE, @@ -574,11 +574,11 @@ Return Value: } RtlZeroMemory(sectionContext, AV_SECTION_CONTEXT_SIZE); - + status = AvGetFileSize( Instance, - FileObject, + FileObject, &fileSize ); - + if (!NT_SUCCESS( status )) { AV_DBG_PRINT( AVDBG_TRACE_ERROR, @@ -590,9 +590,9 @@ Return Value: sectionContext->FileSize = fileSize; } - + *SectionContext = sectionContext; - + return STATUS_SUCCESS; } @@ -611,7 +611,7 @@ Routine Description: Arguments: InstanceArray - This function will allocate the memory of the arrary containing the instances. - + NumberInstances - The number of instances in InstanceArray. Return Value: @@ -625,8 +625,8 @@ Return Value: ULONG i = 0; ULONG instCnt = 0; ULONG newCount = 0; - - + + // // Get a count of how many instances there are // @@ -668,9 +668,9 @@ Return Value: instCnt += 2; - instArray = ExAllocatePoolWithTag( PagedPool, - (instCnt * sizeof(PFLT_INSTANCE)), - AV_INSTANCES_ARRAY_TAG ); + instArray = ExAllocatePoolZero( PagedPool, + (instCnt * sizeof(PFLT_INSTANCE)), + AV_INSTANCES_ARRAY_TAG ); if (instArray == NULL) { @@ -718,11 +718,11 @@ Return Value: *InstanceArray = instArray; *NumberInstances = instCnt; - + Cleanup: - + if ( !NT_SUCCESS(status) ) { - + if (instArray) { // @@ -739,8 +739,8 @@ Cleanup: instArray = NULL; } } - - + + return status; } @@ -759,7 +759,7 @@ Routine Description: Arguments: InstanceArray - The instance arrary to be freed. - + NumberInstances - The number of instances in InstanceArray. Return Value: @@ -769,7 +769,7 @@ Return Value: --*/ { ULONG i = 0; - + // // Release all the objects in the array // @@ -794,13 +794,13 @@ AvAllocateScanContext( Routine Description: The routine allocates the scan context - + Arguments: Instance - Opaque instance pointer for the caller. This parameter is required and cannot be NULL. - + FileObject - File object pointer for the file. This parameter is required and cannot be NULL. - + ScanContext - The output scan context. Return Value: @@ -818,12 +818,12 @@ Return Value: ASSERT(Instance != NULL); ASSERT(FileObject != NULL); - scanCtx = ExAllocatePoolWithTag( NonPagedPoolNx, - sizeof(AV_SCAN_CONTEXT), - AV_SCAN_CTX_TAG ); - + scanCtx = ExAllocatePoolZero( NonPagedPoolNx, + sizeof(AV_SCAN_CONTEXT), + AV_SCAN_CTX_TAG ); + if (NULL == scanCtx) { - + return STATUS_INSUFFICIENT_RESOURCES; } scanCtx->RefCount = 1; @@ -846,7 +846,7 @@ Return Value: // ObReferenceObject( FileObject ); scanCtx->FileObject = FileObject; - + *ScanContext = scanCtx; return STATUS_SUCCESS; } @@ -860,7 +860,7 @@ AvReferenceScanContext( Routine Description: The routine increments the reference count of scan context to prevent it from deletion. - + Arguments: ScanContext - The scan context to be added reference. @@ -873,18 +873,18 @@ Return Value: --*/ { PAGED_CODE(); - + if (ScanContext == NULL) { - + return STATUS_INVALID_PARAMETER; } ASSERT(ScanContext->RefCount != 0); ASSERT(ScanContext->FilterInstance != NULL); ASSERT(ScanContext->FileObject != NULL); - + InterlockedIncrement(&ScanContext->RefCount); - + return STATUS_SUCCESS; } @@ -898,7 +898,7 @@ Routine Description: The routine decrements the reference count of scan context. Release it if reference count goes to zero. - + Arguments: ScanContext - The scan context to be released. @@ -913,15 +913,15 @@ Return Value: ULONG newRefCount = 0; PAGED_CODE(); - + if (ScanContext == NULL) { - + return STATUS_INVALID_PARAMETER; } ASSERT(ScanContext->FilterInstance != NULL); ASSERT(ScanContext->FileObject != NULL); - + // // Assume the usage of AvReferenceScanContext and AvReleaseScanContext are not raced, // This simple version would suffice. @@ -935,7 +935,7 @@ Return Value: // FltObjectDereference( ScanContext->FilterInstance ); ObDereferenceObject( ScanContext->FileObject ); - ExFreePoolWithTag( ScanContext, AV_SCAN_CTX_TAG ); + ExFreePoolWithTag( ScanContext, AV_SCAN_CTX_TAG ); } return STATUS_SUCCESS; } diff --git a/filesys/miniFilter/avscan/filter/utility.c b/filesys/miniFilter/avscan/filter/utility.c index e2c4a892..2fcf27c9 100644 --- a/filesys/miniFilter/avscan/filter/utility.c +++ b/filesys/miniFilter/avscan/filter/utility.c @@ -67,13 +67,13 @@ Return Value: // if (lhs->FileId.FileId64.Value < rhs->FileId.FileId64.Value) { - + return GenericLessThan; } else if (lhs->FileId.FileId64.Value > rhs->FileId.FileId64.Value) { - + return GenericGreaterThan; - + } else if (lhs->FileId.FileId64.UpperZeroes < rhs->FileId.FileId64.UpperZeroes) { return GenericLessThan; @@ -114,7 +114,7 @@ Return Value: UNREFERENCED_PARAMETER (Table); - return ExAllocatePoolWithTag(PagedPool, ByteSize, AV_TABLE_ENTRY_TAG); + return ExAllocatePoolZero( PagedPool, ByteSize, AV_TABLE_ENTRY_TAG ); } VOID @@ -167,7 +167,7 @@ Routine Description: Arguments: Instance - Opaque filter pointer for the caller. This parameter is required and cannot be NULL. - + FileObject - File object pointer for the file. This parameter is required and cannot be NULL. pFileId - Pointer to file id. This is the output @@ -242,7 +242,7 @@ Routine Description: Arguments: Instance - Opaque filter pointer for the caller. This parameter is required and cannot be NULL. - + FileObject - File object pointer for the file. This parameter is required and cannot be NULL. Size - Pointer to a LONGLONG indicating the file size. This is the output. @@ -290,7 +290,7 @@ Routine Description: Arguments: Instance - Opaque filter pointer for the caller. This parameter is required and cannot be NULL. - + FileObject - File object pointer for the file. This parameter is required and cannot be NULL. Encrypted - Pointer to a boolean indicating if this file is encrypted or not. This is the output. diff --git a/filesys/miniFilter/avscan/filter/utility.h b/filesys/miniFilter/avscan/filter/utility.h index 97447665..0f137f23 100644 --- a/filesys/miniFilter/avscan/filter/utility.h +++ b/filesys/miniFilter/avscan/filter/utility.h @@ -10,8 +10,8 @@ Abstract: Header file which contains the structures, type definitions, constants, global variables and function prototypes that are - only visible within the kernel. The functions include - generic table routines. + only visible within the kernel. The functions include + generic table routines. Environment: @@ -59,7 +59,7 @@ typedef union _AV_FILE_REFERENCE { // typedef struct _AV_GENERIC_TABLE_ENTRY { - + AV_FILE_REFERENCE FileId; ULONG InfectedState; @@ -69,7 +69,7 @@ typedef struct _AV_GENERIC_TABLE_ENTRY { LONGLONG VolumeRevision; LONGLONG CacheRevision; LONGLONG FileRevision; - + } AV_GENERIC_TABLE_ENTRY, *PAV_GENERIC_TABLE_ENTRY; #define AV_GENERIC_TABLE_ENTRY_SIZE sizeof( AV_GENERIC_TABLE_ENTRY ) @@ -93,9 +93,9 @@ AvAllocateGenericTableEntry ( _In_ PRTL_GENERIC_TABLE Table, _In_ CLONG ByteSize ); - + _IRQL_requires_same_ -_Function_class_(RTL_GENERIC_FREE_ROUTINE) +_Function_class_(RTL_GENERIC_FREE_ROUTINE) VOID NTAPI AvFreeGenericTableEntry ( @@ -112,7 +112,7 @@ RTL_GENERIC_FREE_ROUTINE AvFreeGenericTableEntry; // // NTFS supports a file state cache. Since CSVFS is built on top of -// NTFS, it can also support the cache. +// NTFS, it can also support the cache. // #define FS_SUPPORTS_FILE_STATE_CACHE(VolumeFilesystemType) \ ( ((VolumeFilesystemType) == FLT_FSTYPE_NTFS) || \ @@ -130,10 +130,10 @@ AvAllocateResource ( // eResource by its rule has to be in the non-paged pool // NonPagedPoolNx: non-executable non-paged pool // - - return ExAllocatePoolWithTag( NonPagedPoolNx, - sizeof( ERESOURCE ), - AV_RESOURCE_TAG ); + + return ExAllocatePoolZero( NonPagedPoolNx, + sizeof( ERESOURCE ), + AV_RESOURCE_TAG ); } FORCEINLINE @@ -156,10 +156,10 @@ AvAllocateKevent ( // // KEVENT has to be in the non-paged pool // - - return ExAllocatePoolWithTag( NonPagedPoolNx, - sizeof( KEVENT ), - AV_KEVENT_TAG ); + + return ExAllocatePoolZero( NonPagedPoolNx, + sizeof( KEVENT ), + AV_KEVENT_TAG ); } FORCEINLINE @@ -186,7 +186,7 @@ AvGetFileSize ( _In_ PFILE_OBJECT FileObject, _Out_ PLONGLONG Size ); - + NTSTATUS AvGetFileEncrypted ( _In_ PFLT_INSTANCE Instance, @@ -199,7 +199,7 @@ AvExceptionFilter ( _In_ PEXCEPTION_POINTERS ExceptionPointer, _In_ BOOLEAN AccessingUserBuffer ); - + FORCEINLINE VOID _Acquires_lock_(_Global_critical_region_) diff --git a/filesys/miniFilter/cancelSafe/cancelSafe.c b/filesys/miniFilter/cancelSafe/cancelSafe.c index d2f4b83d..4c9e7633 100644 --- a/filesys/miniFilter/cancelSafe/cancelSafe.c +++ b/filesys/miniFilter/cancelSafe/cancelSafe.c @@ -121,7 +121,7 @@ typedef struct _CSQ_GLOBAL_DATA { PWSTR PathBuffer; LONGLONG TimeDelay; - + } CSQ_GLOBAL_DATA; @@ -362,7 +362,7 @@ Return Value: // // Default to NonPagedPoolNx for non paged pool allocations where supported. // - + ExInitializeDriverRuntime( DrvRtPoolNxOptIn ); // @@ -380,8 +380,8 @@ Return Value: // // Initialize the configuration to default values // - - Globals.DebugLevel = CSQ_TRACE_ERROR; + + Globals.DebugLevel = CSQ_TRACE_ERROR; Globals.TimeDelay = CSQ_DEFAULT_TIME_DELAY; @@ -397,7 +397,7 @@ Return Value: Status = SetConfiguration( RegistryPath ); if (!NT_SUCCESS( Status )) { - + goto DriverEntryCleanup; } @@ -449,10 +449,10 @@ Return Value: DriverEntryCleanup: if (!NT_SUCCESS( Status )) { - + FreeGlobals(); } - + return Status; } @@ -460,7 +460,7 @@ DriverEntryCleanup: NTSTATUS SetConfiguration ( _In_ PUNICODE_STRING RegistryPath - ) + ) /*++ Routine Description: @@ -510,31 +510,31 @@ Return Value: } CloseHandle = TRUE; - + // // Query the debug level // RtlInitUnicodeString( &ValueName, CSQ_KEY_NAME_DEBUG_LEVEL ); - + Status = ZwQueryValueKey( DriverRegKey, &ValueName, KeyValuePartialInformation, Value, ValueLength, &ResultLength ); - + if (NT_SUCCESS( Status )) { Globals.DebugLevel = *(PULONG)(Value->Data); } - + // // Query the queue time delay // - + RtlInitUnicodeString( &ValueName, CSQ_KEY_NAME_DELAY ); Status = ZwQueryValueKey( DriverRegKey, @@ -551,11 +551,11 @@ Return Value: Status = STATUS_INVALID_PARAMETER; goto SetConfigurationCleanup; } - + Globals.TimeDelay = (LONGLONG)(*(PULONG)(Value->Data)); - + } - + // // Query the mapping path // @@ -594,17 +594,17 @@ Return Value: // Allocate enough space for an extra character in case a trailing '\' // is missing and needs to be added. // - + Length = Value->DataLength + sizeof(WCHAR), - Globals.PathBuffer = ExAllocatePoolWithTag( NonPagedPool, Length, CSQ_STRING_TAG ); - + Globals.PathBuffer = ExAllocatePoolZero( NonPagedPool, Length, CSQ_STRING_TAG ); + if (Globals.PathBuffer == NULL) { Status = STATUS_INSUFFICIENT_RESOURCES; - goto SetConfigurationCleanup; + goto SetConfigurationCleanup; } - + RtlCopyMemory( Globals.PathBuffer, Value->Data, Value->DataLength ); Globals.PathBuffer[Length / sizeof(WCHAR) - 1] = L'\0'; @@ -612,9 +612,9 @@ Return Value: // // Add a trailing '\' if one is missing. // - + if (Globals.PathBuffer[Length/sizeof(WCHAR) - 3] != L'\\') { - + Globals.PathBuffer[Length/sizeof(WCHAR) - 2] = L'\\'; } @@ -627,9 +627,9 @@ Return Value: // Ignore errors when looking for values in the registry. // Default values will be used. // - + Status = STATUS_SUCCESS; - + SetConfigurationCleanup: if (CloseHandle) { @@ -667,7 +667,7 @@ Return Value: ExDeleteNPagedLookasideList( &Globals.QueueContextLookaside ); if (Globals.PathBuffer != NULL) { - + ExFreePoolWithTag( Globals.PathBuffer, CSQ_STRING_TAG ); Globals.PathBuffer = NULL; } @@ -709,7 +709,7 @@ Return Value: FltUnregisterFilter( Globals.FilterHandle ); FreeGlobals(); - + return STATUS_SUCCESS; } @@ -1512,11 +1512,11 @@ Return Value: if (!RtlPrefixUnicodeString( &Globals.MappingPath, &NameInfo->ParentDir, TRUE )) { - goto PreReadCleanup; + goto PreReadCleanup; } // - // Since Fast I/O operations cannot be queued, we could return + // Since Fast I/O operations cannot be queued, we could return // FLT_PREOP_SUCCESS_NO_CALLBACK at this point. In this sample, // we disallow Fast I/O for this magic file in order to force an IRP // to be sent to us again. The purpose of doing that is to demonstrate @@ -1581,7 +1581,7 @@ Return Value: // In general, we can create a worker thread here as long as we can // correctly handle the insert/remove race conditions b/w multi threads. // In this sample, the worker thread creation is done in CsqInsertIo. - // This is a simpler solution because CsqInsertIo is atomic with + // This is a simpler solution because CsqInsertIo is atomic with // respect to other CsqXxxIo callback routines. // @@ -1707,32 +1707,32 @@ Return Value: // // Check to see if we need to lock the user buffer. // - // If the FLTFL_CALLBACK_DATA_SYSTEM_BUFFER flag is set we don't + // If the FLTFL_CALLBACK_DATA_SYSTEM_BUFFER flag is set we don't // have to lock the buffer because its already a system buffer. // - // If the MdlAddress is NULL and the buffer is a user buffer, + // If the MdlAddress is NULL and the buffer is a user buffer, // then we have to construct one in order to look at the buffer. // // If the length of the buffer is zero there is nothing to read, // so we cannot construct a MDL. // - if (!FlagOn(Data->Flags, FLTFL_CALLBACK_DATA_SYSTEM_BUFFER) && + if (!FlagOn(Data->Flags, FLTFL_CALLBACK_DATA_SYSTEM_BUFFER) && Data->Iopb->Parameters.Read.MdlAddress == NULL && Data->Iopb->Parameters.Read.Length > 0) { Status = FltLockUserBuffer( Data ); if (!NT_SUCCESS( Status )) { - + // // If could not lock the user buffer we cannot - // allow the IO to go below us. Because we are + // allow the IO to go below us. Because we are // in a different VA space and the buffer is a - // user mode address, we will either fault or + // user mode address, we will either fault or // corrpt data // - + DebugTrace( CSQ_TRACE_PRE_READ | CSQ_TRACE_ERROR, ("[Csq]: Failed to lock user buffer (Status = 0x%x)\n", Status) ); @@ -1779,10 +1779,10 @@ Return Value: // if (InterlockedDecrement( &InstCtx->WorkerThreadFlag ) == 0) { - + break; } - + } } @@ -1902,17 +1902,17 @@ Return Value: // // Check to see if we need to lock the user buffer. // - // If the FLTFL_CALLBACK_DATA_SYSTEM_BUFFER flag is set we don't + // If the FLTFL_CALLBACK_DATA_SYSTEM_BUFFER flag is set we don't // have to lock the buffer because its already a system buffer. // - // If the MdlAddress is NULL and the buffer is a user buffer, + // If the MdlAddress is NULL and the buffer is a user buffer, // then we have to construct one in order to look at the buffer. // // If the length of the buffer is zero there is nothing to read, // so we cannot construct a MDL. // - if (!FlagOn(Data->Flags, FLTFL_CALLBACK_DATA_SYSTEM_BUFFER) && + if (!FlagOn(Data->Flags, FLTFL_CALLBACK_DATA_SYSTEM_BUFFER) && Data->Iopb->Parameters.Read.MdlAddress == NULL && Data->Iopb->Parameters.Read.Length > 0) { @@ -1922,12 +1922,12 @@ Return Value: // // If could not lock the user buffer we cannot - // allow the IO to go below us. Because we are + // allow the IO to go below us. Because we are // in a different VA space and the buffer is a - // user mode address, we will either fault or + // user mode address, we will either fault or // corrpt data // - + callbackStatus = FLT_PREOP_COMPLETE; Data->IoStatus.Status = Status; } diff --git a/filesys/miniFilter/change/utility.h b/filesys/miniFilter/change/utility.h index bb7743ad..1b6cd4d4 100644 --- a/filesys/miniFilter/change/utility.h +++ b/filesys/miniFilter/change/utility.h @@ -10,8 +10,8 @@ Abstract: Header file which contains the structures, type definitions, constants, global variables and function prototypes that are - only visible within the kernel. The functions include - generic table routines. + only visible within the kernel. The functions include + generic table routines. Environment: @@ -32,10 +32,10 @@ CgAllocateMutex ( // // Fast mutex by its rule has to be in the non-paged pool // - - return ExAllocatePoolWithTag( NonPagedPoolNx, - sizeof( FAST_MUTEX ), - CG_MUTEX_TAG ); + + return ExAllocatePoolZero( NonPagedPoolNx, + sizeof( FAST_MUTEX ), + CG_MUTEX_TAG ); } FORCEINLINE diff --git a/filesys/miniFilter/ctx/CtxProc.h b/filesys/miniFilter/ctx/CtxProc.h index 06873a23..6887c0c5 100644 --- a/filesys/miniFilter/ctx/CtxProc.h +++ b/filesys/miniFilter/ctx/CtxProc.h @@ -134,7 +134,7 @@ CtxUpdateNameInStreamHandleContext ( // _At_(String->Length, _Out_range_(==, 0)) -_At_(String->MaximumLength, _In_) +_At_(String->MaximumLength, _In_) _At_(String->Buffer, _Pre_maybenull_ _Post_notnull_ _Post_writable_byte_size_(String->MaximumLength)) NTSTATUS CtxAllocateUnicodeString ( @@ -161,9 +161,9 @@ CtxAllocateResource ( ) { - return ExAllocatePoolWithTag( NonPagedPool, - sizeof( ERESOURCE ), - CTX_RESOURCE_TAG ); + return ExAllocatePoolZero( NonPagedPool, + sizeof( ERESOURCE ), + CTX_RESOURCE_TAG ); } FORCEINLINE @@ -215,7 +215,7 @@ _Releases_lock_(_Global_critical_region_) _Requires_lock_held_(_Global_critical_region_) _IRQL_requires_max_(APC_LEVEL) CtxReleaseResource ( - _Inout_ _Requires_lock_held_(*_Curr_) _Releases_lock_(*_Curr_) + _Inout_ _Requires_lock_held_(*_Curr_) _Releases_lock_(*_Curr_) PERESOURCE Resource ) { diff --git a/filesys/miniFilter/ctx/support.c b/filesys/miniFilter/ctx/support.c index 7e3db95f..eb5a72e9 100644 --- a/filesys/miniFilter/ctx/support.c +++ b/filesys/miniFilter/ctx/support.c @@ -37,7 +37,7 @@ Environment: // _At_(String->Length, _Out_range_(==, 0)) -_At_(String->MaximumLength, _In_) +_At_(String->MaximumLength, _In_) _At_(String->Buffer, _Pre_maybenull_ _Post_notnull_ _Post_writable_byte_size_(String->MaximumLength)) NTSTATUS CtxAllocateUnicodeString ( @@ -63,9 +63,9 @@ Return Value: { PAGED_CODE(); - String->Buffer = ExAllocatePoolWithTag( PagedPool, - String->MaximumLength, - CTX_STRING_TAG ); + String->Buffer = ExAllocatePoolZero( PagedPool, + String->MaximumLength, + CTX_STRING_TAG ); if (String->Buffer == NULL) { diff --git a/filesys/miniFilter/delete/delete.c b/filesys/miniFilter/delete/delete.c index 74fc435b..0c682f1c 100644 --- a/filesys/miniFilter/delete/delete.c +++ b/filesys/miniFilter/delete/delete.c @@ -957,9 +957,9 @@ Return Value: InitializeListHead( &transactionContext->DeleteNotifyList ); - transactionContext->Resource = ExAllocatePoolWithTag( NonPagedPool, - sizeof(ERESOURCE), - DF_ERESOURCE_POOL_TAG ); + transactionContext->Resource = ExAllocatePoolZero( NonPagedPool, + sizeof(ERESOURCE), + DF_ERESOURCE_POOL_TAG ); if (NULL == transactionContext->Resource) { FltReleaseContext( transactionContext ); @@ -1688,9 +1688,9 @@ Return Value: String->Length = 0; - String->Buffer = ExAllocatePoolWithTag( DF_CONTEXT_POOL_TYPE, - String->MaximumLength, - DF_STRING_POOL_TAG ); + String->Buffer = ExAllocatePoolZero( DF_CONTEXT_POOL_TYPE, + String->MaximumLength, + DF_STRING_POOL_TAG ); if (NULL == String->Buffer) { @@ -2311,17 +2311,15 @@ Return Value: ASSERT( NULL != StreamContext ); - deleteNotify = ExAllocatePoolWithTag( DF_CONTEXT_POOL_TYPE, - sizeof(DF_DELETE_NOTIFY), - DF_DELETE_NOTIFY_POOL_TAG ); + deleteNotify = ExAllocatePoolZero( DF_CONTEXT_POOL_TYPE, + sizeof(DF_DELETE_NOTIFY), + DF_DELETE_NOTIFY_POOL_TAG ); if (NULL == deleteNotify) { return STATUS_INSUFFICIENT_RESOURCES; } - RtlZeroMemory( deleteNotify, sizeof(DF_DELETE_NOTIFY) ); - FltReferenceContext( StreamContext ); deleteNotify->StreamContext = StreamContext; deleteNotify->FileDelete = FileDelete; diff --git a/filesys/miniFilter/scanner/filter/scanner.c b/filesys/miniFilter/scanner/filter/scanner.c index cd72d71b..318941d1 100644 --- a/filesys/miniFilter/scanner/filter/scanner.c +++ b/filesys/miniFilter/scanner/filter/scanner.c @@ -54,7 +54,7 @@ UNICODE_STRING ScannedExtensionDefault = RTL_CONSTANT_STRING( L"doc" ); // Function prototypes // -NTSTATUS +NTSTATUS ScannerInitializeScannedExtensions( _In_ PUNICODE_STRING RegistryPath ); @@ -105,12 +105,12 @@ ScannerpCheckExtension ( #ifdef ALLOC_PRAGMA #pragma alloc_text(INIT, DriverEntry) - #pragma alloc_text(INIT, ScannerInitializeScannedExtensions) + #pragma alloc_text(INIT, ScannerInitializeScannedExtensions) #pragma alloc_text(PAGE, ScannerInstanceSetup) #pragma alloc_text(PAGE, ScannerPreCreate) #pragma alloc_text(PAGE, ScannerPortConnect) #pragma alloc_text(PAGE, ScannerPortDisconnect) - #pragma alloc_text(PAGE, ScannerFreeExtensions) + #pragma alloc_text(PAGE, ScannerFreeExtensions) #pragma alloc_text(PAGE, ScannerAllocateUnicodeString) #pragma alloc_text(PAGE, ScannerFreeUnicodeString) #endif @@ -221,7 +221,7 @@ Return Value: // // Default to NonPagedPoolNx for non paged pool allocations where supported. // - + ExInitializeDriverRuntime( DrvRtPoolNxOptIn ); // @@ -247,10 +247,10 @@ Return Value: if (!NT_SUCCESS( status )) { status = STATUS_SUCCESS; - + ScannedExtensions = &ScannedExtensionDefault; - ScannedExtensionCount = 1; - } + ScannedExtensionCount = 1; + } // // Create a communication port. @@ -307,12 +307,12 @@ Return Value: ScannerFreeExtensions(); FltUnregisterFilter( ScannerData.Filter ); - + return status; } -NTSTATUS +NTSTATUS ScannerInitializeScannedExtensions( _In_ PUNICODE_STRING RegistryPath ) @@ -322,7 +322,7 @@ Routine Descrition: This routine sets the the extensions for files to be scanned based on the registry. - + Arguments: RegistryPath - The path key passed to the driver during DriverEntry. @@ -345,7 +345,7 @@ Return Value: SIZE_T length; ULONG count; PUNICODE_STRING ext; - + PAGED_CODE(); ScannedExtensions = NULL; @@ -375,7 +375,7 @@ Return Value: // // Query the length of the reg value // - + RtlInitUnicodeString( &valueName, L"Extensions" ); status = ZwQueryValueKey( driverRegKey, @@ -395,9 +395,9 @@ Return Value: // Extract the path. // - valueBuffer = ExAllocatePoolWithTag( NonPagedPool, - valueLength, - SCANNER_REG_TAG ); + valueBuffer = ExAllocatePoolZero( NonPagedPool, + valueLength, + SCANNER_REG_TAG ); if (valueBuffer == NULL) { @@ -424,38 +424,38 @@ Return Value: // // Count how many strings are in the multi string // - + while (*ch != '\0') { ch = ch + wcslen( ch ) + 1; count++; } - ScannedExtensions = ExAllocatePoolWithTag( PagedPool, - count * sizeof(UNICODE_STRING), - SCANNER_STRING_TAG ); - + ScannedExtensions = ExAllocatePoolZero( PagedPool, + count * sizeof(UNICODE_STRING), + SCANNER_STRING_TAG ); + if (ScannedExtensions == NULL) { goto ScannerInitializeScannedExtensionsCleanup; } ch = (PWCHAR)((PKEY_VALUE_PARTIAL_INFORMATION)valueBuffer->Data); ext = ScannedExtensions; - + while (ScannedExtensionCount < count) { length = wcslen( ch ) * sizeof(WCHAR); ext->MaximumLength = (USHORT) length; - + status = ScannerAllocateUnicodeString( ext ); - + if (!NT_SUCCESS( status )) { goto ScannerInitializeScannedExtensionsCleanup; } ext->Length = (USHORT)length; - + RtlCopyMemory( ext->Buffer, ch, length ); ch = ch + length/sizeof(WCHAR) + 1; @@ -463,7 +463,7 @@ Return Value: ScannedExtensionCount++; ext++; - + } ScannerInitializeScannedExtensionsCleanup: @@ -489,7 +489,7 @@ ScannerInitializeScannedExtensionsCleanup: ScannerFreeExtensions(); } - + return status; } @@ -524,16 +524,16 @@ Return Value: if (ScannedExtensions != &ScannedExtensionDefault) { - ScannerFreeUnicodeString( ScannedExtensions + ScannedExtensionCount ); + ScannerFreeUnicodeString( ScannedExtensions + ScannedExtensionCount ); } } - + if (ScannedExtensions != &ScannedExtensionDefault && ScannedExtensions != NULL) { ExFreePoolWithTag( ScannedExtensions, SCANNER_STRING_TAG ); } - ScannedExtensions = NULL; + ScannedExtensions = NULL; } @@ -550,22 +550,22 @@ Routine Description: Arguments: - String - supplies the size of the string to be allocated in the MaximumLength field + String - supplies the size of the string to be allocated in the MaximumLength field return the unicode string Return Value: STATUS_SUCCESS - success STATUS_INSUFFICIENT_RESOURCES - failure - + --*/ { PAGED_CODE(); - String->Buffer = ExAllocatePoolWithTag( NonPagedPool, - String->MaximumLength, - SCANNER_STRING_TAG ); + String->Buffer = ExAllocatePoolZero( NonPagedPool, + String->MaximumLength, + SCANNER_STRING_TAG ); if (String->Buffer == NULL) { @@ -590,11 +590,11 @@ Routine Description: Arguments: - String - supplies the string to be freed + String - supplies the string to be freed Return Value: - None + None --*/ { @@ -662,7 +662,7 @@ Return Value // Set the user process and port. In a production filter it may // be necessary to synchronize access to such fields with port // lifetime. For instance, while filter manager will synchronize - // FltCloseClientPort with FltSendMessage's reading of the port + // FltCloseClientPort with FltSendMessage's reading of the port // handle, synchronizing access to the UserProcess would be up to // the filter. // @@ -936,7 +936,7 @@ Return Value // for (count = 0; count < ScannedExtensionCount; count++) { - + if (RtlCompareUnicodeString( Extension, ScannedExtensions + count, TRUE ) == 0) { // @@ -1092,7 +1092,7 @@ Return Value: // // Normally we would check the results of FltSetStreamHandleContext - // for a variety of error cases. However, The only error status + // for a variety of error cases. However, The only error status // that could be returned, in this case, would tell us that // contexts are not supported. Even if we got this error, // we just want to release the context now and that will free @@ -1283,9 +1283,9 @@ Return Value: // This is just a sample! // - notification = ExAllocatePoolWithTag( NonPagedPool, - sizeof( SCANNER_NOTIFICATION ), - 'nacS' ); + notification = ExAllocatePoolZero( NonPagedPool, + sizeof( SCANNER_NOTIFICATION ), + 'nacS' ); if (notification == NULL) { Data->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES; @@ -1398,7 +1398,7 @@ ScannerPreFileSystemControl ( Routine Description: - Pre FS Control callback. + Pre FS Control callback. Arguments: @@ -1460,13 +1460,13 @@ Return Value: // // Scanner cannot access the data in this offload write request. - // In a production-level filter, we would actually let user mode + // In a production-level filter, we would actually let user mode // scan the file after offload write completes (on cleanup etc). // Since this is just a sample, block offload write with // STATUS_ACCESS_DENIED, although this is not an acceptable // production-level behavior. // - + DbgPrint( "!!! scanner.sys -- blocking the offload write !!!\n" ); Data->IoStatus.Status = STATUS_ACCESS_DENIED; @@ -1474,7 +1474,7 @@ Return Value: returnStatus = FLT_PREOP_COMPLETE; } - + } finally { if (context) { @@ -1482,7 +1482,7 @@ Return Value: FltReleaseContext( context ); } } - + return returnStatus; } @@ -1600,9 +1600,9 @@ Return Value: leave; } - notification = ExAllocatePoolWithTag( NonPagedPool, - sizeof( SCANNER_NOTIFICATION ), - 'nacS' ); + notification = ExAllocatePoolZero( NonPagedPool, + sizeof( SCANNER_NOTIFICATION ), + 'nacS' ); if(NULL == notification) { diff --git a/filesys/miniFilter/simrep/simrep.c b/filesys/miniFilter/simrep/simrep.c index e2068604..4d377ecb 100644 --- a/filesys/miniFilter/simrep/simrep.c +++ b/filesys/miniFilter/simrep/simrep.c @@ -784,9 +784,9 @@ Return Value: // Extract the old mapping string. // - mappingValue = ExAllocatePoolWithTag( PagedPool, - mappingValueLength, - SIMREP_REG_TAG ); + mappingValue = ExAllocatePoolZero( PagedPool, + mappingValueLength, + SIMREP_REG_TAG ); if (mappingValue == NULL) { @@ -855,9 +855,9 @@ Return Value: ExFreePoolWithTag( mappingValue, SIMREP_REG_TAG ); - mappingValue = ExAllocatePoolWithTag( PagedPool, - mappingValueLength, - SIMREP_REG_TAG ); + mappingValue = ExAllocatePoolZero( PagedPool, + mappingValueLength, + SIMREP_REG_TAG ); if (mappingValue == NULL) { @@ -1745,6 +1745,8 @@ Return Value: fileInfoClass = Cbd->Iopb->Parameters.SetFileInformation.FileInformationClass; +#pragma warning( push ) +#pragma warning( disable:4061 ) switch (fileInfoClass) { case FileRenameInformation: @@ -1835,6 +1837,7 @@ Return Value: NT_ASSERTMSG("SimRep passing through unknown information class\n", FALSE); goto SimRepPreSetInformationCleanup; } +#pragma warning( pop ) // // When this filter is configured to remap renames and hardlinks we need @@ -1940,7 +1943,7 @@ Return Value: bufferLength = FIELD_OFFSET( FILE_RENAME_INFORMATION, FileName ) + newFileName.Length; - buffer = ExAllocatePoolWithTag( PagedPool, bufferLength, SIMREP_STRING_TAG ); + buffer = ExAllocatePoolZero( PagedPool, bufferLength, SIMREP_STRING_TAG ); if (buffer == NULL) { @@ -1960,7 +1963,7 @@ Return Value: bufferLength = FIELD_OFFSET( FILE_LINK_INFORMATION, FileName ) + newFileName.Length; - buffer = ExAllocatePoolWithTag( PagedPool, bufferLength, SIMREP_STRING_TAG ); + buffer = ExAllocatePoolZero( PagedPool, bufferLength, SIMREP_STRING_TAG ); if (buffer == NULL) { @@ -2061,9 +2064,9 @@ Return Value: PAGED_CODE(); - String->Buffer = ExAllocatePoolWithTag( NonPagedPool, - String->MaximumLength, - SIMREP_STRING_TAG ); + String->Buffer = ExAllocatePoolZero( NonPagedPool, + String->MaximumLength, + SIMREP_STRING_TAG ); if (String->Buffer == NULL) { @@ -2161,6 +2164,7 @@ Return Value: // if (FileNameLength <= fileName->MaximumLength) { + RtlZeroMemory(fileName->Buffer, fileName->MaximumLength); goto CopyAndReturn; } @@ -2169,9 +2173,9 @@ Return Value: // newMaxLength = FileNameLength; - buffer = ExAllocatePoolWithTag( PagedPool, - newMaxLength, - SIMREP_STRING_TAG ); + buffer = ExAllocatePoolZero( PagedPool, + newMaxLength, + SIMREP_STRING_TAG ); if (!buffer) { @@ -2189,7 +2193,6 @@ Return Value: CopyAndReturn: fileName->Length = FileNameLength; - RtlZeroMemory(fileName->Buffer, fileName->MaximumLength); RtlCopyMemory(fileName->Buffer, NewFileName, FileNameLength); return STATUS_SUCCESS; diff --git a/filesys/miniFilter/swapBuffers/swapBuffers.c b/filesys/miniFilter/swapBuffers/swapBuffers.c index 8773fde2..dc0d0542 100644 --- a/filesys/miniFilter/swapBuffers/swapBuffers.c +++ b/filesys/miniFilter/swapBuffers/swapBuffers.c @@ -473,9 +473,9 @@ Return Value: // #pragma prefast(suppress:__WARNING_MEMORY_LEAK, "ctx->Name.Buffer will not be leaked because it is freed in CleanupVolumeContext") - ctx->Name.Buffer = ExAllocatePoolWithTag( NonPagedPool, - size, - NAME_TAG ); + ctx->Name.Buffer = ExAllocatePoolZero( NonPagedPool, + size, + NAME_TAG ); if (ctx->Name.Buffer == NULL) { status = STATUS_INSUFFICIENT_RESOURCES; @@ -671,7 +671,7 @@ Return Value: // // Default to NonPagedPoolNx for non paged pool allocations where supported. // - + ExInitializeDriverRuntime( DrvRtPoolNxOptIn ); // @@ -865,7 +865,7 @@ Return Value: // don't swap buffers on this operation. // - newBuf = FltAllocatePoolAlignedWithTag( FltObjects->Instance, + newBuf = FltAllocatePoolAlignedWithTag( FltObjects->Instance, NonPagedPool, (SIZE_T) readLen, BUFFER_SWAP_TAG ); @@ -1076,7 +1076,7 @@ Return Value: // This should be a simple MDL. We don't expect chained MDLs // this high up the stack // - + FLT_ASSERT( ((PMDL)iopb->Parameters.Read.MdlAddress)->Next == NULL); // @@ -1427,9 +1427,9 @@ Return Value: // operation. // - newBuf = ExAllocatePoolWithTag( NonPagedPool, - iopb->Parameters.DirectoryControl.QueryDirectory.Length, - BUFFER_SWAP_TAG ); + newBuf = ExAllocatePoolZero( NonPagedPool, + iopb->Parameters.DirectoryControl.QueryDirectory.Length, + BUFFER_SWAP_TAG ); if (newBuf == NULL) { @@ -1442,15 +1442,7 @@ Return Value: } // - // Zero the new buffer so as not to potentially expose any sensitive - // data to the user. - // - - RtlZeroMemory( newBuf, iopb->Parameters.DirectoryControl.QueryDirectory.Length ); - - - // - // We need to build a MDL because Directory Control Operations are always IRP operations. + // We need to build a MDL because Directory Control Operations are always IRP operations. // @@ -1729,9 +1721,9 @@ Return Value: // NOTE: Due to a bug in FASTFAT where it is returning the wrong // length in the information field (it is sort) we are always // going to copy the original buffer length. Please note that - // this is a potential security problem because we will copy - // more than what was touched by the FS. So we have to make - // sure the buffer is clean before calling into the FS or we + // this is a potential security problem because we will copy + // more than what was touched by the FS. So we have to make + // sure the buffer is clean before calling into the FS or we // risk exposing sensitive data to the user. // @@ -1997,7 +1989,7 @@ Return Value: // don't swap buffers on this operation. // - newBuf = FltAllocatePoolAlignedWithTag( FltObjects->Instance, + newBuf = FltAllocatePoolAlignedWithTag( FltObjects->Instance, NonPagedPool, (SIZE_T) writeLen, BUFFER_SWAP_TAG ); @@ -2058,7 +2050,7 @@ Return Value: // This should be a simple MDL. We don't expect chained MDLs // this high up the stack // - + FLT_ASSERT( ((PMDL)iopb->Parameters.Write.MdlAddress)->Next == NULL); origBuf = MmGetSystemAddressForMdlSafe( iopb->Parameters.Write.MdlAddress, |
