NTAPI
ObpValidateAccessMask(IN PACCESS_STATE AccessState)
{
- /* TODO */
+ PISECURITY_DESCRIPTOR SecurityDescriptor;
+
+ /* We're only interested if the object for this access state has an SD */
+ SecurityDescriptor = AccessState->SecurityDescriptor;
+ if (SecurityDescriptor)
+ {
+ /* Check if the SD has a system ACL but hasn't been granted access to get/set it */
+ if ((SecurityDescriptor->Control & SE_SACL_PRESENT) &&
+ !(AccessState->PreviouslyGrantedAccess & ACCESS_SYSTEM_SECURITY))
+ {
+ /* We're gonna need access */
+ AccessState->RemainingDesiredAccess |= ACCESS_SYSTEM_SECURITY;
+ }
+ }
+
+ /* This can't fail */
return STATUS_SUCCESS;
}
KIRQL CalloutIrql;
KPROCESSOR_MODE ProbeMode;
ULONG Total;
+ POBJECT_HEADER_NAME_INFO NameInfo;
PAGED_CODE();
/* Get the object header and type */
goto Quickie;
}
+ /* Check for exclusive kernel object */
+ NameInfo = OBJECT_HEADER_TO_NAME_INFO(ObjectHeader);
+ if ((NameInfo) && (NameInfo->QueryReferences & OB_FLAG_KERNEL_EXCLUSIVE) &&
+ (ProbeMode != KernelMode))
+ {
+ /* Caller is not kernel, but the object is kernel exclusive */
+ Status = STATUS_ACCESS_DENIED;
+ goto Quickie;
+ }
+
/*
* Check if this is an object that went from 0 handles back to existence,
* but doesn't have an open procedure, only a close procedure. This means
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;
return Ret;
}
+/*++
+* @name ObClearProcessHandleTable
+*
+* The ObClearProcessHandleTable routine clears the handle table
+* of the given process.
+*
+* @param Process
+* The process of which the handle table should be cleared.
+*
+* @return None.
+*
+* @remarks None.
+*
+*--*/
VOID
NTAPI
ObClearProcessHandleTable(IN PEPROCESS Process)
{
- /* FIXME */
+ PHANDLE_TABLE HandleTable;
+ OBP_CLOSE_HANDLE_CONTEXT Context;
+ KAPC_STATE ApcState;
+ BOOLEAN AttachedToProcess = FALSE;
+
+ ASSERT(Process);
+
+ /* Ensure the handle table doesn't go away while we use it */
+ HandleTable = ObReferenceProcessHandleTable(Process);
+ if (!HandleTable) return;
+
+ /* Attach to the current process if needed */
+ if (PsGetCurrentProcess() != Process)
+ {
+ KeStackAttachProcess(&Process->Pcb, &ApcState);
+ AttachedToProcess = TRUE;
+ }
+
+ /* Enter a critical region */
+ KeEnterCriticalRegion();
+
+ /* Fill out the context */
+ Context.AccessMode = UserMode;
+ Context.HandleTable = HandleTable;
+
+ /* Sweep the handle table to close all handles */
+ ExSweepHandleTable(HandleTable,
+ ObpCloseHandleCallback,
+ &Context);
+
+ /* Leave the critical region */
+ KeLeaveCriticalRegion();
+
+ /* Detach if needed */
+ if (AttachedToProcess)
+ KeUnstackDetachProcess(&ApcState);
+
+ /* Let the handle table go */
+ ObDereferenceProcessHandleTable(Process);
}
/*++
-* @name ObpCreateHandleTable
+* @name ObInitProcess
*
-* The ObpCreateHandleTable routine <FILLMEIN>
+* The ObInitProcess routine initializes the handle table for the process
+* to be initialized, by either creating a new one or duplicating it from
+* the parent process.
*
* @param Parent
-* <FILLMEIN>.
+* A parent process (optional).
*
* @param Process
-* <FILLMEIN>.
+* The process to initialize.
*
-* @return <FILLMEIN>.
+* @return Success or failure.
*
* @remarks None.
*
/*++
* @name ObKillProcess
*
-* The ObKillProcess routine <FILLMEIN>
+* The ObKillProcess routine performs rundown operations on the process,
+* then clears and destroys its handle table.
*
* @param Process
-* <FILLMEIN>.
+* The process to be killed.
*
* @return None.
*
-* @remarks None.
+* @remarks Called by the Object Manager cleanup code (kernel)
+* when a process is to be destroyed.
*
*--*/
VOID
PHANDLE_TABLE HandleTable;
OBJECT_HANDLE_INFORMATION HandleInformation;
ULONG AuditMask;
+ BOOLEAN KernelHandle = FALSE;
+
PAGED_CODE();
OBTRACE(OB_HANDLE_DEBUG,
"%s - Duplicating handle: %p for %p into %p\n",
return Status;
}
+ /* Create a kernel handle if asked, but only in the system process */
+ if (PreviousMode == KernelMode &&
+ HandleAttributes & OBJ_KERNEL_HANDLE &&
+ TargetProcess == PsInitialSystemProcess)
+ {
+ KernelHandle = TRUE;
+ }
+
/* Get the target handle table */
HandleTable = ObReferenceProcessHandleTable(TargetProcess);
if (!HandleTable)
Status = STATUS_INSUFFICIENT_RESOURCES;
}
+ /* Mark it as a kernel handle if requested */
+ if (KernelHandle)
+ {
+ NewHandle = ObMarkHandleAsKernelHandle(NewHandle);
+ }
+
/* Return the handle */
if (TargetHandle) *TargetHandle = NewHandle;
{
PVOID Object = NULL;
UNICODE_STRING ObjectName;
- NTSTATUS Status;
+ NTSTATUS Status, Status2;
POBJECT_HEADER ObjectHeader;
PGENERIC_MAPPING GenericMapping = NULL;
OB_OPEN_REASON OpenReason;
PassedAccessState->SecurityDescriptor =
TempBuffer->ObjectCreateInfo.SecurityDescriptor;
}
-
+
/* Validate the access mask */
Status = ObpValidateAccessMask(PassedAccessState);
if (!NT_SUCCESS(Status))
else
{
/* Create the actual handle now */
- Status = ObpCreateHandle(OpenReason,
- Object,
- ObjectType,
- PassedAccessState,
- 0,
- TempBuffer->ObjectCreateInfo.Attributes,
- &TempBuffer->LookupContext,
- AccessMode,
- NULL,
- Handle);
- if (!NT_SUCCESS(Status)) ObDereferenceObject(Object);
+ Status2 = ObpCreateHandle(OpenReason,
+ Object,
+ ObjectType,
+ PassedAccessState,
+ 0,
+ TempBuffer->ObjectCreateInfo.Attributes,
+ &TempBuffer->LookupContext,
+ AccessMode,
+ NULL,
+ Handle);
+ if (!NT_SUCCESS(Status2))
+ {
+ ObDereferenceObject(Object);
+ Status = Status2;
+ }
}
Cleanup:
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;
}
/*++
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 */