From 1dc051294c48bb81a92d152b2e3e5ae0fac00fae Mon Sep 17 00:00:00 2001 From: Rod Widdowson Date: Sun, 25 Aug 2013 09:16:39 -0700 Subject: [PATCH] Windows: Pin the Cc FileObject during section create. This means that if we purge the data cache while the section is being created then the MJ_CLOSE will not happen until we unpin the FO. Thus we can drop any embarsssing locks prior to the close and meddling antivirus products can do odd stuff in the close path. Note that there may not be a file object, but in that case there will be no close on the purge since any CcInitialize operations will wait on us dropping the SOP lock exe - hence the SOP cannot be set up. Also note that this only applies to the data section, but we do not purge the image section. Change-Id: I63884888d98eb4eb03858ed962d74bd3b4702042 Reviewed-on: http://gerrit.openafs.org/10189 Tested-by: BuildBot Reviewed-by: Jeffrey Altman --- .../afsrdr/common/AFSRedirCommonStructs.h | 7 ++++++ .../afsrdr/kernel/fs/AFSFastIoSupport.cpp | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/WINNT/afsrdr/common/AFSRedirCommonStructs.h b/src/WINNT/afsrdr/common/AFSRedirCommonStructs.h index bddd44799..946b33017 100644 --- a/src/WINNT/afsrdr/common/AFSRedirCommonStructs.h +++ b/src/WINNT/afsrdr/common/AFSRedirCommonStructs.h @@ -391,6 +391,13 @@ typedef struct AFS_FCB LONG ExtentLength; // in KBs + // + // We pin the Cc File Object between AcquireFileForNtCreateSection + // and ReleaseFileForNtCreateSection. Protected by SOP lock + // + + PFILE_OBJECT SectionCreateFO; + } File; struct diff --git a/src/WINNT/afsrdr/kernel/fs/AFSFastIoSupport.cpp b/src/WINNT/afsrdr/kernel/fs/AFSFastIoSupport.cpp index 366a0090d..6ea12117a 100644 --- a/src/WINNT/afsrdr/kernel/fs/AFSFastIoSupport.cpp +++ b/src/WINNT/afsrdr/kernel/fs/AFSFastIoSupport.cpp @@ -271,6 +271,19 @@ AFSFastIoAcquireFile( IN struct _FILE_OBJECT *FileObject) AFSAcquireExcl( &pFcb->NPFcb->SectionObjectResource, TRUE); + if( NULL == pFcb->Specific.File.SectionCreateFO ) + { + // + // If not re-entrant then save and reference + // + pFcb->Specific.File.SectionCreateFO = + CcGetFileObjectFromSectionPtrs( &pFcb->NPFcb->SectionObjectPointers ); + if( NULL != pFcb->Specific.File.SectionCreateFO ) + { + ObReferenceObject( pFcb->Specific.File.SectionCreateFO); + } + } + return; } @@ -282,6 +295,8 @@ AFSFastIoReleaseFile( IN struct _FILE_OBJECT *FileObject) if( ExIsResourceAcquiredExclusiveLite( &pFcb->NPFcb->SectionObjectResource)) { + PFILE_OBJECT fileObject = pFcb->Specific.File.SectionCreateFO; + pFcb->Specific.File.SectionCreateFO = NULL; AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING, AFS_TRACE_LEVEL_VERBOSE, @@ -290,6 +305,15 @@ AFSFastIoReleaseFile( IN struct _FILE_OBJECT *FileObject) PsGetCurrentThread())); AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource); + + // + // Now defer the Cc file object (if there was one) now that we are lock free + // + + if( NULL != fileObject ) + { + ObDereferenceObject( fileObject ); + } } return; -- 2.39.5