Use IoOpenDriverRegistryKey to avoid opening an absolute registry path.
Driver Verifier can detect registry isolation violations when running WHQL
tests on Server 2025. The rule states that a driver may not open an absolute
registry key path. Use the specific API to open the 'Parameters' key with
KEY_READ when querying settings.
Signed-off-by: Owen Smith <owen.smith@cloud.com>
Cosmetic fix-up.
Signed-off-by: Paul Durrant <pdurrant@amazon.com>
#define REGISTRY_TAG 'GERX'
+static PDRIVER_OBJECT RegistryDriverObject;
static UNICODE_STRING RegistryPath;
static FORCEINLINE PVOID
NTSTATUS
RegistryInitialize(
- IN PUNICODE_STRING Path
+ IN PDRIVER_OBJECT DriverObject,
+ IN PUNICODE_STRING Path
)
{
NTSTATUS status;
if (!NT_SUCCESS(status))
goto fail1;
+ ASSERT3P(RegistryDriverObject, ==, NULL);
+ RegistryDriverObject = DriverObject;
+
return STATUS_SUCCESS;
fail1:
VOID
)
{
+ RegistryDriverObject = NULL;
+
RtlFreeUnicodeString(&RegistryPath);
RegistryPath.Buffer = NULL;
RegistryPath.MaximumLength = RegistryPath.Length = 0;
}
+NTSTATUS
+RegistryOpenParametersKey(
+ IN ACCESS_MASK DesiredAccess,
+ OUT PHANDLE Key
+ )
+{
+ return IoOpenDriverRegistryKey(RegistryDriverObject,
+ DriverRegKeyParameters,
+ DesiredAccess,
+ 0,
+ Key);
+}
+
NTSTATUS
RegistryOpenKey(
IN HANDLE Parent,
extern NTSTATUS
RegistryInitialize(
- IN PUNICODE_STRING Path
+ IN PDRIVER_OBJECT DrvObj,
+ IN PUNICODE_STRING Path
);
extern VOID
VOID
);
+extern NTSTATUS
+RegistryOpenParametersKey(
+ IN ACCESS_MASK DesiredAccess,
+ OUT PHANDLE Key
+ );
+
extern NTSTATUS
RegistryOpenKey(
IN HANDLE Parent,
if (!NT_SUCCESS(status))
goto fail1;
- status = RegistryInitialize(RegistryPath);
+ status = RegistryInitialize(NULL, RegistryPath);
if (!NT_SUCCESS(status))
goto fail2;
IN PUNICODE_STRING RegistryPath
)
{
- HANDLE ServiceKey;
HANDLE ParametersKey;
ULONG Index;
LOG_LEVEL LogLevel;
MONTH,
YEAR);
- status = RegistryInitialize(RegistryPath);
+ status = RegistryInitialize(DriverObject, RegistryPath);
if (!NT_SUCCESS(status))
goto fail1;
- status = RegistryOpenServiceKey(KEY_READ, &ServiceKey);
+ status = RegistryOpenParametersKey(KEY_READ, &ParametersKey);
if (!NT_SUCCESS(status))
goto fail2;
- status = RegistryOpenSubKey(ServiceKey,
- "Parameters",
- KEY_READ,
- &ParametersKey);
- if (!NT_SUCCESS(status))
- goto fail3;
-
__DriverSetParametersKey(ParametersKey);
status = LogReadLogLevel(ParametersKey,
__DriverSetConsoleLogLevel(LogLevel);
- RegistryCloseKey(ServiceKey);
-
status = XenTouch(__MODULE__,
MAJOR_VERSION,
MINOR_VERSION,
return STATUS_SUCCESS;
-fail3:
- Error("fail3\n");
-
- RegistryCloseKey(ServiceKey);
-
fail2:
Error("fail2\n");
return __DriverGetDriverObject();
}
-static FORCEINLINE NTSTATUS
-__DriverOpenParametersKey(
- OUT PHANDLE ParametersKey
- )
-{
- HANDLE ServiceKey;
- NTSTATUS status;
-
- status = RegistryOpenServiceKey(KEY_READ, &ServiceKey);
- if (!NT_SUCCESS(status))
- goto fail1;
-
- status = RegistryOpenSubKey(ServiceKey, "Parameters", KEY_READ, ParametersKey);
- if (!NT_SUCCESS(status))
- goto fail2;
-
- RegistryCloseKey(ServiceKey);
-
- return STATUS_SUCCESS;
-
-fail2:
- RegistryCloseKey(ServiceKey);
-
-fail1:
- return status;
-}
-
static FORCEINLINE VOID
__DriverSetEmulatedContext(
IN PXENFILT_EMULATED_CONTEXT Context
ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
- status = __DriverOpenParametersKey(&ParametersKey);
+ status = RegistryOpenParametersKey(KEY_READ, &ParametersKey);
if (!NT_SUCCESS(status))
goto fail1;
ULONG Index;
NTSTATUS status;
- status = __DriverOpenParametersKey(&ParametersKey);
+ status = RegistryOpenParametersKey(KEY_READ, &ParametersKey);
if (!NT_SUCCESS(status))
goto fail1;
if (!NT_SUCCESS(status))
goto done;
- status = RegistryInitialize(RegistryPath);
+ status = RegistryInitialize(DriverObject, RegistryPath);
if (!NT_SUCCESS(status))
goto fail1;