[KS] KsRead/WriteFile: finish IRP initialization and properly setup I/O stack location for it (#5784)

- Initialize the rest of IRP data which is not initialized by IoBuildSynchronousFsdRequest.
- Setup an IO_STACK_LOCATION structure for the IRP before calling the driver's read/write routine.
- Do this for both KsReadFile and KsWriteFile functions in our Kernel Streaming driver (ks.sys).
This fixes several problems when calling these functions from outside, so now they are working correctly, as expected.
Discovered during my audio investigations.
CORE-19232
This commit is contained in:
Oleg Dubinskiy 2023-10-10 22:30:00 +02:00 committed by GitHub
parent 8451230753
commit a6b281c228
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -150,6 +150,7 @@ KsReadFile(
IN KPROCESSOR_MODE RequestorMode)
{
PDEVICE_OBJECT DeviceObject;
PIO_STACK_LOCATION IoStack;
PIRP Irp;
NTSTATUS Status;
BOOLEAN Result;
@ -216,6 +217,16 @@ KsReadFile(
return STATUS_INSUFFICIENT_RESOURCES;
}
/* setup the rest of irp */
Irp->RequestorMode = RequestorMode;
Irp->Overlay.AsynchronousParameters.UserApcContext = PortContext;
Irp->Tail.Overlay.OriginalFileObject = FileObject;
/* setup irp stack */
IoStack = IoGetNextIrpStackLocation(Irp);
IoStack->FileObject = FileObject;
IoStack->Parameters.Read.Key = Key;
/* send the packet */
Status = IoCallDriver(DeviceObject, Irp);
@ -250,6 +261,7 @@ KsWriteFile(
IN KPROCESSOR_MODE RequestorMode)
{
PDEVICE_OBJECT DeviceObject;
PIO_STACK_LOCATION IoStack;
PIRP Irp;
NTSTATUS Status;
BOOLEAN Result;
@ -316,6 +328,16 @@ KsWriteFile(
return STATUS_INSUFFICIENT_RESOURCES;
}
/* setup the rest of irp */
Irp->RequestorMode = RequestorMode;
Irp->Overlay.AsynchronousParameters.UserApcContext = PortContext;
Irp->Tail.Overlay.OriginalFileObject = FileObject;
/* setup irp stack */
IoStack = IoGetNextIrpStackLocation(Irp);
IoStack->FileObject = FileObject;
IoStack->Parameters.Write.Key = Key;
/* send the packet */
Status = IoCallDriver(DeviceObject, Irp);