Modified: trunk/reactos/ntoskrnl/ex/event.c
Modified: trunk/reactos/ntoskrnl/ex/mutant.c
Modified: trunk/reactos/ntoskrnl/ex/sem.c
Modified: trunk/reactos/ntoskrnl/ex/timer.c
Modified: trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h
Modified: trunk/reactos/ntoskrnl/include/internal/ob.h
Modified: trunk/reactos/ntoskrnl/io/iocomp.c
Modified: trunk/reactos/ntoskrnl/mm/section.c
Modified: trunk/reactos/ntoskrnl/ps/query.c
Modified: trunk/reactos/ntoskrnl/se/token.c
--- trunk/reactos/ntoskrnl/ex/event.c 2005-10-10 13:03:09 UTC (rev 18393)
+++ trunk/reactos/ntoskrnl/ex/event.c 2005-10-10 13:03:55 UTC (rev 18394)
@@ -311,13 +311,13 @@
DPRINT("NtQueryEvent(0x%p, 0x%x)\n", EventHandle, EventInformationClass);
/* Check buffers and class validity */
- DefaultQueryInfoBufferCheck(EventInformationClass,
- ExEventInfoClass,
- EventInformation,
- EventInformationLength,
- ReturnLength,
- PreviousMode,
- &Status);
+ Status = DefaultQueryInfoBufferCheck(EventInformationClass,
+ ExEventInfoClass,
+ sizeof(ExEventInfoClass) / sizeof(ExEventInfoClass[0]),
+ EventInformation,
+ EventInformationLength,
+ ReturnLength,
+ PreviousMode);
if(!NT_SUCCESS(Status)) {
/* Invalid buffers */
--- trunk/reactos/ntoskrnl/ex/mutant.c 2005-10-10 13:03:09 UTC (rev 18393)
+++ trunk/reactos/ntoskrnl/ex/mutant.c 2005-10-10 13:03:55 UTC (rev 18394)
@@ -227,13 +227,13 @@
PAGED_CODE();
/* Check buffers and parameters */
- DefaultQueryInfoBufferCheck(MutantInformationClass,
- ExMutantInfoClass,
- MutantInformation,
- MutantInformationLength,
- ResultLength,
- PreviousMode,
- &Status);
+ Status = DefaultQueryInfoBufferCheck(MutantInformationClass,
+ ExMutantInfoClass,
+ sizeof(ExMutantInfoClass) / sizeof(ExMutantInfoClass[0]),
+ MutantInformation,
+ MutantInformationLength,
+ ResultLength,
+ PreviousMode);
if(!NT_SUCCESS(Status)) {
DPRINT("NtQueryMutant() failed, Status: 0x%x\n", Status);
--- trunk/reactos/ntoskrnl/ex/sem.c 2005-10-10 13:03:09 UTC (rev 18393)
+++ trunk/reactos/ntoskrnl/ex/sem.c 2005-10-10 13:03:55 UTC (rev 18394)
@@ -215,13 +215,13 @@
PAGED_CODE();
/* Check buffers and class validity */
- DefaultQueryInfoBufferCheck(SemaphoreInformationClass,
- ExSemaphoreInfoClass,
- SemaphoreInformation,
- SemaphoreInformationLength,
- ReturnLength,
- PreviousMode,
- &Status);
+ Status = DefaultQueryInfoBufferCheck(SemaphoreInformationClass,
+ ExSemaphoreInfoClass,
+ sizeof(ExSemaphoreInfoClass) / sizeof(ExSemaphoreInfoClass[0]),
+ SemaphoreInformation,
+ SemaphoreInformationLength,
+ ReturnLength,
+ PreviousMode);
if(!NT_SUCCESS(Status))
{
/* Invalid buffers */
--- trunk/reactos/ntoskrnl/ex/timer.c 2005-10-10 13:03:09 UTC (rev 18393)
+++ trunk/reactos/ntoskrnl/ex/timer.c 2005-10-10 13:03:55 UTC (rev 18394)
@@ -545,13 +545,13 @@
DPRINT("NtQueryTimer(TimerHandle: 0x%p, Class: %d)\n", TimerHandle, TimerInformationClass);
/* Check Validity */
- DefaultQueryInfoBufferCheck(TimerInformationClass,
- ExTimerInfoClass,
- TimerInformation,
- TimerInformationLength,
- ReturnLength,
- PreviousMode,
- &Status);
+ Status = DefaultQueryInfoBufferCheck(TimerInformationClass,
+ ExTimerInfoClass,
+ sizeof(ExTimerInfoClass) / sizeof(ExTimerInfoClass[0]),
+ TimerInformation,
+ TimerInformationLength,
+ ReturnLength,
+ PreviousMode);
if(!NT_SUCCESS(Status))
{
DPRINT1("NtQueryTimer() failed, Status: 0x%x\n", Status);
--- trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h 2005-10-10 13:03:09 UTC (rev 18393)
+++ trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h 2005-10-10 13:03:55 UTC (rev 18394)
@@ -208,6 +208,138 @@
#define ProbeForReadUlargeInteger(Ptr) ((ULARGE_INTEGER)ProbeForReadGenericType(&(Ptr)->QuadPart, ULONGLONG, 0))
/*
+ * generic information class probing code
+ */
+
+#define ICIF_QUERY 0x1
+#define ICIF_SET 0x2
+#define ICIF_QUERY_SIZE_VARIABLE 0x4
+#define ICIF_SET_SIZE_VARIABLE 0x8
+#define ICIF_SIZE_VARIABLE (ICIF_QUERY_SIZE_VARIABLE | ICIF_SET_SIZE_VARIABLE)
+
+typedef struct _INFORMATION_CLASS_INFO
+{
+ ULONG RequiredSizeQUERY;
+ ULONG RequiredSizeSET;
+ ULONG AlignmentSET;
+ ULONG AlignmentQUERY;
+ ULONG Flags;
+} INFORMATION_CLASS_INFO, *PINFORMATION_CLASS_INFO;
+
+#define ICI_SQ_SAME(Size, Alignment, Flags) \
+ { Size, Size, Alignment, Alignment, Flags }
+
+#define ICI_SQ(SizeQuery, SizeSet, AlignmentQuery, AlignmentSet, Flags) \
+ { SizeQuery, SizeSet, AlignmentQuery, AlignmentSet, Flags }
+
+static inline NTSTATUS
+DefaultSetInfoBufferCheck(UINT Class,
+ const INFORMATION_CLASS_INFO *ClassList,
+ UINT ClassListEntries,
+ PVOID Buffer,
+ ULONG BufferLength,
+ KPROCESSOR_MODE PreviousMode)
+{
+ NTSTATUS Status = STATUS_SUCCESS;
+
+ if (Class >= 0 && Class < ClassListEntries)
+ {
+ if (!(ClassList[Class].Flags & ICIF_SET))
+ {
+ Status = STATUS_INVALID_INFO_CLASS;
+ }
+ else if (ClassList[Class].RequiredSizeSET > 0 &&
+ BufferLength != ClassList[Class].RequiredSizeSET)
+ {
+ if (!(ClassList[Class].Flags & ICIF_SET_SIZE_VARIABLE))
+ {
+ Status = STATUS_INFO_LENGTH_MISMATCH;
+ }
+ }
+
+ if (NT_SUCCESS(Status))
+ {
+ if (PreviousMode != KernelMode)
+ {
+ _SEH_TRY
+ {
+ ProbeForRead(Buffer,
+ BufferLength,
+ ClassList[Class].AlignmentSET);
+ }
+ _SEH_HANDLE
+ {
+ Status = _SEH_GetExceptionCode();
+ }
+ _SEH_END;
+ }
+ }
+ }
+ else
+ Status = STATUS_INVALID_INFO_CLASS;
+
+ return Status;
+}
+
+static inline NTSTATUS
+DefaultQueryInfoBufferCheck(UINT Class,
+ const INFORMATION_CLASS_INFO *ClassList,
+ UINT ClassListEntries,
+ PVOID Buffer,
+ ULONG BufferLength,
+ PULONG ReturnLength,
+ KPROCESSOR_MODE PreviousMode)
+{
+ NTSTATUS Status = STATUS_SUCCESS;
+
+ if (Class >= 0 && Class < ClassListEntries)
+ {
+ if (!(ClassList[Class].Flags & ICIF_QUERY))
+ {
+ Status = STATUS_INVALID_INFO_CLASS;
+ }
+ else if (ClassList[Class].RequiredSizeQUERY > 0 &&
+ BufferLength != ClassList[Class].RequiredSizeQUERY)
+ {
+ if (!(ClassList[Class].Flags & ICIF_QUERY_SIZE_VARIABLE))
+ {
+ Status = STATUS_INFO_LENGTH_MISMATCH;
+ }
+ }
+
+ if (NT_SUCCESS(Status))
+ {
+ if (PreviousMode != KernelMode)
+ {
+ _SEH_TRY
+ {
+ if (Buffer != NULL)
+ {
+ ProbeForWrite(Buffer,
+ BufferLength,
+ ClassList[Class].AlignmentQUERY);
+ }
+
+ if (ReturnLength != NULL)
+ {
+ ProbeForWriteUlong(ReturnLength);
+ }
+ }
+ _SEH_HANDLE
+ {
+ Status = _SEH_GetExceptionCode();
+ }
+ _SEH_END;
+ }
+ }
+ }
+ else
+ Status = STATUS_INVALID_INFO_CLASS;
+
+ return Status;
+}
+
+/*
* Use IsPointerOffset to test whether a pointer should be interpreted as an offset
* or as a pointer
*/
--- trunk/reactos/ntoskrnl/include/internal/ob.h 2005-10-10 13:03:09 UTC (rev 18393)
+++ trunk/reactos/ntoskrnl/include/internal/ob.h 2005-10-10 13:03:55 UTC (rev 18394)
@@ -11,12 +11,6 @@
struct _EPROCESS;
-#define ICIF_QUERY 0x1
-#define ICIF_SET 0x2
-#define ICIF_QUERY_SIZE_VARIABLE 0x4
-#define ICIF_SET_SIZE_VARIABLE 0x8
-#define ICIF_SIZE_VARIABLE (ICIF_QUERY_SIZE_VARIABLE | ICIF_SET_SIZE_VARIABLE)
-
typedef struct _DIRECTORY_OBJECT
{
CSHORT Type;
@@ -37,15 +31,6 @@
LARGE_INTEGER CreateTime;
} SYMLINK_OBJECT, *PSYMLINK_OBJECT;
-typedef struct _INFORMATION_CLASS_INFO
-{
- ULONG RequiredSizeQUERY;
- ULONG RequiredSizeSET;
- ULONG AlignmentSET;
- ULONG AlignmentQUERY;
- ULONG Flags;
-} INFORMATION_CLASS_INFO, *PINFORMATION_CLASS_INFO;
-
#define BODY_TO_HEADER(objbdy) \
CONTAINING_RECORD((objbdy), OBJECT_HEADER, Body)
@@ -251,152 +236,6 @@
/* object information classes */
-#define ICI_SQ_SAME(Size, Alignment, Flags) \
- { Size, Size, Alignment, Alignment, Flags }
-#define ICI_SQ(SizeQuery, SizeSet, AlignmentQuery, AlignmentSet, Flags) \
- { SizeQuery, SizeSet, AlignmentQuery, AlignmentSet, Flags }
-#define CheckInfoClass(Class, BufferLen, ClassList, StatusVar, Mode) \
- do { \
- if((Class) >= 0 && (Class) < sizeof(ClassList) / sizeof(ClassList[0])) \
- { \
- if(!(ClassList[Class].Flags & ICIF_##Mode)) \
- { \
- *(StatusVar) = STATUS_INVALID_INFO_CLASS; \
- } \
- else if(ClassList[Class].RequiredSize##Mode > 0 && \
- (BufferLen) != ClassList[Class].RequiredSize##Mode) \
- { \
- if(!(ClassList[Class].Flags & ICIF_##Mode##_SIZE_VARIABLE) && \
- (BufferLen) != ClassList[Class].RequiredSize##Mode) \
- { \
- *(StatusVar) = STATUS_INFO_LENGTH_MISMATCH; \
- } \
- } \
- } \
- else \
- { \
- *(StatusVar) = STATUS_INVALID_INFO_CLASS; \
- } \
- } while(0)
-
-
-#define GetInfoClassAlignment(Class, ClassList, AlignmentVar, Mode) \
- do { \
- if((Class) >= 0 && (Class) < sizeof(ClassList) / sizeof(ClassList[0])) \
- { \
- *(AlignmentVar) = ClassList[Class].Alignment##Mode; \
- } \
- else \
- { \
- *(AlignmentVar) = sizeof(ULONG); \
- } \
- } while(0)
-
-#define ProbeQueryInfoBuffer(Buffer, BufferLen, Alignment, RetLen, PrevMode, StatusVar) \
- do { \
- if(PrevMode != KernelMode) \
- { \
- _SEH_TRY \
- { \
- ProbeForWrite(Buffer, \
- BufferLen, \
- Alignment); \
- if(RetLen != NULL) \
- { \
- ProbeForWrite(RetLen, \
- sizeof(ULONG), \
- 1); \
- } \
- } \
- _SEH_HANDLE \
- { \
- *(StatusVar) = _SEH_GetExceptionCode(); \
- } \
- _SEH_END; \
- \
- if(!NT_SUCCESS(*(StatusVar))) \
- { \
- DPRINT1("ProbeQueryInfoBuffer failed: 0x%x\n", *(StatusVar)); \
- return *(StatusVar); \
- } \
- } \
- } while(0)
-
-#define ProbeSetInfoBuffer(Buffer, BufferLen, Alignment, PrevMode, StatusVar) \
- do { \
- if(PrevMode != KernelMode) \
- { \
- _SEH_TRY \
- { \
- ProbeForRead(Buffer, \
- BufferLen, \
- Alignment); \
- } \
- _SEH_HANDLE \
- { \
- *(StatusVar) = _SEH_GetExceptionCode(); \
- } \
- _SEH_END; \
- \
- if(!NT_SUCCESS(*(StatusVar))) \
- { \
- DPRINT1("ProbeAllInfoBuffer failed: 0x%x\n", *(StatusVar)); \
- return *(StatusVar); \
- } \
- } \
- } while(0)
-
-#define DefaultSetInfoBufferCheck(Class, ClassList, Buffer, BufferLen, PrevMode, StatusVar) \
- do { \
- ULONG _Alignment; \
- /* get the preferred alignment for the information class or return */ \
- /* default alignment in case the class doesn't exist */ \
- GetInfoClassAlignment(Class, \
- ClassList, \
- &_Alignment, \
- SET); \
- \
- /* probe the ENTIRE buffers and return on failure */ \
- ProbeSetInfoBuffer(Buffer, \
- BufferLen, \
- _Alignment, \
- PrevMode, \
- StatusVar); \
- \
- /* validate information class index and check buffer size */ \
- CheckInfoClass(Class, \
- BufferLen, \
- ClassList, \
- StatusVar, \
- SET); \
- } while(0)
-
-#define DefaultQueryInfoBufferCheck(Class, ClassList, Buffer, BufferLen, RetLen, PrevMode, StatusVar) \
- do { \
- ULONG _Alignment; \
- /* get the preferred alignment for the information class or return */ \
- /* alignment in case the class doesn't exist */ \
- GetInfoClassAlignment(Class, \
- ClassList, \
- &_Alignment, \
- QUERY); \
- \
- /* probe the ENTIRE buffers and return on failure */ \
- ProbeQueryInfoBuffer(Buffer, \
- BufferLen, \
- _Alignment, \
- RetLen, \
- PrevMode, \
- StatusVar); \
- \
- /* validate information class index and check buffer size */ \
- CheckInfoClass(Class, \
- BufferLen, \
- ClassList, \
- StatusVar, \
- QUERY); \
- } while(0)
-
#endif /* __INCLUDE_INTERNAL_OBJMGR_H */
--- trunk/reactos/ntoskrnl/io/iocomp.c 2005-10-10 13:03:09 UTC (rev 18393)
+++ trunk/reactos/ntoskrnl/io/iocomp.c 2005-10-10 13:03:55 UTC (rev 18394)
@@ -359,13 +359,13 @@
PAGED_CODE();
/* Check buffers and parameters */
- DefaultQueryInfoBufferCheck(IoCompletionInformationClass,
- IoCompletionInfoClass,
- IoCompletionInformation,
- IoCompletionInformationLength,
- ResultLength,
- PreviousMode,
- &Status);
+ Status = DefaultQueryInfoBufferCheck(IoCompletionInformationClass,
+ IoCompletionInfoClass,
+ sizeof(IoCompletionInfoClass) / sizeof(IoCompletionInfoClass[0]),
+ IoCompletionInformation,
+ IoCompletionInformationLength,
+ ResultLength,
+ PreviousMode);
if(!NT_SUCCESS(Status)) {
DPRINT1("NtQueryMutant() failed, Status: 0x%x\n", Status);
--- trunk/reactos/ntoskrnl/mm/section.c 2005-10-10 13:03:09 UTC (rev 18393)
+++ trunk/reactos/ntoskrnl/mm/section.c 2005-10-10 13:03:55 UTC (rev 18394)
@@ -4012,13 +4012,13 @@
PreviousMode = ExGetPreviousMode();
- DefaultQueryInfoBufferCheck(SectionInformationClass,
- ExSectionInfoClass,
- SectionInformation,
- SectionInformationLength,
- ResultLength,
- PreviousMode,
- &Status);
+ Status = DefaultQueryInfoBufferCheck(SectionInformationClass,
+ ExSectionInfoClass,
+ sizeof(ExSectionInfoClass) / sizeof(ExSectionInfoClass[0]),
+ SectionInformation,
+ SectionInformationLength,
+ ResultLength,
+ PreviousMode);
if(!NT_SUCCESS(Status))
{
--- trunk/reactos/ntoskrnl/ps/query.c 2005-10-10 13:03:09 UTC (rev 18393)
+++ trunk/reactos/ntoskrnl/ps/query.c 2005-10-10 13:03:55 UTC (rev 18394)
@@ -143,13 +143,13 @@
PreviousMode = ExGetPreviousMode();
- DefaultQueryInfoBufferCheck(ProcessInformationClass,
- PsProcessInfoClass,
- ProcessInformation,
- ProcessInformationLength,
- ReturnLength,
- PreviousMode,
- &Status);
+ Status = DefaultQueryInfoBufferCheck(ProcessInformationClass,
+ PsProcessInfoClass,
+ sizeof(PsProcessInfoClass) / sizeof(PsProcessInfoClass[0]),
+ ProcessInformation,
+ ProcessInformationLength,
+ ReturnLength,
+ PreviousMode);
if(!NT_SUCCESS(Status))
{
DPRINT1("NtQueryInformationProcess() failed, Status: 0x%x\n", Status);
@@ -654,12 +654,12 @@
PreviousMode = ExGetPreviousMode();
- DefaultSetInfoBufferCheck(ProcessInformationClass,
- PsProcessInfoClass,
- ProcessInformation,
- ProcessInformationLength,
- PreviousMode,
- &Status);
+ Status = DefaultSetInfoBufferCheck(ProcessInformationClass,
+ PsProcessInfoClass,
+ sizeof(PsProcessInfoClass) / sizeof(PsProcessInfoClass[0]),
+ ProcessInformation,
+ ProcessInformationLength,
+ PreviousMode);
if(!NT_SUCCESS(Status))
{
DPRINT1("NtSetInformationProcess() %d %x %x called\n", ProcessInformationClass, ProcessInformation, ProcessInformationLength);
--- trunk/reactos/ntoskrnl/se/token.c 2005-10-10 13:03:09 UTC (rev 18393)
+++ trunk/reactos/ntoskrnl/se/token.c 2005-10-10 13:03:55 UTC (rev 18394)
@@ -615,13 +615,13 @@
PreviousMode = ExGetPreviousMode();
/* Check buffers and class validity */
- DefaultQueryInfoBufferCheck(TokenInformationClass,
- SeTokenInformationClass,
- TokenInformation,
- TokenInformationLength,
- ReturnLength,
- PreviousMode,
- &Status);
+ Status = DefaultQueryInfoBufferCheck(TokenInformationClass,
+ SeTokenInformationClass,
+ sizeof(SeTokenInformationClass) / sizeof(SeTokenInformationClass[0]),
+ TokenInformation,
+ TokenInformationLength,
+ ReturnLength,
+ PreviousMode);
if(!NT_SUCCESS(Status))
{
@@ -1198,12 +1198,12 @@
PreviousMode = ExGetPreviousMode();
- DefaultSetInfoBufferCheck(TokenInformationClass,
- SeTokenInformationClass,
- TokenInformation,
- TokenInformationLength,
- PreviousMode,
- &Status);
+ Status = DefaultSetInfoBufferCheck(TokenInformationClass,
+ SeTokenInformationClass,
+ sizeof(SeTokenInformationClass) / sizeof(SeTokenInformationClass[0]),
+ TokenInformation,
+ TokenInformationLength,
+ PreviousMode);
if(!NT_SUCCESS(Status))
{