[NTOSKRNL]

Add SEH to NtRequestPort. Patch by Alexander Andrejevic.
CORE-7371

svn path=/trunk/; revision=67144
This commit is contained in:
Timo Kreuzer 2015-04-10 19:53:08 +00:00
parent e8730d240c
commit 47c8ea734e

View file

@ -453,6 +453,7 @@ NtRequestPort(IN HANDLE PortHandle,
PLPCP_MESSAGE Message; PLPCP_MESSAGE Message;
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode(); KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
PETHREAD Thread = PsGetCurrentThread(); PETHREAD Thread = PsGetCurrentThread();
PORT_MESSAGE CapturedLpcRequest;
PAGED_CODE(); PAGED_CODE();
@ -462,15 +463,37 @@ NtRequestPort(IN HANDLE PortHandle,
LpcRequest, LpcRequest,
LpcpGetMessageType(LpcRequest)); LpcpGetMessageType(LpcRequest));
/* Check if the call comes from user mode */
if (PreviousMode != KernelMode)
{
_SEH2_TRY
{
/* Probe and capture the LpcRequest */
ProbeForRead(LpcRequest, sizeof(PORT_MESSAGE), sizeof(ULONG));
ProbeForRead(LpcRequest, LpcRequest->u1.s1.TotalLength, sizeof(ULONG));
CapturedLpcRequest = *LpcRequest;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
_SEH2_YIELD(return _SEH2_GetExceptionCode());
}
_SEH2_END;
}
else
{
/* Access the LpcRequest directly */
CapturedLpcRequest = *LpcRequest;
}
/* Get the message type */ /* Get the message type */
MessageType = LpcRequest->u2.s2.Type | LPC_DATAGRAM; MessageType = CapturedLpcRequest.u2.s2.Type | LPC_DATAGRAM;
/* Can't have data information on this type of call */ /* Can't have data information on this type of call */
if (LpcRequest->u2.s2.DataInfoOffset) return STATUS_INVALID_PARAMETER; if (CapturedLpcRequest.u2.s2.DataInfoOffset) return STATUS_INVALID_PARAMETER;
/* Validate the length */ /* Validate the length */
if (((ULONG)LpcRequest->u1.s1.DataLength + sizeof(PORT_MESSAGE)) > if (((ULONG)CapturedLpcRequest.u1.s1.DataLength + sizeof(PORT_MESSAGE)) >
(ULONG)LpcRequest->u1.s1.TotalLength) (ULONG)CapturedLpcRequest.u1.s1.TotalLength)
{ {
/* Fail */ /* Fail */
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
@ -486,8 +509,8 @@ NtRequestPort(IN HANDLE PortHandle,
if (!NT_SUCCESS(Status)) return Status; if (!NT_SUCCESS(Status)) return Status;
/* Validate the message length */ /* Validate the message length */
if (((ULONG)LpcRequest->u1.s1.TotalLength > Port->MaxMessageLength) || if (((ULONG)CapturedLpcRequest.u1.s1.TotalLength > Port->MaxMessageLength) ||
((ULONG)LpcRequest->u1.s1.TotalLength <= (ULONG)LpcRequest->u1.s1.DataLength)) ((ULONG)CapturedLpcRequest.u1.s1.TotalLength <= (ULONG)CapturedLpcRequest.u1.s1.DataLength))
{ {
/* Fail */ /* Fail */
ObDereferenceObject(Port); ObDereferenceObject(Port);
@ -729,7 +752,7 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle,
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{ {
DPRINT1("Got exception\n"); DPRINT1("Got exception\n");
return _SEH2_GetExceptionCode(); _SEH2_YIELD(return _SEH2_GetExceptionCode());
} }
_SEH2_END; _SEH2_END;
} }