This function is called prior to a create operation. Data - The data associated with the current operation. FltObjects - Objects related to the filter, instance, and its associated volume. CompletionContext - Optional context to be passed to post operation callbacks. */
| 122 | CompletionContext - Optional context to be passed to post operation callbacks. |
| 123 | */ |
| 124 | FLT_PREOP_CALLBACK_STATUS |
| 125 | FSBlockingFilter::HandlePreCreateOperation( |
| 126 | _Inout_ PFLT_CALLBACK_DATA Data, |
| 127 | _In_ PCFLT_RELATED_OBJECTS FltObjects, |
| 128 | _Flt_CompletionContext_Outptr_ PVOID* CompletionContext |
| 129 | ) |
| 130 | { |
| 131 | FLT_PREOP_CALLBACK_STATUS callbackStatus; |
| 132 | PFLT_FILE_NAME_INFORMATION fileNameInfo; |
| 133 | |
| 134 | PUNICODE_STRING callerProcessPath; |
| 135 | PSTACK_RETURN_INFO fileOperationStack; |
| 136 | ULONG fileOperationStackSize; |
| 137 | BOOLEAN reportOperation; |
| 138 | |
| 139 | UNREFERENCED_PARAMETER(FltObjects); |
| 140 | UNREFERENCED_PARAMETER(CompletionContext); |
| 141 | |
| 142 | reportOperation = FALSE; |
| 143 | fileOperationStackSize = MAX_STACK_RETURN_HISTORY; |
| 144 | fileNameInfo = NULL; |
| 145 | callbackStatus = FLT_PREOP_SUCCESS_NO_CALLBACK; |
| 146 | |
| 147 | // |
| 148 | // PeaceMaker is not designed to block kernel operations. |
| 149 | // |
| 150 | if (ExGetPreviousMode() == KernelMode) |
| 151 | { |
| 152 | return callbackStatus; |
| 153 | } |
| 154 | |
| 155 | if (FlagOn(Data->Iopb->Parameters.Create.Options, FILE_DELETE_ON_CLOSE)) |
| 156 | { |
| 157 | if (NT_SUCCESS(FltGetFileNameInformation(Data, FLT_FILE_NAME_NORMALIZED | FLT_FILE_NAME_QUERY_DEFAULT, &fileNameInfo))) |
| 158 | { |
| 159 | if (FSBlockingFilter::FileStringFilters->MatchesFilter(fileNameInfo->Name.Buffer, FILTER_FLAG_DELETE) != FALSE) |
| 160 | { |
| 161 | DBGPRINT("FSBlockingFilter!HandlePreCreateOperation: Detected FILE_DELETE_ON_CLOSE of %wZ. Prevented deletion!", fileNameInfo->Name); |
| 162 | |
| 163 | Data->Iopb->TargetFileObject->DeletePending = FALSE; |
| 164 | Data->IoStatus.Information = 0; |
| 165 | Data->IoStatus.Status = STATUS_ACCESS_DENIED; |
| 166 | callbackStatus = FLT_PREOP_COMPLETE; |
| 167 | reportOperation = TRUE; |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | if (Data->Iopb->Parameters.Create.SecurityContext && FlagOn(Data->Iopb->Parameters.Create.SecurityContext->DesiredAccess, FILE_EXECUTE)) |
| 173 | { |
| 174 | if (NT_SUCCESS(FltGetFileNameInformation(Data, FLT_FILE_NAME_NORMALIZED | FLT_FILE_NAME_QUERY_DEFAULT, &fileNameInfo))) |
| 175 | { |
| 176 | if (FSBlockingFilter::FileStringFilters->MatchesFilter(fileNameInfo->Name.Buffer, FILTER_FLAG_EXECUTE) != FALSE) |
| 177 | { |
| 178 | DBGPRINT("FSBlockingFilter!HandlePreCreateOperation: Detected FILE_EXECUTE desired access of %wZ. Prevented execute access!", fileNameInfo->Name); |
| 179 | Data->Iopb->TargetFileObject->DeletePending = FALSE; |
| 180 | Data->IoStatus.Information = 0; |
| 181 | Data->IoStatus.Status = STATUS_ACCESS_DENIED; |
nothing calls this directly
no test coverage detected