[NTOS:PS] Enable alignment probing for thread/process information classes 2874/head
authorGeorge Bișoc <george.bisoc@reactos.org>
Mon, 3 May 2021 13:46:35 +0000 (15:46 +0200)
committerGeorge Bișoc <george.bisoc@reactos.org>
Sun, 6 Jun 2021 15:14:22 +0000 (17:14 +0200)
In addition to that, here are some stuff done in this commit whilst testing:

- ICIF_QUERY_SIZE_VARIABLE and friends were badly misused, they should be used only when an information class whose information length size is dyanmic and not fixed. By removing such flags from erroneous classes, this fixes the STATUS_INFO_LENGTH_MISMATCH testcases.

- Use CHAR instead of UCHAR for classes that do not need alignment probing, as every other class in the table do, for the sake of consistency.

- ProcessEnableAlignmentFaultFixup uses BOOLEAN as type size, not CHAR. This fixes a testcase failure on ROS.

- Check for information length size before proceeding further on querying the process' cookie information.

- ProcessHandleTracing wants an alignment of a ULONG, not CHAR.

- Move PROCESS_LDT_INFORMATION and PROCESS_LDT_SIZE outside of NTOS_MODE_USER macro case. This fixes a compilation issue when enabling the alignment probing. My mistake of having them inside NTOS_MODE_USER case, sorry.

- On functions like NtQueryInformationThread and the Process equivalent, complete probing is not done at the beginning of the function, complete probing including if the buffer is writable alongside with datatype misalignment check that is. Instead such check is done on each information class case basis. With that said, we have to explicitly tell DefaultQueryInfoBufferCheck if we want a complete probing or not initially.

ntoskrnl/ex/event.c
ntoskrnl/ex/mutant.c
ntoskrnl/ex/sem.c
ntoskrnl/ex/timer.c
ntoskrnl/include/internal/probe.h
ntoskrnl/include/internal/ps_i.h
ntoskrnl/include/ntoskrnl.h
ntoskrnl/io/iomgr/iocomp.c
ntoskrnl/ps/query.c
ntoskrnl/se/token.c
sdk/include/ndk/pstypes.h

index 0f7d6d3..e30420f 100644 (file)
@@ -333,7 +333,8 @@ NtQueryEvent(IN HANDLE EventHandle,
                                          EventInformationLength,
                                          ReturnLength,
                                          NULL,
-                                         PreviousMode);
+                                         PreviousMode,
+                                         TRUE);
     if(!NT_SUCCESS(Status))
     {
         /* Invalid buffers */
index ff5772b..bab471c 100644 (file)
@@ -243,7 +243,8 @@ NtQueryMutant(IN HANDLE MutantHandle,
                                          MutantInformationLength,
                                          ResultLength,
                                          NULL,
-                                         PreviousMode);
+                                         PreviousMode,
+                                         TRUE);
     if(!NT_SUCCESS(Status))
     {
         DPRINT("NtQueryMutant() failed, Status: 0x%x\n", Status);
index 8a1810d..29c6228 100644 (file)
@@ -239,7 +239,8 @@ NtQuerySemaphore(IN HANDLE SemaphoreHandle,
                                          SemaphoreInformationLength,
                                          ReturnLength,
                                          NULL,
-                                         PreviousMode);
+                                         PreviousMode,
+                                         TRUE);
     if (!NT_SUCCESS(Status))
     {
         /* Invalid buffers */
index 129881d..0ce7af0 100644 (file)
@@ -536,7 +536,8 @@ NtQueryTimer(IN HANDLE TimerHandle,
                                          TimerInformationLength,
                                          ReturnLength,
                                          NULL,
-                                         PreviousMode);
+                                         PreviousMode,
+                                         TRUE);
     if (!NT_SUCCESS(Status)) return Status;
 
     /* Get the Timer Object */
index f02af65..b819718 100644 (file)
@@ -63,7 +63,8 @@ DefaultQueryInfoBufferCheck(ULONG Class,
                             ULONG BufferLength,
                             PULONG ReturnLength,
                             PULONG_PTR ReturnLengthPtr,
-                            KPROCESSOR_MODE PreviousMode)
+                            KPROCESSOR_MODE PreviousMode,
+                            BOOLEAN CompleteProbing)
 {
     NTSTATUS Status = STATUS_SUCCESS;
 
@@ -90,9 +91,18 @@ DefaultQueryInfoBufferCheck(ULONG Class,
                 {
                     if (Buffer != NULL)
                     {
-                        ProbeForWrite(Buffer,
-                                      BufferLength,
-                                      ClassList[Class].AlignmentQUERY);
+                        if (!CompleteProbing)
+                        {
+                            ProbeForRead(Buffer,
+                                         BufferLength,
+                                         ClassList[Class].AlignmentQUERY);
+                        }
+                        else
+                        {
+                            ProbeForWrite(Buffer,
+                                          BufferLength,
+                                          ClassList[Class].AlignmentQUERY);
+                        }
                     }
 
                     if (ReturnLength != NULL)
index 0f0a58e..85de26d 100644 (file)
@@ -19,7 +19,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         PROCESS_BASIC_INFORMATION,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ProcessQuotaLimits */
@@ -27,7 +27,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         QUOTA_LIMITS,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ProcessIoCounters */
@@ -35,7 +35,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         IO_COUNTERS,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ProcessVmCounters */
@@ -51,7 +51,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         KERNEL_USER_TIMES,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ProcessBasePriority */
@@ -59,7 +59,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         KPRIORITY,
         ULONG,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ProcessRaisePriority */
@@ -67,7 +67,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ProcessDebugPort */
@@ -75,7 +75,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         HANDLE,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ProcessExceptionPort */
@@ -83,7 +83,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         HANDLE,
         ULONG,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ProcessAccessToken */
@@ -91,7 +91,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         PROCESS_ACCESS_TOKEN,
         ULONG,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ProcessLdtInformation */
@@ -99,7 +99,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         PROCESS_LDT_INFORMATION,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ProcessLdtSize */
@@ -107,7 +107,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         PROCESS_LDT_SIZE,
         ULONG,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ProcessDefaultHardErrorMode */
@@ -115,7 +115,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ProcessIoPortHandlers */
@@ -123,7 +123,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         UCHAR,
         ULONG,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ProcessPooledUsageAndLimits */
@@ -131,7 +131,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         POOLED_USAGE_AND_LIMITS,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ProcessWorkingSetWatch */
@@ -139,7 +139,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         PROCESS_WS_WATCH_INFORMATION,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET | ICIF_SET_SIZE_VARIABLE
     ),
 
     /* ProcessUserModeIOPL */
@@ -147,17 +147,17 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         UCHAR,
         ULONG,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ProcessEnableAlignmentFaultFixup */
     IQS
     (
-        CHAR,
+        BOOLEAN,
         CHAR,
         BOOLEAN,
-        UCHAR,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        CHAR,
+        ICIF_SET
     ),
 
     /* ProcessPriorityClass */
@@ -167,7 +167,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
         ULONG,
         PROCESS_PRIORITY_CLASS,
         CHAR,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ProcessWx86Information */
@@ -175,7 +175,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ProcessHandleCount */
@@ -183,7 +183,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ProcessAffinityMask */
@@ -191,7 +191,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         KAFFINITY,
         ULONG,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ProcessPriorityBoost */
@@ -199,7 +199,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ProcessDeviceMap */
@@ -209,7 +209,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
         ULONG,
         RTL_FIELD_TYPE(PROCESS_DEVICEMAP_INFORMATION, Set),
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ProcessSessionInformation */
@@ -217,7 +217,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         PROCESS_SESSION_INFORMATION,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ProcessForegroundInformation */
@@ -226,8 +226,8 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
         CHAR,
         CHAR,
         BOOLEAN,
-        UCHAR,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        CHAR,
+        ICIF_SET
     ),
 
     /* ProcessWow64Information */
@@ -235,7 +235,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ProcessImageFileName */
@@ -251,7 +251,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ProcessBreakOnTermination */
@@ -259,7 +259,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ProcessDebugObjectHandle */
@@ -267,7 +267,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         HANDLE,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ProcessDebugFlags */
@@ -275,17 +275,17 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ProcessHandleTracing */
     IQS
     (
         PROCESS_HANDLE_TRACING_QUERY,
-        CHAR,
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ULONG,
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ProcessIoPriority */
@@ -301,7 +301,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ProcessTlsInformation */
@@ -317,7 +317,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ProcessImageInformation */
@@ -325,7 +325,7 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
     (
         SECTION_IMAGE_INFORMATION,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ProcessCycleTime */
@@ -411,7 +411,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         THREAD_BASIC_INFORMATION,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ThreadTimes */
@@ -419,7 +419,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         KERNEL_USER_TIMES,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ThreadPriority */
@@ -427,7 +427,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         KPRIORITY,
         ULONG,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ThreadBasePriority */
@@ -435,7 +435,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         LONG,
         ULONG,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ThreadAffinityMask */
@@ -443,7 +443,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         KAFFINITY,
         ULONG,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ThreadImpersonationToken */
@@ -451,7 +451,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         HANDLE,
         ULONG,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ThreadDescriptorTableEntry is only implemented in x86 as well as the descriptor entry */
@@ -461,7 +461,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
         (
             DESCRIPTOR_TABLE_ENTRY,
             ULONG,
-            ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+            ICIF_QUERY
         ),
     #else
         IQS_NONE,
@@ -474,7 +474,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
         CHAR,
         BOOLEAN,
         UCHAR,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ThreadEventPair_Reusable */
@@ -492,7 +492,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
         ULONG,
         ULONG_PTR,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ThreadZeroTlsCell */
@@ -500,7 +500,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         ULONG_PTR,
         ULONG,
-        ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ThreadPerformanceCount */
@@ -508,7 +508,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         LARGE_INTEGER,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ThreadAmILastThread */
@@ -516,7 +516,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ThreadIdealProcessor */
@@ -524,7 +524,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         ULONG_PTR,
         ULONG,
-        ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ThreadPriorityBoost */
@@ -534,7 +534,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
         ULONG,
         ULONG_PTR,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ThreadSetTlsArrayAddress */
@@ -550,7 +550,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ThreadHideFromDebugger */
@@ -566,7 +566,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ThreadSwitchLegacyState */
@@ -574,7 +574,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_SET | ICIF_SET_SIZE_VARIABLE
+        ICIF_SET
     ),
 
     /* ThreadIsTerminated */
@@ -582,7 +582,7 @@ static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
     (
         ULONG,
         ULONG,
-        ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
+        ICIF_QUERY
     ),
 
     /* ThreadLastSystemCall */
index a6ac78b..643562e 100644 (file)
@@ -124,6 +124,9 @@ C_ASSERT(MAX_WIN32_PATH == MAX_PATH);
 #include "internal/probe.h"
 #include "resource.h"
 
+/* Internal Ps alignment probing header */
+#include "internal/ps_i.h"
+
 #ifdef _MSC_VER
 # pragma section("INITDATA", read,write,discard)
 #endif
index df883d4..41457a6 100644 (file)
@@ -399,7 +399,8 @@ NtQueryIoCompletion(IN  HANDLE IoCompletionHandle,
                                          IoCompletionInformationLength,
                                          ResultLength,
                                          NULL,
-                                         PreviousMode);
+                                         PreviousMode,
+                                         TRUE);
     if (!NT_SUCCESS(Status)) return Status;
 
     /* Get the Object */
index 895c2db..5c28b03 100644 (file)
@@ -86,26 +86,20 @@ NtQueryInformationProcess(
     ULONG Flags;
     PAGED_CODE();
 
-    /* Check for user-mode caller */
-    if (PreviousMode != KernelMode)
+    /* Verify Information Class validity */
+    Status = DefaultQueryInfoBufferCheck(ProcessInformationClass,
+                                         PsProcessInfoClass,
+                                         RTL_NUMBER_OF(PsProcessInfoClass),
+                                         ProcessInformation,
+                                         ProcessInformationLength,
+                                         ReturnLength,
+                                         NULL,
+                                         PreviousMode,
+                                         FALSE);
+    if (!NT_SUCCESS(Status))
     {
-        /* Prepare to probe parameters */
-        _SEH2_TRY
-        {
-            /* Probe the buffer */
-            ProbeForRead(ProcessInformation,
-                         ProcessInformationLength,
-                         sizeof(ULONG));
-
-            /* Probe the return length if required */
-            if (ReturnLength) ProbeForWriteUlong(ReturnLength);
-        }
-        _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
-        {
-            /* Return the exception code */
-            _SEH2_YIELD(return _SEH2_GetExceptionCode());
-        }
-        _SEH2_END;
+        DPRINT1("NtQueryInformationProcess(): Information verification class failed! (Status -> 0x%lx, ProcessInformationClass -> %lx)\n", Status, ProcessInformationClass);
+        return Status;
     }
 
     if (((ProcessInformationClass == ProcessCookie) ||
@@ -794,6 +788,13 @@ NtQueryInformationProcess(
         /* Per-process security cookie */
         case ProcessCookie:
 
+            if (ProcessInformationLength != sizeof(ULONG))
+            {
+                /* Length size wrong, bail out */
+                Status = STATUS_INFO_LENGTH_MISMATCH;
+                break;
+            }
+
             /* Get the current process and cookie */
             Process = PsGetCurrentProcess();
             Cookie = Process->Cookie;
@@ -1131,15 +1132,17 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
     PAGED_CODE();
 
     /* Verify Information Class validity */
-#if 0
     Status = DefaultSetInfoBufferCheck(ProcessInformationClass,
                                        PsProcessInfoClass,
                                        RTL_NUMBER_OF(PsProcessInfoClass),
                                        ProcessInformation,
                                        ProcessInformationLength,
                                        PreviousMode);
-    if (!NT_SUCCESS(Status)) return Status;
-#endif
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("NtSetInformationProcess(): Information verification class failed! (Status -> 0x%lx, ProcessInformationClass -> %lx)\n", Status, ProcessInformationClass);
+        return Status;
+    }
 
     /* Check what class this is */
     Access = PROCESS_SET_INFORMATION;
@@ -1846,7 +1849,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
         case ProcessEnableAlignmentFaultFixup:
 
             /* Check buffer length */
-            if (ProcessInformationLength != sizeof(ULONG))
+            if (ProcessInformationLength != sizeof(BOOLEAN))
             {
                 Status = STATUS_INFO_LENGTH_MISMATCH;
                 break;
@@ -2036,15 +2039,17 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
     PAGED_CODE();
 
     /* Verify Information Class validity */
-#if 0
     Status = DefaultSetInfoBufferCheck(ThreadInformationClass,
                                        PsThreadInfoClass,
                                        RTL_NUMBER_OF(PsThreadInfoClass),
                                        ThreadInformation,
                                        ThreadInformationLength,
                                        PreviousMode);
-    if (!NT_SUCCESS(Status)) return Status;
-#endif
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("NtSetInformationThread(): Information verification class failed! (Status -> 0x%lx, ThreadInformationClass -> %lx)\n", Status, ThreadInformationClass);
+        return Status;
+    }
 
     /* Check what kind of information class this is */
     switch (ThreadInformationClass)
@@ -2634,26 +2639,20 @@ NtQueryInformationThread(IN HANDLE ThreadHandle,
     ULONG ThreadTerminated;
     PAGED_CODE();
 
-    /* Check if we were called from user mode */
-    if (PreviousMode != KernelMode)
+    /* Verify Information Class validity */
+    Status = DefaultQueryInfoBufferCheck(ThreadInformationClass,
+                                         PsThreadInfoClass,
+                                         RTL_NUMBER_OF(PsThreadInfoClass),
+                                         ThreadInformation,
+                                         ThreadInformationLength,
+                                         ReturnLength,
+                                         NULL,
+                                         PreviousMode,
+                                         FALSE);
+    if (!NT_SUCCESS(Status))
     {
-        /* Enter SEH */
-        _SEH2_TRY
-        {
-            /* Probe the buffer */
-            ProbeForWrite(ThreadInformation,
-                          ThreadInformationLength,
-                          sizeof(ULONG));
-
-            /* Probe the return length if required */
-            if (ReturnLength) ProbeForWriteUlong(ReturnLength);
-        }
-        _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
-        {
-            /* Return the exception code */
-            _SEH2_YIELD(return _SEH2_GetExceptionCode());
-        }
-        _SEH2_END;
+        DPRINT1("NtQueryInformationThread(): Information verification class failed! (Status -> 0x%lx , ThreadInformationClass -> %lx)\n", Status, ThreadInformationClass);
+        return Status;
     }
 
     /* Check what class this is */
index eb67cda..256e4b3 100644 (file)
@@ -2400,7 +2400,8 @@ NtQueryInformationToken(
                                          TokenInformationLength,
                                          ReturnLength,
                                          NULL,
-                                         PreviousMode);
+                                         PreviousMode,
+                                         TRUE);
     if (!NT_SUCCESS(Status))
     {
         DPRINT("NtQueryInformationToken() failed, Status: 0x%x\n", Status);
index 53e7651..3a47b04 100644 (file)
@@ -911,18 +911,6 @@ typedef struct _POOLED_USAGE_AND_LIMITS
     SIZE_T PagefileLimit;
 } POOLED_USAGE_AND_LIMITS, *PPOOLED_USAGE_AND_LIMITS;
 
-typedef struct _PROCESS_LDT_INFORMATION
-{
-    ULONG Start;
-    ULONG Length;
-    LDT_ENTRY LdtEntries[ANYSIZE_ARRAY];
-} PROCESS_LDT_INFORMATION, *PPROCESS_LDT_INFORMATION;
-
-typedef struct _PROCESS_LDT_SIZE
-{
-    ULONG Length;
-} PROCESS_LDT_SIZE, *PPROCESS_LDT_SIZE;
-
 typedef struct _PROCESS_WS_WATCH_INFORMATION
 {
     PVOID FaultingPc;
@@ -951,6 +939,18 @@ typedef struct _PROCESS_HANDLE_TRACING_QUERY
 
 #endif
 
+typedef struct _PROCESS_LDT_INFORMATION
+{
+    ULONG Start;
+    ULONG Length;
+    LDT_ENTRY LdtEntries[ANYSIZE_ARRAY];
+} PROCESS_LDT_INFORMATION, *PPROCESS_LDT_INFORMATION;
+
+typedef struct _PROCESS_LDT_SIZE
+{
+    ULONG Length;
+} PROCESS_LDT_SIZE, *PPROCESS_LDT_SIZE;
+
 typedef struct _PROCESS_PRIORITY_CLASS
 {
     BOOLEAN Foreground;