Hi all,
I have a BSOD problem of KERNEL_STACK_INPAGE_ERROR, which may be trigered by the following codes:
NTSTATUS
NTAPI
HookCreateSection(OUT PHANDLE SectionHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes,
IN PLARGE_INTEGER MaximumSize,
IN ULONG SectionPageProtection,
IN ULONG AllocationAttributes,
IN HANDLE FileHandle)
{
…
ntstatus = ObReferenceObjectByHandle(FileHandle, SYNCHRONIZE|FILE_READ_DATA, 0,
KernelMode,
&pFileObject,
NULL);
if(!NT_SUCCESS(ntstatus))
{
goto HOOKEND;
}
ntStatus = ObOpenObjectByPointer(pFileObject,
0,
NULL,
SYNCHRONIZE|FILE_READ_DATA,
NULL,KernelMode,
&hFileHandle);
if(!NT_SUCCESS(ntStatus))
{
goto HOOKEND;
}
ntStatus = ZwQueryInformationFile(hFileHandle,
&IoStatus,
&StandardFileInfo,
sizeof(FILE_STANDARD_INFORMATION),
FileStandardInformation);
if(ntStatus != STATUS_SUCCESS)
{
ZwClose(hFileHandle);
goto HOOKEND;
}
nFileLen=StandardFileInfo.EndOfFile.LowPart;
if ((nFileLen==0)||(nFileLen==0xFFFFFFFF))
{
ZwClose(hFileHandle);
goto HOOKEND;
}
if(nFileLen <= ReadFileLen)
{
pbData=(PCHAR)ExAllocatePool(NonPagedPool, nFileLen+1);
ntemLen=nFileLen+1;
}
else
{
pbData=(PCHAR)ExAllocatePool(NonPagedPool, ReadFileLen+1);
ntemLen=ReadFileLen+1;
}
if (pbData==NULL)
{
//zz KdPrint((“ProcessCheckSum: ExAllocatePool failed!\n”));
ZwClose(hFileHandle);
goto HOOKEND;
}
RtlZeroMemory(pbData,ntemLen);
if(nFileLen <= ReadFileLen)
{
ntStatus=ZwReadFile(hFileHandle,
NULL,
NULL,
NULL,
&IoStatus,
(PVOID)pbData,
nFileLen,
NULL,
NULL);
if(ntStatus != STATUS_SUCCESS)
{
//zz KdPrint((“ProcessCheckSum: ZwReadFile %s Failed\n”, pFile));
ZwClose(hFileHandle);
ExFreePool(pbData);
return FALSE;
}
// calculate the crc valure
CheckSum(CheckSumImage,pbData,nFileLen);
}
else
{
for(i = 0;i {
ntStatus=ZwReadFile(hFileHandle,
NULL,
NULL,
NULL,
&IoStatus,
(PVOID)pbData,
ReadFileLen,
NULL,
NULL);
if(ntStatus != STATUS_SUCCESS)
{
//zz KdPrint((“ProcessCheckSum: ZwReadFile %s Failed\n”, pFile));
ZwClose(hFileHandle);
ExFreePool(pbData);
return FALSE;
}
CheckSum(CheckSumImage,pbData,ReadFileLen);
RtlZeroMemory(pbData,ReadFileLen);
}
ntStatus=ZwReadFile(hFileHandle,
NULL,
NULL,
NULL,
&IoStatus,
(PVOID)pbData,
nFileLen-ReadFileLen*(nFileLen/ReadFileLen),
NULL,
NULL);
if(ntStatus != STATUS_SUCCESS)
{
//zz KdPrint((“ProcessCheckSum: ZwReadFile %s Failed\n”, pFile));
ZwClose(hFileHandle);
ExFreePool(pbData);
goto HOOKEND;
}
CheckSum(CheckSumImage,pbData,nFileLen-ReadFileLen*(nFileLen/ReadFileLen));
}
ZwClose(hFileHandle);
ExFreePool(pbData);
…
}
Can anyone tell me where i am wrong, thank you!