I have a very simple completion routine for the first occurance of (IRP_MJ_READ or IRP_MJ_WRITE, whichever occurs first) that does nothing more than read from the MBR of a raw disk. The method itself performs exactly as I require it to… however as the method ends and returns, it causes a BSOD indicating that there was a buffer overflow possibly with ‘MBRBuffer’. I don’t understand why and more importantly how to resolve it so that it stops crashing.
Thanks for any help in advance.
NTSTATUS
MyIoCompletion(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
)
{
PDEVICE_EXTENSION deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
PIRP irp;
KEVENT Event;
IO_STATUS_BLOCK ioStatus;
NTSTATUS status;
IO_STATUS_BLOCK file_status;
OBJECT_ATTRIBUTES obj_attrib;
BYTE MBRBuffer[513];
LARGE_INTEGER offset;
UNREFERENCED_PARAMETER(Context);
if (Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}
// Open the raw disk which we are filtering
InitializeObjectAttributes(&obj_attrib, &deviceExtension->PhysicalDeviceName,
OBJ_CASE_INSENSITIVE, NULL, NULL);
status = ZwCreateFile(&deviceExtension->MBR,
FILE_READ_DATA | FILE_WRITE_DATA,
&obj_attrib,
&file_status,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE,
NULL,
0);
// Read the MBR from raw disk which we are filtering
if (deviceExtension->MBR != NULL){
offset.QuadPart = 0;
status = ZwReadFile(deviceExtension->MBR, NULL, NULL, NULL,
&ioStatus, MBRBuffer, (sizeof(MBRBuffer)-1),
&offset, NULL);
}
// Close the raw disk which we are filtering
status = ZwClose(deviceExtension->MBR);
deviceExtension->MBR = NULL;
return STATUS_SUCCESS;
} // DARKIoCompletion