Fix RtlWriteRegistryValue, it closed the handle passed to it instead of checking for RTL_REGISTRY_HANDLE flag.

[NTOSKRNL]
Fix PnpRootCreateDevice, which was relying on the broken RtlWriteRegistryValue by aborting, when it *succeeded* to create a registry key, instead of when it failed.
Also use kernel handles and ObCloseHandle.

svn path=/trunk/; revision=61011
This commit is contained in:
Timo Kreuzer 2013-11-16 18:27:26 +00:00
parent 31652fc90f
commit 544b85b8c0
2 changed files with 21 additions and 8 deletions

View file

@ -661,8 +661,13 @@ RtlWriteRegistryValue(IN ULONG RelativeTo,
ValueData,
ValueLength);
/* All went well, close the handle and return status */
ZwClose(KeyHandle);
/* Did the caller pass a key handle? */
if (!(RelativeTo & RTL_REGISTRY_HANDLE))
{
/* We opened the key in RtlpGetRegistryHandle, so close it now */
ZwClose(KeyHandle);
}
return Status;
}

View file

@ -227,9 +227,13 @@ PnpRootCreateDevice(
Status = IopOpenRegistryKeyEx(&EnumHandle, NULL, &EnumKeyName, KEY_READ);
if (NT_SUCCESS(Status))
{
InitializeObjectAttributes(&ObjectAttributes, &Device->DeviceID, OBJ_CASE_INSENSITIVE, EnumHandle, NULL);
InitializeObjectAttributes(&ObjectAttributes,
&Device->DeviceID,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
EnumHandle,
NULL);
Status = ZwCreateKey(&DeviceKeyHandle, KEY_SET_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_VOLATILE, NULL);
ZwClose(EnumHandle);
ObCloseHandle(EnumHandle, KernelMode);
}
if (!NT_SUCCESS(Status))
@ -298,16 +302,20 @@ tryagain:
}
/* Finish creating the instance path in the registry */
InitializeObjectAttributes(&ObjectAttributes, &Device->InstanceID, OBJ_CASE_INSENSITIVE, DeviceKeyHandle, NULL);
InitializeObjectAttributes(&ObjectAttributes,
&Device->InstanceID,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
DeviceKeyHandle,
NULL);
Status = ZwCreateKey(&InstanceKeyHandle, KEY_QUERY_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_VOLATILE, NULL);
if (NT_SUCCESS(Status))
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to create instance path (0x%x)\n", Status);
goto cleanup;
}
/* Just close the handle */
ZwClose(InstanceKeyHandle);
ObCloseHandle(InstanceKeyHandle, KernelMode);
if (FullInstancePath)
{
@ -370,7 +378,7 @@ cleanup:
ExFreePoolWithTag(Device, TAG_PNP_ROOT);
}
if (DeviceKeyHandle != INVALID_HANDLE_VALUE)
ZwClose(DeviceKeyHandle);
ObCloseHandle(DeviceKeyHandle, KernelMode);
return Status;
}