From: Jérôme Gardou Date: Tue, 8 Jul 2014 18:42:20 +0000 (+0000) Subject: [NTOSKRNL] X-Git-Tag: backups/0.3.17@66124~911 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=3eaff9c2bcf0c8d0d079904a9d3a7ed9a2da1fd0 [NTOSKRNL] - Use ZwSetValueKey instead of NtSetValueKey - Properly probe and copy parameters when NtSetValueKey is called from UMode CORE-7738 #resolve #comment fixed in r63700 svn path=/trunk/; revision=63700 --- diff --git a/reactos/ntoskrnl/config/cmconfig.c b/reactos/ntoskrnl/config/cmconfig.c index a0f66ac9a7a..95ddcbe6802 100644 --- a/reactos/ntoskrnl/config/cmconfig.c +++ b/reactos/ntoskrnl/config/cmconfig.c @@ -97,7 +97,7 @@ CmpInitializeRegistryNode(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry, /* Setup the component information key */ RtlInitUnicodeString(&ValueName, L"Component Information"); - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_BINARY, @@ -124,7 +124,7 @@ CmpInitializeRegistryNode(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry, if (NT_SUCCESS(Status)) { /* Save the identifier in the registry */ - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, @@ -178,7 +178,7 @@ CmpInitializeRegistryNode(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry, CmpConfigurationData->BusNumber = BusNumber; /* Save the actual data */ - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_FULL_RESOURCE_DESCRIPTOR, diff --git a/reactos/ntoskrnl/config/cmsysini.c b/reactos/ntoskrnl/config/cmsysini.c index f41d27b042c..954e3488715 100644 --- a/reactos/ntoskrnl/config/cmsysini.c +++ b/reactos/ntoskrnl/config/cmsysini.c @@ -416,7 +416,7 @@ CmpSetSystemValues(IN PLOADER_PARAMETER_BLOCK LoaderBlock) /* Key opened, now write to the key */ RtlInitUnicodeString(&KeyName, L"SystemStartOptions"); - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &KeyName, 0, REG_SZ, @@ -427,7 +427,7 @@ CmpSetSystemValues(IN PLOADER_PARAMETER_BLOCK LoaderBlock) /* Setup value name for system boot device in ARC format */ RtlInitUnicodeString(&KeyName, L"SystemBootDevice"); RtlCreateUnicodeStringFromAsciiz(&ValueName, LoaderBlock->ArcBootDeviceName); - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &KeyName, 0, REG_SZ, @@ -474,7 +474,7 @@ CmpCreateControlSet(IN PLOADER_PARAMETER_BLOCK LoaderBlock) OBJ_CASE_INSENSITIVE, NULL, NULL); - Status = NtOpenKey(&SelectHandle, KEY_READ, &ObjectAttributes); + Status = ZwOpenKey(&SelectHandle, KEY_READ, &ObjectAttributes); if (!NT_SUCCESS(Status)) { /* ReactOS Hack: Hard-code current to 001 for SetupLdr */ @@ -488,16 +488,17 @@ CmpCreateControlSet(IN PLOADER_PARAMETER_BLOCK LoaderBlock) OBJ_CASE_INSENSITIVE, NULL, NULL); - Status = NtCreateKey(&KeyHandle, + Status = ZwCreateKey(&KeyHandle, KEY_ALL_ACCESS, &ObjectAttributes, 0, NULL, 0, &Disposition); - if (!NT_SUCCESS(Status)) return Status; + if (!NT_SUCCESS(Status)) + return Status; - /* Don't need the handle */ + /* We don't need the handle */ ZwClose(KeyHandle); /* Use hard-coded setting */ @@ -533,7 +534,7 @@ UseSet: OBJ_CASE_INSENSITIVE, NULL, NULL); - Status = NtCreateKey(&KeyHandle, + Status = ZwCreateKey(&KeyHandle, KEY_CREATE_LINK, &ObjectAttributes, 0, @@ -557,7 +558,7 @@ UseSet: Status = RtlAnsiStringToUnicodeString(&KeyName, &TempString, FALSE); /* Set the value */ - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &CmSymbolicLinkValueName, 0, REG_LINK, @@ -572,7 +573,7 @@ UseSet: KeyHandle, NULL); Status = NtOpenKey(&ConfigHandle, KEY_READ, &ObjectAttributes); - NtClose(KeyHandle); + ZwClose(KeyHandle); /* Check if we don't have one */ if (!NT_SUCCESS(Status)) @@ -689,7 +690,7 @@ UseSet: ASSERT(STATUS_SUCCESS == Status); /* Set it */ - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &CmSymbolicLinkValueName, 0, REG_LINK, @@ -2180,7 +2181,7 @@ CmpSetVersionData(VOID) RtlInitUnicodeString(&ValueData, Buffer); - NtSetValueKey(CurrentVersionKeyHandle, + ZwSetValueKey(CurrentVersionKeyHandle, &ValueName, 0, REG_SZ, diff --git a/reactos/ntoskrnl/config/i386/cmhardwr.c b/reactos/ntoskrnl/config/i386/cmhardwr.c index cb8d7e8938d..1da455763af 100644 --- a/reactos/ntoskrnl/config/i386/cmhardwr.c +++ b/reactos/ntoskrnl/config/i386/cmhardwr.c @@ -268,7 +268,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Set the value */ RtlInitUnicodeString(&ValueName, L"PhysicalAddressExtension"); - NtSetValueKey(KeyHandle, + ZwSetValueKey(KeyHandle, &ValueName, 0, REG_DWORD, @@ -463,7 +463,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Add it to the registry */ RtlInitUnicodeString(&ValueName, L"ProcessorNameString"); - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, @@ -486,7 +486,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Add it to the registry */ RtlInitUnicodeString(&ValueName, L"VendorIdentifier"); - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, @@ -502,7 +502,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc { /* Add them to the registry */ RtlInitUnicodeString(&ValueName, L"FeatureSet"); - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_DWORD, @@ -515,7 +515,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc { /* Add it to the registry */ RtlInitUnicodeString(&ValueName, L"~MHz"); - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_DWORD, @@ -528,7 +528,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc { /* Add it to the registry */ RtlInitUnicodeString(&ValueName, L"Update Signature"); - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_BINARY, @@ -621,7 +621,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Write the date into the registry */ RtlInitUnicodeString(&ValueName, L"SystemBiosDate"); - Status = NtSetValueKey(SystemHandle, + Status = ZwSetValueKey(SystemHandle, &ValueName, 0, REG_SZ, @@ -643,7 +643,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc if (NT_SUCCESS(Status)) { /* Save it to the registry */ - Status = NtSetValueKey(BiosHandle, + Status = ZwSetValueKey(BiosHandle, &ValueName, 0, REG_SZ, @@ -703,7 +703,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Write the BIOS Version to the registry */ RtlInitUnicodeString(&ValueName, L"SystemBiosVersion"); - Status = NtSetValueKey(SystemHandle, + Status = ZwSetValueKey(SystemHandle, &ValueName, 0, REG_MULTI_SZ, @@ -746,7 +746,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Write the date into the registry */ RtlInitUnicodeString(&ValueName, L"VideoBiosDate"); - Status = NtSetValueKey(SystemHandle, + Status = ZwSetValueKey(SystemHandle, &ValueName, 0, REG_SZ, @@ -801,7 +801,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Write the BIOS Version to the registry */ RtlInitUnicodeString(&ValueName, L"VideoBiosVersion"); - Status = NtSetValueKey(SystemHandle, + Status = ZwSetValueKey(SystemHandle, &ValueName, 0, REG_MULTI_SZ, diff --git a/reactos/ntoskrnl/config/ntapi.c b/reactos/ntoskrnl/config/ntapi.c index b3bf0ece98d..bc89d22c4d7 100644 --- a/reactos/ntoskrnl/config/ntapi.c +++ b/reactos/ntoskrnl/config/ntapi.c @@ -33,7 +33,10 @@ NtCreateKey(OUT PHANDLE KeyHandle, CM_PARSE_CONTEXT ParseContext = {0}; HANDLE Handle; PAGED_CODE(); - DPRINT("NtCreateKey(OB name %wZ)\n", ObjectAttributes->ObjectName); + + DPRINT("NtCreateKey(Path: %wZ, Root %x, Access: %x, CreateOptions %x)\n", + ObjectAttributes->ObjectName, ObjectAttributes->RootDirectory, + DesiredAccess, CreateOptions); /* Check for user-mode caller */ if (PreviousMode != KernelMode) @@ -60,7 +63,8 @@ NtCreateKey(OUT PHANDLE KeyHandle, sizeof(OBJECT_ATTRIBUTES), sizeof(ULONG)); - if (Disposition) ProbeForWriteUlong(Disposition); + if (Disposition) + ProbeForWriteUlong(Disposition); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { @@ -101,6 +105,8 @@ NtCreateKey(OUT PHANDLE KeyHandle, } _SEH2_END; + DPRINT("Returning handle %x, Status %x.\n", Handle, Status); + /* Return status */ return Status; } @@ -116,7 +122,8 @@ NtOpenKey(OUT PHANDLE KeyHandle, NTSTATUS Status; KPROCESSOR_MODE PreviousMode = ExGetPreviousMode(); PAGED_CODE(); - DPRINT("NtOpenKey(OB 0x%wZ)\n", ObjectAttributes->ObjectName); + DPRINT("NtOpenKey(Path: %wZ, Root %x, Access: %x)\n", + ObjectAttributes->ObjectName, ObjectAttributes->RootDirectory, DesiredAccess); /* Check for user-mode caller */ if (PreviousMode != KernelMode) @@ -166,6 +173,8 @@ NtOpenKey(OUT PHANDLE KeyHandle, _SEH2_END; } + DPRINT("Returning handle %x, Status %x.\n", Handle, Status); + /* Return status */ return Status; } @@ -301,6 +310,7 @@ NtEnumerateKey(IN HANDLE KeyHandle, /* Dereference and return status */ ObDereferenceObject(KeyObject); + DPRINT("Returning status %x.\n", Status); return Status; } @@ -604,14 +614,52 @@ NtSetValueKey(IN HANDLE KeyHandle, IN PVOID Data, IN ULONG DataSize) { - NTSTATUS Status; - PCM_KEY_BODY KeyObject; + NTSTATUS Status = STATUS_SUCCESS; + PCM_KEY_BODY KeyObject = NULL; REG_SET_VALUE_KEY_INFORMATION SetValueKeyInfo; REG_POST_OPERATION_INFORMATION PostOperationInfo; - UNICODE_STRING ValueNameCopy = *ValueName; + UNICODE_STRING ValueNameCopy; + KPROCESSOR_MODE PreviousMode; + PAGED_CODE(); + + PreviousMode = ExGetPreviousMode(); + + if (Data && !DataSize) + return STATUS_INVALID_PARAMETER; + + /* Probe and copy the data */ + if ((PreviousMode != KernelMode) && Data) + { + PVOID DataCopy = ExAllocatePoolWithTag(PagedPool, DataSize, TAG_CM); + if (!DataCopy) + return STATUS_NO_MEMORY; + _SEH2_TRY + { + ProbeForRead(Data, DataSize, 1); + RtlCopyMemory(DataCopy, Data, DataSize); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + Status = _SEH2_GetExceptionCode(); + } + _SEH2_END; + + if (!NT_SUCCESS(Status)) + { + ExFreePoolWithTag(DataCopy, TAG_CM); + return Status; + } + Data = DataCopy; + } + + /* Capture the string */ + Status = ProbeAndCaptureUnicodeString(&ValueNameCopy, PreviousMode, ValueName); + if (!NT_SUCCESS(Status)) + goto end; + DPRINT("NtSetValueKey() KH 0x%p, VN '%wZ', TI %x, T %lu, DS %lu\n", - KeyHandle, ValueName, TitleIndex, Type, DataSize); + KeyHandle, &ValueNameCopy, TitleIndex, Type, DataSize); /* Verify that the handle is valid and is a registry key */ Status = ObReferenceObjectByHandle(KeyHandle, @@ -620,7 +668,8 @@ NtSetValueKey(IN HANDLE KeyHandle, ExGetPreviousMode(), (PVOID*)&KeyObject, NULL); - if (!NT_SUCCESS(Status)) return Status; + if (!NT_SUCCESS(Status)) + goto end; /* Make sure the name is aligned, not too long, and the data under 4GB */ if ( (ValueNameCopy.Length > 32767) || @@ -628,8 +677,8 @@ NtSetValueKey(IN HANDLE KeyHandle, (DataSize > 0x80000000)) { /* Fail */ - ObDereferenceObject(KeyObject); - return STATUS_INVALID_PARAMETER; + Status = STATUS_INVALID_PARAMETER; + goto end; } /* Ignore any null characters at the end */ @@ -644,14 +693,14 @@ NtSetValueKey(IN HANDLE KeyHandle, if (KeyObject->KeyControlBlock->ExtFlags & CM_KCB_READ_ONLY_KEY) { /* Fail */ - ObDereferenceObject(KeyObject); - return STATUS_ACCESS_DENIED; + Status = STATUS_ACCESS_DENIED; + goto end; } /* Setup callback */ PostOperationInfo.Object = (PVOID)KeyObject; SetValueKeyInfo.Object = (PVOID)KeyObject; - SetValueKeyInfo.ValueName = ValueName; + SetValueKeyInfo.ValueName = &ValueNameCopy; SetValueKeyInfo.TitleIndex = TitleIndex; SetValueKeyInfo.Type = Type; SetValueKeyInfo.Data = Data; @@ -673,8 +722,13 @@ NtSetValueKey(IN HANDLE KeyHandle, PostOperationInfo.Status = Status; CmiCallRegisteredCallbacks(RegNtPostSetValueKey, &PostOperationInfo); +end: /* Dereference and return status */ - ObDereferenceObject(KeyObject); + if (KeyObject) + ObDereferenceObject(KeyObject); + ReleaseCapturedUnicodeString(&ValueNameCopy, PreviousMode); + if ((PreviousMode != KernelMode) && Data) + ExFreePoolWithTag(Data, TAG_CM); return Status; } diff --git a/reactos/ntoskrnl/config/powerpc/cmhardwr.c b/reactos/ntoskrnl/config/powerpc/cmhardwr.c index f034f537433..84b7d912630 100644 --- a/reactos/ntoskrnl/config/powerpc/cmhardwr.c +++ b/reactos/ntoskrnl/config/powerpc/cmhardwr.c @@ -267,7 +267,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Set the value */ RtlInitUnicodeString(&ValueName, L"PhysicalAddressExtension"); - NtSetValueKey(KeyHandle, + ZwSetValueKey(KeyHandle, &ValueName, 0, REG_DWORD, @@ -465,7 +465,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Add it to the registry */ RtlInitUnicodeString(&ValueName, L"ProcessorNameString"); - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, @@ -488,7 +488,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Add it to the registry */ RtlInitUnicodeString(&ValueName, L"VendorIdentifier"); - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, @@ -504,7 +504,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc { /* Add them to the registry */ RtlInitUnicodeString(&ValueName, L"FeatureSet"); - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_DWORD, @@ -517,7 +517,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc { /* Add it to the registry */ RtlInitUnicodeString(&ValueName, L"~MHz"); - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_DWORD, @@ -530,7 +530,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc { /* Add it to the registry */ RtlInitUnicodeString(&ValueName, L"Update Signature"); - Status = NtSetValueKey(KeyHandle, + Status = ZwSetValueKey(KeyHandle, &ValueName, 0, REG_BINARY, @@ -623,7 +623,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Write the date into the registry */ RtlInitUnicodeString(&ValueName, L"SystemBiosDate"); - Status = NtSetValueKey(SystemHandle, + Status = ZwSetValueKey(SystemHandle, &ValueName, 0, REG_SZ, @@ -645,7 +645,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc if (NT_SUCCESS(Status)) { /* Save it to the registry */ - Status = NtSetValueKey(BiosHandle, + Status = ZwSetValueKey(BiosHandle, &ValueName, 0, REG_SZ, @@ -705,7 +705,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Write the BIOS Version to the registry */ RtlInitUnicodeString(&ValueName, L"SystemBiosVersion"); - Status = NtSetValueKey(SystemHandle, + Status = ZwSetValueKey(SystemHandle, &ValueName, 0, REG_MULTI_SZ, @@ -749,7 +749,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Write the date into the registry */ RtlInitUnicodeString(&ValueName, L"VideoBiosDate"); - Status = NtSetValueKey(SystemHandle, + Status = ZwSetValueKey(SystemHandle, &ValueName, 0, REG_SZ, @@ -804,7 +804,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc /* Write the BIOS Version to the registry */ RtlInitUnicodeString(&ValueName, L"VideoBiosVersion"); - Status = NtSetValueKey(SystemHandle, + Status = ZwSetValueKey(SystemHandle, &ValueName, 0, REG_MULTI_SZ, diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index 04f8e785d10..519f8400bf1 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -1853,7 +1853,7 @@ Phase1InitializationDiscard(IN PVOID Context) { /* Write the safe boot type */ RtlInitUnicodeString(&KeyName, L"OptionValue"); - NtSetValueKey(OptionHandle, + ZwSetValueKey(OptionHandle, &KeyName, 0, REG_DWORD, @@ -1866,7 +1866,7 @@ Phase1InitializationDiscard(IN PVOID Context) /* Remember this for later */ Disposition = TRUE; RtlInitUnicodeString(&KeyName, L"UseAlternateShell"); - NtSetValueKey(OptionHandle, + ZwSetValueKey(OptionHandle, &KeyName, 0, REG_DWORD, diff --git a/reactos/ntoskrnl/io/iomgr/bootlog.c b/reactos/ntoskrnl/io/iomgr/bootlog.c index bb2d8adfbd1..8fb20b81c5d 100644 --- a/reactos/ntoskrnl/io/iomgr/bootlog.c +++ b/reactos/ntoskrnl/io/iomgr/bootlog.c @@ -135,7 +135,7 @@ IopBootLog(PUNICODE_STRING DriverName, if (!NT_SUCCESS(Status)) { - DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); + DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status); } else {