mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 16:35:49 +00:00
- Enable sanity check in ObInsertObject to catch assholes that were calling it incorrectly (without a Handle output parameter, which is only allowed in a specific scenario). Changes:
- Registry code which was calling ObInsertObject for no reason at all. Now an ugly hack has been added to Cm code to perform the only operation the insert did -> to free the create info. - SeSubProcessToken was broken and calling it incorrectly, fixed. - \Device\PhysicalMemory was being inserted incorrectly, fixed. - Boot-time driver objects were being inserted for no reason, call removed. - Support the only case of ObInsertObject where it is OK to call it without an output handle. This codepath will only charge quota instead of creating the full-blown handle. svn path=/trunk/; revision=25394
This commit is contained in:
parent
612a4059a4
commit
fe1190c599
6 changed files with 61 additions and 57 deletions
|
@ -597,6 +597,7 @@ CmiConnectHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes,
|
||||||
RtlFreeUnicodeString(&RemainingPath);
|
RtlFreeUnicodeString(&RemainingPath);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
DPRINT("Inserting Key into Object Tree\n");
|
DPRINT("Inserting Key into Object Tree\n");
|
||||||
Status = ObInsertObject((PVOID)NewKey,
|
Status = ObInsertObject((PVOID)NewKey,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -605,6 +606,11 @@ CmiConnectHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
DPRINT("Status %x\n", Status);
|
DPRINT("Status %x\n", Status);
|
||||||
|
#else
|
||||||
|
/* Free the create information */
|
||||||
|
ObpFreeAndReleaseCapturedAttributes(OBJECT_TO_OBJECT_HEADER(NewKey)->ObjectCreateInfo);
|
||||||
|
OBJECT_TO_OBJECT_HEADER(NewKey)->ObjectCreateInfo = NULL;
|
||||||
|
#endif
|
||||||
NewKey->Flags = 0;
|
NewKey->Flags = 0;
|
||||||
NewKey->SubKeyCounts = 0;
|
NewKey->SubKeyCounts = 0;
|
||||||
NewKey->SubKeys = NULL;
|
NewKey->SubKeys = NULL;
|
||||||
|
|
|
@ -382,6 +382,7 @@ CmiObjectParse(IN PVOID ParsedObject,
|
||||||
RtlFreeUnicodeString(&KeyName);
|
RtlFreeUnicodeString(&KeyName);
|
||||||
return(Status);
|
return(Status);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
DPRINT("Inserting Key into Object Tree\n");
|
DPRINT("Inserting Key into Object Tree\n");
|
||||||
Status = ObInsertObject((PVOID)FoundObject,
|
Status = ObInsertObject((PVOID)FoundObject,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -390,6 +391,11 @@ CmiObjectParse(IN PVOID ParsedObject,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
DPRINT("Status %x\n", Status);
|
DPRINT("Status %x\n", Status);
|
||||||
|
#else
|
||||||
|
/* Free the create information */
|
||||||
|
ObpFreeAndReleaseCapturedAttributes(OBJECT_TO_OBJECT_HEADER(FoundObject)->ObjectCreateInfo);
|
||||||
|
OBJECT_TO_OBJECT_HEADER(FoundObject)->ObjectCreateInfo = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Add the keep-alive reference */
|
/* Add the keep-alive reference */
|
||||||
ObReferenceObject(FoundObject);
|
ObReferenceObject(FoundObject);
|
||||||
|
|
|
@ -263,18 +263,6 @@ IopCreateDriverObject(
|
||||||
ExFreePool(Buffer);
|
ExFreePool(Buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Status = ObInsertObject(Object,
|
|
||||||
NULL,
|
|
||||||
FILE_ALL_ACCESS,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
*DriverObject = Object;
|
*DriverObject = Object;
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
|
|
|
@ -2216,6 +2216,7 @@ MmCreatePhysicalMemorySection(VOID)
|
||||||
OBJECT_ATTRIBUTES Obj;
|
OBJECT_ATTRIBUTES Obj;
|
||||||
UNICODE_STRING Name = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
|
UNICODE_STRING Name = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
|
||||||
LARGE_INTEGER SectionSize;
|
LARGE_INTEGER SectionSize;
|
||||||
|
HANDLE Handle;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the section mapping physical memory
|
* Create the section mapping physical memory
|
||||||
|
@ -2244,11 +2245,12 @@ MmCreatePhysicalMemorySection(VOID)
|
||||||
SECTION_ALL_ACCESS,
|
SECTION_ALL_ACCESS,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
&Handle);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
ObDereferenceObject(PhysSection);
|
ObDereferenceObject(PhysSection);
|
||||||
}
|
}
|
||||||
|
ObCloseHandle(Handle, KernelMode);
|
||||||
PhysSection->AllocationAttributes |= SEC_PHYSICALMEMORY;
|
PhysSection->AllocationAttributes |= SEC_PHYSICALMEMORY;
|
||||||
PhysSection->Segment->Flags &= ~MM_PAGEFILE_SEGMENT;
|
PhysSection->Segment->Flags &= ~MM_PAGEFILE_SEGMENT;
|
||||||
|
|
||||||
|
|
|
@ -2329,6 +2329,7 @@ ObInsertObject(IN PVOID Object,
|
||||||
OB_OPEN_REASON OpenReason;
|
OB_OPEN_REASON OpenReason;
|
||||||
KPROCESSOR_MODE PreviousMode;
|
KPROCESSOR_MODE PreviousMode;
|
||||||
NTSTATUS Status = STATUS_SUCCESS, RealStatus;
|
NTSTATUS Status = STATUS_SUCCESS, RealStatus;
|
||||||
|
BOOLEAN IsNewObject;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Get the Header */
|
/* Get the Header */
|
||||||
|
@ -2371,34 +2372,28 @@ ObInsertObject(IN PVOID Object,
|
||||||
ObjectName = &ObjectNameInfo->Name;
|
ObjectName = &ObjectNameInfo->Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sanity check, but broken on ROS due to Cm */
|
/* Sanity check */
|
||||||
#if 0
|
|
||||||
ASSERT((Handle) ||
|
ASSERT((Handle) ||
|
||||||
((ObjectPointerBias == 0) &&
|
((ObjectPointerBias == 0) &&
|
||||||
(ObjectName == NULL) &&
|
(ObjectName == NULL) &&
|
||||||
(ObjectType->TypeInfo.SecurityRequired) &&
|
(ObjectType->TypeInfo.SecurityRequired) &&
|
||||||
(NewObject == NULL)));
|
(NewObject == NULL)));
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Check if the object is unnamed and also doesn't have security */
|
/* Check if the object is unnamed and also doesn't have security */
|
||||||
PreviousMode = KeGetPreviousMode();
|
PreviousMode = KeGetPreviousMode();
|
||||||
if (!(ObjectType->TypeInfo.SecurityRequired) && !(ObjectName))
|
if (!(ObjectType->TypeInfo.SecurityRequired) && !(ObjectName))
|
||||||
{
|
{
|
||||||
/* ReactOS HACK */
|
/* Assume failure */
|
||||||
if (Handle)
|
*Handle = NULL;
|
||||||
{
|
|
||||||
/* Assume failure */
|
|
||||||
*Handle = NULL;
|
|
||||||
|
|
||||||
/* Create the handle */
|
/* Create the handle */
|
||||||
Status = ObpCreateUnnamedHandle(Object,
|
Status = ObpCreateUnnamedHandle(Object,
|
||||||
DesiredAccess,
|
DesiredAccess,
|
||||||
ObjectPointerBias + 1,
|
ObjectPointerBias + 1,
|
||||||
ObjectCreateInfo->Attributes,
|
ObjectCreateInfo->Attributes,
|
||||||
PreviousMode,
|
PreviousMode,
|
||||||
NewObject,
|
NewObject,
|
||||||
Handle);
|
Handle);
|
||||||
}
|
|
||||||
|
|
||||||
/* Free the create information */
|
/* Free the create information */
|
||||||
ObpFreeAndReleaseCapturedAttributes(ObjectCreateInfo);
|
ObpFreeAndReleaseCapturedAttributes(ObjectCreateInfo);
|
||||||
|
@ -2408,7 +2403,7 @@ ObInsertObject(IN PVOID Object,
|
||||||
if (ObjectNameInfo) ObpDecrementQueryReference(ObjectNameInfo);
|
if (ObjectNameInfo) ObpDecrementQueryReference(ObjectNameInfo);
|
||||||
|
|
||||||
/* Remove the extra keep-alive reference */
|
/* Remove the extra keep-alive reference */
|
||||||
if (Handle) ObDereferenceObject(Object);
|
ObDereferenceObject(Object);
|
||||||
|
|
||||||
/* Return */
|
/* Return */
|
||||||
OBTRACE(OB_HANDLE_DEBUG,
|
OBTRACE(OB_HANDLE_DEBUG,
|
||||||
|
@ -2590,12 +2585,7 @@ ObInsertObject(IN PVOID Object,
|
||||||
/* Save the actual status until here */
|
/* Save the actual status until here */
|
||||||
RealStatus = Status;
|
RealStatus = Status;
|
||||||
|
|
||||||
/* HACKHACK: Because of ROS's incorrect startup, this can be called
|
/* Check if caller wants us to create a handle */
|
||||||
* without a valid Process until I finalize the startup patch,
|
|
||||||
* so don't create a handle if this is the case. We also don't create
|
|
||||||
* a handle if Handle is NULL when the Registry Code calls it, because
|
|
||||||
* the registry code totally bastardizes the Ob and needs to be fixed
|
|
||||||
*/
|
|
||||||
ObjectHeader->ObjectCreateInfo = NULL;
|
ObjectHeader->ObjectCreateInfo = NULL;
|
||||||
if (Handle)
|
if (Handle)
|
||||||
{
|
{
|
||||||
|
@ -2610,29 +2600,39 @@ ObInsertObject(IN PVOID Object,
|
||||||
PreviousMode,
|
PreviousMode,
|
||||||
NewObject,
|
NewObject,
|
||||||
Handle);
|
Handle);
|
||||||
}
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* If the object had a name, backout everything */
|
||||||
|
if (ObjectName) ObpDeleteNameCheck(Object);
|
||||||
|
|
||||||
/* Check if creating the handle failed */
|
/* Return the status of the failure */
|
||||||
if (!NT_SUCCESS(Status))
|
*Handle = NULL;
|
||||||
|
RealStatus = Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove a query reference */
|
||||||
|
if (ObjectNameInfo) ObpDecrementQueryReference(ObjectNameInfo);
|
||||||
|
|
||||||
|
/* Remove the extra keep-alive reference */
|
||||||
|
ObDereferenceObject(Object);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
/* If the object had a name, backout everything */
|
/* Otherwise, lock the object type */
|
||||||
if (ObjectName) ObpDeleteNameCheck(Object);
|
ObpEnterObjectTypeMutex(ObjectType);
|
||||||
|
|
||||||
|
/* And charge quota for the process to make it appear as used */
|
||||||
|
RealStatus = ObpChargeQuotaForObject(ObjectHeader,
|
||||||
|
ObjectType,
|
||||||
|
&IsNewObject);
|
||||||
|
|
||||||
|
/* Release the lock */
|
||||||
|
ObpLeaveObjectTypeMutex(ObjectType);
|
||||||
|
|
||||||
|
/* Check if we failed and dereference the object if so */
|
||||||
|
if (!NT_SUCCESS(RealStatus)) ObDereferenceObject(Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check our final status */
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
/* Return the status of the failure */
|
|
||||||
*Handle = NULL;
|
|
||||||
RealStatus = Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Remove a query reference */
|
|
||||||
if (ObjectNameInfo) ObpDecrementQueryReference(ObjectNameInfo);
|
|
||||||
|
|
||||||
/* Remove the extra keep-alive reference */
|
|
||||||
if (Handle) ObDereferenceObject(Object);
|
|
||||||
|
|
||||||
/* We can delete the Create Info now */
|
/* We can delete the Create Info now */
|
||||||
ObpFreeAndReleaseCapturedAttributes(ObjectCreateInfo);
|
ObpFreeAndReleaseCapturedAttributes(ObjectCreateInfo);
|
||||||
|
|
||||||
|
|
|
@ -350,7 +350,7 @@ SeSubProcessToken(IN PTOKEN ParentToken,
|
||||||
Status = ObInsertObject(NewToken,
|
Status = ObInsertObject(NewToken,
|
||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
1,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
if (NT_SUCCESS(Status))
|
if (NT_SUCCESS(Status))
|
||||||
|
@ -658,6 +658,8 @@ SepInitializeTokenImplementation(VOID)
|
||||||
RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
|
RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
|
||||||
RtlInitUnicodeString(&Name, L"Token");
|
RtlInitUnicodeString(&Name, L"Token");
|
||||||
ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
|
ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
|
||||||
|
ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
|
||||||
|
ObjectTypeInitializer.SecurityRequired = TRUE;
|
||||||
ObjectTypeInitializer.DefaultPagedPoolCharge = sizeof(TOKEN);
|
ObjectTypeInitializer.DefaultPagedPoolCharge = sizeof(TOKEN);
|
||||||
ObjectTypeInitializer.GenericMapping = SepTokenMapping;
|
ObjectTypeInitializer.GenericMapping = SepTokenMapping;
|
||||||
ObjectTypeInitializer.PoolType = PagedPool;
|
ObjectTypeInitializer.PoolType = PagedPool;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue