From 21b04efae881d1a96d7704d079a1ee89fe19f781 Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Sat, 17 Oct 2015 18:37:49 +0000 Subject: [PATCH] [NTOS:OB] - Create kernel handles if requested by the caller in ObDuplicateObject CORE-10207 svn path=/trunk/; revision=69571 --- reactos/ntoskrnl/ob/obhandle.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/reactos/ntoskrnl/ob/obhandle.c b/reactos/ntoskrnl/ob/obhandle.c index 94d96220f24..e97c69d5616 100644 --- a/reactos/ntoskrnl/ob/obhandle.c +++ b/reactos/ntoskrnl/ob/obhandle.c @@ -2150,6 +2150,8 @@ ObDuplicateObject(IN PEPROCESS SourceProcess, 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", @@ -2222,6 +2224,14 @@ ObDuplicateObject(IN PEPROCESS SourceProcess, 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) @@ -2376,6 +2386,12 @@ ObDuplicateObject(IN PEPROCESS SourceProcess, Status = STATUS_INSUFFICIENT_RESOURCES; } + /* Mark it as a kernel handle if requested */ + if (KernelHandle) + { + NewHandle = ObMarkHandleAsKernelHandle(NewHandle); + } + /* Return the handle */ if (TargetHandle) *TargetHandle = NewHandle; -- 2.17.1