diff --git a/ntoskrnl/config/cmwraprs.c b/ntoskrnl/config/cmwraprs.c index b23092e0cd9..f75a52fbcb2 100644 --- a/ntoskrnl/config/cmwraprs.c +++ b/ntoskrnl/config/cmwraprs.c @@ -129,21 +129,32 @@ CmpFileWrite(IN PHHIVE RegistryHive, BOOLEAN NTAPI -CmpFileSetSize(IN PHHIVE RegistryHive, - IN ULONG FileType, - IN ULONG FileSize, - IN ULONG OldFileSize) +CmpFileSetSize( + _In_ PHHIVE RegistryHive, + _In_ ULONG FileType, + _In_ ULONG FileSize, + _In_ ULONG OldFileSize) { PCMHIVE CmHive = (PCMHIVE)RegistryHive; HANDLE HiveHandle = CmHive->FileHandles[FileType]; FILE_END_OF_FILE_INFORMATION EndOfFileInfo; FILE_ALLOCATION_INFORMATION FileAllocationInfo; IO_STATUS_BLOCK IoStatusBlock; + BOOLEAN HardErrors; NTSTATUS Status; /* Just return success if no file is associated with this hive */ if (HiveHandle == NULL) + { + DPRINT1("No hive handle associated with the given hive\n"); return TRUE; + } + + /* + * Disable hard errors so that we don't deadlock + * when touching with the hive files. + */ + HardErrors = IoSetThreadHardErrorMode(FALSE); EndOfFileInfo.EndOfFile.QuadPart = FileSize; Status = ZwSetInformationFile(HiveHandle, @@ -151,7 +162,12 @@ CmpFileSetSize(IN PHHIVE RegistryHive, &EndOfFileInfo, sizeof(FILE_END_OF_FILE_INFORMATION), FileEndOfFileInformation); - if (!NT_SUCCESS(Status)) return FALSE; + if (!NT_SUCCESS(Status)) + { + DPRINT1("ZwSetInformationFile failed to set new size of end of file (Status 0x%lx)\n", Status); + IoSetThreadHardErrorMode(HardErrors); + return FALSE; + } FileAllocationInfo.AllocationSize.QuadPart = FileSize; Status = ZwSetInformationFile(HiveHandle, @@ -159,8 +175,15 @@ CmpFileSetSize(IN PHHIVE RegistryHive, &FileAllocationInfo, sizeof(FILE_ALLOCATION_INFORMATION), FileAllocationInformation); - if (!NT_SUCCESS(Status)) return FALSE; + if (!NT_SUCCESS(Status)) + { + DPRINT1("ZwSetInformationFile failed to set new of allocation file (Status 0x%lx)\n", Status); + IoSetThreadHardErrorMode(HardErrors); + return FALSE; + } + /* Reset the hard errors back */ + IoSetThreadHardErrorMode(HardErrors); return TRUE; } diff --git a/ntoskrnl/include/internal/cm.h b/ntoskrnl/include/internal/cm.h index e8fee77faf4..5c2f352f753 100644 --- a/ntoskrnl/include/internal/cm.h +++ b/ntoskrnl/include/internal/cm.h @@ -1236,10 +1236,10 @@ CmpFileWrite( BOOLEAN NTAPI CmpFileSetSize( - IN PHHIVE RegistryHive, - IN ULONG FileType, - IN ULONG FileSize, - IN ULONG OldFileSize + _In_ PHHIVE RegistryHive, + _In_ ULONG FileType, + _In_ ULONG FileSize, + _In_ ULONG OldFileSize ); BOOLEAN