From 51e2ff7462880adcbb395bdf8c808f83b93cb2ac Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Wed, 19 Jan 2005 21:47:51 +0000 Subject: [PATCH] 1. fixed the ProcessAccessToken information class to properly check buffers 2. implemented the ProcessExceptionPort information class svn path=/trunk/; revision=13141 --- reactos/ntoskrnl/ps/process.c | 99 +++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 5 deletions(-) diff --git a/reactos/ntoskrnl/ps/process.c b/reactos/ntoskrnl/ps/process.c index 6c6dba38d4b..9b02b7c7093 100644 --- a/reactos/ntoskrnl/ps/process.c +++ b/reactos/ntoskrnl/ps/process.c @@ -1458,7 +1458,6 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, { PEPROCESS Process; NTSTATUS Status; - PHANDLE ProcessAccessTokenP; KPROCESSOR_MODE PreviousMode; PreviousMode = ExGetPreviousMode(); @@ -1480,14 +1479,104 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, case ProcessBasePriority: case ProcessRaisePriority: case ProcessDebugPort: - case ProcessExceptionPort: Status = STATUS_NOT_IMPLEMENTED; break; + case ProcessExceptionPort: + { + if(ProcessInformationLength != sizeof(PROCESS_ACCESS_TOKEN)) + { + Status = STATUS_INFO_LENGTH_MISMATCH; + } + else + { + HANDLE PortHandle; + + /* make a safe copy of the buffer on the stack */ + _SEH_TRY + { + PortHandle = *(PHANDLE)ProcessInformation; + Status = STATUS_SUCCESS; + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + + if(NT_SUCCESS(Status)) + { + PEPORT ExceptionPort; + + /* in case we had success reading from the buffer, verify the provided + * LPC port handle + */ + Status = ObReferenceObjectByHandle(PortHandle, + 0, + LpcPortObjectType, + PreviousMode, + (PVOID)&ExceptionPort, + NULL); + if(NT_SUCCESS(Status)) + { + /* lock the process to be thread-safe! */ + + Status = PsLockProcess(Process, FALSE); + if(NT_SUCCESS(Status)) + { + /* + * according to "NT Native API" documentation, setting the exception + * port is only permitted once! + */ + if(Process->ExceptionPort == NULL) + { + Process->ExceptionPort = ExceptionPort; + Status = STATUS_SUCCESS; + } + else + { + Status = STATUS_PORT_ALREADY_SET; + } + PsUnlockProcess(Process); + } + + ObDereferenceObject(ExceptionPort); + } + } + } + break; + } + case ProcessAccessToken: - ProcessAccessTokenP = (PHANDLE)ProcessInformation; - Status = PspAssignPrimaryToken(Process, *ProcessAccessTokenP); + { + if(ProcessInformationLength != sizeof(PROCESS_ACCESS_TOKEN)) + { + Status = STATUS_INFO_LENGTH_MISMATCH; + } + else + { + HANDLE TokenHandle; + + /* make a safe copy of the buffer on the stack */ + _SEH_TRY + { + TokenHandle = ((PPROCESS_ACCESS_TOKEN)ProcessInformation)->Token; + Status = STATUS_SUCCESS; + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + + if(NT_SUCCESS(Status)) + { + /* in case we had success reading from the buffer, perform the actual task */ + Status = PspAssignPrimaryToken(Process, TokenHandle); + } + } break; + } case ProcessDefaultHardErrorMode: { @@ -1572,7 +1661,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, /* FIXME - update the session id for the process token */ - Status = PsLockProcess(Process, TRUE); + Status = PsLockProcess(Process, FALSE); if(NT_SUCCESS(Status)) { Process->SessionId = SessionInfo.SessionId;