Skip to content

Commit a330b56

Browse files
committed
[NTOS:PS] Enable alignment probing for thread/process information classes
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.
1 parent d30a167 commit a330b56

File tree

11 files changed

+141
-123
lines changed

11 files changed

+141
-123
lines changed

ntoskrnl/ex/event.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ NtQueryEvent(IN HANDLE EventHandle,
333333
EventInformationLength,
334334
ReturnLength,
335335
NULL,
336-
PreviousMode);
336+
PreviousMode,
337+
TRUE);
337338
if(!NT_SUCCESS(Status))
338339
{
339340
/* Invalid buffers */

ntoskrnl/ex/mutant.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ NtQueryMutant(IN HANDLE MutantHandle,
243243
MutantInformationLength,
244244
ResultLength,
245245
NULL,
246-
PreviousMode);
246+
PreviousMode,
247+
TRUE);
247248
if(!NT_SUCCESS(Status))
248249
{
249250
DPRINT("NtQueryMutant() failed, Status: 0x%x\n", Status);

ntoskrnl/ex/sem.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ NtQuerySemaphore(IN HANDLE SemaphoreHandle,
239239
SemaphoreInformationLength,
240240
ReturnLength,
241241
NULL,
242-
PreviousMode);
242+
PreviousMode,
243+
TRUE);
243244
if (!NT_SUCCESS(Status))
244245
{
245246
/* Invalid buffers */

ntoskrnl/ex/timer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,8 @@ NtQueryTimer(IN HANDLE TimerHandle,
536536
TimerInformationLength,
537537
ReturnLength,
538538
NULL,
539-
PreviousMode);
539+
PreviousMode,
540+
TRUE);
540541
if (!NT_SUCCESS(Status)) return Status;
541542

542543
/* Get the Timer Object */

ntoskrnl/include/internal/probe.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ DefaultQueryInfoBufferCheck(ULONG Class,
6363
ULONG BufferLength,
6464
PULONG ReturnLength,
6565
PULONG_PTR ReturnLengthPtr,
66-
KPROCESSOR_MODE PreviousMode)
66+
KPROCESSOR_MODE PreviousMode,
67+
BOOLEAN CompleteProbing)
6768
{
6869
NTSTATUS Status = STATUS_SUCCESS;
6970

@@ -90,9 +91,18 @@ DefaultQueryInfoBufferCheck(ULONG Class,
9091
{
9192
if (Buffer != NULL)
9293
{
93-
ProbeForWrite(Buffer,
94-
BufferLength,
95-
ClassList[Class].AlignmentQUERY);
94+
if (!CompleteProbing)
95+
{
96+
ProbeForRead(Buffer,
97+
BufferLength,
98+
ClassList[Class].AlignmentQUERY);
99+
}
100+
else
101+
{
102+
ProbeForWrite(Buffer,
103+
BufferLength,
104+
ClassList[Class].AlignmentQUERY);
105+
}
96106
}
97107

98108
if (ReturnLength != NULL)

0 commit comments

Comments
 (0)