From ba62280d9e389d11bb35c51198ce01cd059539e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sat, 21 Sep 2013 22:59:24 +0000 Subject: [PATCH] [NTOS] - Fix Job object session ID setting and comparison; fix a list initialization. - Correct some comments. - As Alex noticed it 7 years and 2 months ago, in revision 23197, the ProcessSessionInformation case in the NtSetInformationProcess API doesn't set a new session ID for the given process anymore (checked by myself too), because it is set once and for all at process creation time and is stored inside the Process->Session structure managed by MM. Therefore fake changing it: we just return success if the user-defined value is the same as the session ID of the process, and otherwise we fail. svn path=/trunk/; revision=60298 --- reactos/ntoskrnl/mm/ARM3/procsup.c | 2 +- reactos/ntoskrnl/ps/job.c | 10 +++++---- reactos/ntoskrnl/ps/query.c | 33 ++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/reactos/ntoskrnl/mm/ARM3/procsup.c b/reactos/ntoskrnl/mm/ARM3/procsup.c index 58c8a5e64d2..b7b7344e4d2 100644 --- a/reactos/ntoskrnl/mm/ARM3/procsup.c +++ b/reactos/ntoskrnl/mm/ARM3/procsup.c @@ -1576,7 +1576,7 @@ MiReleaseProcessReferenceToSessionDataPage(IN PMM_SESSION_SPACE SessionGlobal) /* Get the session ID */ SessionId = SessionGlobal->SessionId; - DPRINT1("Last process in sessino %lu going down!!!\n", SessionId); + DPRINT1("Last process in session %lu going down!!!\n", SessionId); /* Free the session page tables */ #ifndef _M_AMD64 diff --git a/reactos/ntoskrnl/ps/job.c b/reactos/ntoskrnl/ps/job.c index 3841364fdaf..5cd3a8a32a9 100644 --- a/reactos/ntoskrnl/ps/job.c +++ b/reactos/ntoskrnl/ps/job.c @@ -169,8 +169,7 @@ NtAssignProcessToJobObject ( ExAcquireRundownProtection(&Process->RundownProtect); if(NT_SUCCESS(Status)) { - // FIXME: This is broken - if(Process->Job == NULL && PtrToUlong(Process->Session) == Job->SessionId) + if(Process->Job == NULL && PsGetProcessSessionId(Process) == Job->SessionId) { /* Just store the pointer to the job object in the process, we'll assign it later. The reason we can't do this here is that locking @@ -272,9 +271,12 @@ NtCreateJobObject ( the list before it even gets added! */ Job->JobLinks.Flink = NULL; - /* setup the job object */ + /* setup the job object - FIXME: More to do! */ + InitializeListHead(&Job->JobSetLinks); InitializeListHead(&Job->ProcessListHead); - Job->SessionId = PtrToUlong(CurrentProcess->Session); /* inherit the session id from the caller, FIXME: broken */ + + /* inherit the session id from the caller */ + Job->SessionId = PsGetProcessSessionId(CurrentProcess); Status = ExInitializeResource(&Job->JobLock); if(!NT_SUCCESS(Status)) diff --git a/reactos/ntoskrnl/ps/query.c b/reactos/ntoskrnl/ps/query.c index 3cbfa63a7e6..1e81a77ae63 100644 --- a/reactos/ntoskrnl/ps/query.c +++ b/reactos/ntoskrnl/ps/query.c @@ -1169,7 +1169,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, /* Getting VDM powers requires the SeTcbPrivilege */ if (!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode)) { - /* Bail out */ + /* We don't hold the privilege, bail out */ Status = STATUS_PRIVILEGE_NOT_HELD; DPRINT1("Need TCB privilege\n"); break; @@ -1213,7 +1213,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, /* Setting the error port requires the SeTcbPrivilege */ if (!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode)) { - /* Can't set the session ID, bail out. */ + /* We don't hold the privilege, bail out */ Status = STATUS_PRIVILEGE_NOT_HELD; break; } @@ -1332,11 +1332,13 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, /* Setting the session id requires the SeTcbPrivilege */ if (!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode)) { - /* Can't set the session ID, bail out. */ + /* We don't hold the privilege, bail out */ Status = STATUS_PRIVILEGE_NOT_HELD; break; } +#if 0 // OLD AND DEPRECATED CODE!!!! + /* FIXME - update the session id for the process token */ //Status = PsLockProcess(Process, FALSE); if (!NT_SUCCESS(Status)) break; @@ -1372,6 +1374,27 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, /* Unlock the process */ //PsUnlockProcess(Process); + +#endif + + /* + * Since we cannot change the session ID of the given + * process anymore because it is set once and for all + * at process creation time and because it is stored + * inside the Process->Session structure managed by MM, + * we fake changing it: we just return success if the + * user-defined value is the same as the session ID of + * the process, and otherwise we fail. + */ + if (SessionInfo.SessionId == PsGetProcessSessionId(Process)) + { + Status = STATUS_SUCCESS; + } + else + { + Status = STATUS_ACCESS_DENIED; + } + break; case ProcessPriorityClass: @@ -1612,6 +1635,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, /* Setting 'break on termination' requires the SeDebugPrivilege */ if (!SeSinglePrivilegeCheck(SeDebugPrivilege, PreviousMode)) { + /* We don't hold the privilege, bail out */ Status = STATUS_PRIVILEGE_NOT_HELD; break; } @@ -1837,7 +1861,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, /* Only TCB can do this */ if (!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode)) { - /* Fail */ + /* We don't hold the privilege, bail out */ DPRINT1("Need TCB to set IOPL\n"); Status = STATUS_PRIVILEGE_NOT_HELD; break; @@ -2366,6 +2390,7 @@ NtSetInformationThread(IN HANDLE ThreadHandle, /* Setting 'break on termination' requires the SeDebugPrivilege */ if (!SeSinglePrivilegeCheck(SeDebugPrivilege, PreviousMode)) { + /* We don't hold the privilege, bail out */ Status = STATUS_PRIVILEGE_NOT_HELD; break; }