Author: tkreuzer
Date: Mon Nov 18 14:27:01 2013
New Revision: 61037
URL:
http://svn.reactos.org/svn/reactos?rev=61037&view=rev
Log:
[NTOSKRNL]
Implement ObSetHandleAttributes. Rename the ObIsKernelHandle macro to ObpIsKernelHandle to
avoid ambiguities (ObIsKernelHandle is a public Vista+ API). Check for NtCurrentProcess
and NtCurrentThread in ObpIsKernelHandle, since those are always non-kernel handles.
Modified:
trunk/reactos/ntoskrnl/include/internal/ob.h
trunk/reactos/ntoskrnl/ob/obhandle.c
trunk/reactos/ntoskrnl/ob/oblife.c
trunk/reactos/ntoskrnl/ob/obsecure.c
trunk/reactos/ntoskrnl/ob/obwait.c
Modified: trunk/reactos/ntoskrnl/include/internal/ob.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ob.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/ob.h [iso-8859-1] Mon Nov 18 14:27:01 2013
@@ -61,9 +61,11 @@
#else
#define KERNEL_HANDLE_FLAG 0x80000000
#endif
-#define ObIsKernelHandle(Handle, ProcessorMode) \
- (((ULONG_PTR)(Handle) & KERNEL_HANDLE_FLAG) && \
- ((ProcessorMode) == KernelMode))
+#define ObpIsKernelHandle(Handle, ProcessorMode) \
+ ((((ULONG_PTR)(Handle) & KERNEL_HANDLE_FLAG) == KERNEL_HANDLE_FLAG) && \
+ ((ProcessorMode) == KernelMode) && \
+ ((Handle) != NtCurrentProcess()) && \
+ ((Handle) != NtCurrentThread()))
//
// Converts to and from a Kernel Handle to a normal handle
Modified: trunk/reactos/ntoskrnl/ob/obhandle.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/obhandle.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/ob/obhandle.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ob/obhandle.c [iso-8859-1] Mon Nov 18 14:27:01 2013
@@ -1714,7 +1714,7 @@
return STATUS_INVALID_HANDLE;
/* Check if we're dealing with a kernel handle */
- if (ObIsKernelHandle(Handle, AccessMode))
+ if (ObpIsKernelHandle(Handle, AccessMode))
{
/* Use the kernel table and convert the handle */
HandleTable = ObpKernelHandleTable;
@@ -2490,7 +2490,7 @@
PassedAccessState->SecurityDescriptor =
TempBuffer->ObjectCreateInfo.SecurityDescriptor;
}
-
+
/* Validate the access mask */
Status = ObpValidateAccessMask(PassedAccessState);
if (!NT_SUCCESS(Status))
@@ -3197,8 +3197,52 @@
IN POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleFlags,
IN KPROCESSOR_MODE PreviousMode)
{
- UNIMPLEMENTED;
- return STATUS_NOT_IMPLEMENTED;
+ OBP_SET_HANDLE_ATTRIBUTES_CONTEXT SetHandleAttributesContext;
+ BOOLEAN Result, AttachedToSystemProcess = FALSE;
+ PHANDLE_TABLE HandleTable;
+ KAPC_STATE ApcState;
+ PAGED_CODE();
+
+ /* Check if this is a kernel handle */
+ if (ObpIsKernelHandle(Handle, PreviousMode))
+ {
+ /* Use the kernel table and convert the handle */
+ HandleTable = ObpKernelHandleTable;
+ Handle = ObKernelHandleToHandle(Handle);
+
+ /* Check if we're not in the system process */
+ if (PsGetCurrentProcess() != PsInitialSystemProcess)
+ {
+ /* Attach to the system process */
+ KeStackAttachProcess(&PsInitialSystemProcess->Pcb, &ApcState);
+ AttachedToSystemProcess = TRUE;
+ }
+ }
+ else
+ {
+ /* Get the current process' handle table */
+ HandleTable = PsGetCurrentProcess()->ObjectTable;
+ }
+
+ /* Initialize the handle attribute context */
+ SetHandleAttributesContext.PreviousMode = PreviousMode;
+ SetHandleAttributesContext.Information = *HandleFlags;
+
+ /* Invoke the ObpSetHandleAttributes callback */
+ Result = ExChangeHandle(HandleTable,
+ Handle,
+ ObpSetHandleAttributes,
+ (ULONG_PTR)&SetHandleAttributesContext);
+
+ /* Did we attach to the system process? */
+ if (AttachedToSystemProcess)
+ {
+ /* Detach from it */
+ KeUnstackDetachProcess(&ApcState);
+ }
+
+ /* Return the result as an NTSTATUS value */
+ return Result ? STATUS_SUCCESS : STATUS_ACCESS_DENIED;
}
/*++
@@ -3364,13 +3408,12 @@
return Status;
}
-#undef ObIsKernelHandle
BOOLEAN
NTAPI
ObIsKernelHandle(IN HANDLE Handle)
{
- /* We know we're kernel mode, so just check for the kernel handle flag */
- return (BOOLEAN)(((ULONG_PTR)Handle & KERNEL_HANDLE_FLAG) != 0);
+ /* Use the inlined version. We know we are in kernel mode. */
+ return ObpIsKernelHandle(Handle, KernelMode);
}
/* EOF */
Modified: trunk/reactos/ntoskrnl/ob/oblife.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/oblife.c?rev=6…
==============================================================================
--- trunk/reactos/ntoskrnl/ob/oblife.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ob/oblife.c [iso-8859-1] Mon Nov 18 14:27:01 2013
@@ -1675,14 +1675,14 @@
switch (ObjectInformationClass)
{
case ObjectHandleFlagInformation:
-
+
/* Validate the length */
if (Length != sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION))
{
/* Invalid length */
return STATUS_INFO_LENGTH_MISMATCH;
}
-
+
/* Save the previous mode */
Context.PreviousMode = ExGetPreviousMode();
@@ -1714,7 +1714,7 @@
}
/* Check if this is a kernel handle */
- if (ObIsKernelHandle(ObjectHandle, Context.PreviousMode))
+ if (ObpIsKernelHandle(ObjectHandle, Context.PreviousMode))
{
/* Get the actual handle */
ObjectHandle = ObKernelHandleToHandle(ObjectHandle);
@@ -1752,9 +1752,9 @@
/* De-attach if we were attached, and return status */
if (AttachedToProcess) KeUnstackDetachProcess(&ApcState);
break;
-
+
case ObjectSessionInformation:
-
+
/* Only a system process can do this */
PreviousMode = ExGetPreviousMode();
if (!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode))
@@ -1766,8 +1766,8 @@
else
{
/* Get the object directory */
- Status = ObReferenceObjectByHandle(ObjectHandle,
- 0,
+ Status = ObReferenceObjectByHandle(ObjectHandle,
+ 0,
ObDirectoryType,
PreviousMode,
(PVOID*)&Directory,
@@ -1781,7 +1781,7 @@
}
}
break;
-
+
default:
/* Unsupported class */
Status = STATUS_INVALID_INFO_CLASS;
Modified: trunk/reactos/ntoskrnl/ob/obsecure.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/obsecure.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/ob/obsecure.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ob/obsecure.c [iso-8859-1] Mon Nov 18 14:27:01 2013
@@ -62,17 +62,17 @@
EX_FAST_REF FastRef;
ULONG Count;
PSECURITY_DESCRIPTOR OldSecurityDescriptor;
-
+
/* Get the fast reference and capture it */
FastRef = *(PEX_FAST_REF)SecurityDescriptor;
-
+
/* Don't free again later */
*SecurityDescriptor = NULL;
-
+
/* Get the descriptor and reference count */
OldSecurityDescriptor = ExGetObjectFastReference(FastRef);
Count = ExGetCountFastReference(FastRef);
-
+
/* Dereference the descriptor */
ObDereferenceSecurityDescriptor(OldSecurityDescriptor, Count + 1);
@@ -162,11 +162,11 @@
OldValue = ExCompareSwapFastReference(FastRef,
CachedDescriptor,
OldDescriptor);
-
+
/* Get the security descriptor */
SecurityDescriptor = ExGetObjectFastReference(OldValue);
Count = ExGetCountFastReference(OldValue);
-
+
/* Make sure the swap worked */
if (SecurityDescriptor == OldDescriptor)
{
@@ -1010,7 +1010,7 @@
PAGED_CODE();
/* Check if we're dealing with a kernel handle */
- if (ObIsKernelHandle(Handle, ExGetPreviousMode()))
+ if (ObpIsKernelHandle(Handle, ExGetPreviousMode()))
{
/* Use the kernel table and convert the handle */
HandleTable = ObpKernelHandleTable;
Modified: trunk/reactos/ntoskrnl/ob/obwait.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/obwait.c?rev=6…
==============================================================================
--- trunk/reactos/ntoskrnl/ob/obwait.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ob/obwait.c [iso-8859-1] Mon Nov 18 14:27:01 2013
@@ -142,7 +142,7 @@
do
{
/* Use the right Executive Handle */
- if (ObIsKernelHandle(Handles[i], PreviousMode))
+ if (ObpIsKernelHandle(Handles[i], PreviousMode))
{
/* Use the System Handle Table and decode */
HandleTable = ObpKernelHandleTable;