https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1fd730b78115ca0e55335a...
commit 1fd730b78115ca0e55335a0204061c83e48e53c3 Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Fri Jun 11 01:30:40 2021 +0200 Commit: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org CommitDate: Sun Sep 5 20:31:08 2021 +0200
[NTOS:IO] IopInitializeDriverModule(): Set the DRVO_LEGACY_DRIVER flag if the driver is not WDM. (#3749) --- ntoskrnl/io/iomgr/driver.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/ntoskrnl/io/iomgr/driver.c b/ntoskrnl/io/iomgr/driver.c index a5ab9904bb4..eb3817b98ec 100644 --- a/ntoskrnl/io/iomgr/driver.c +++ b/ntoskrnl/io/iomgr/driver.c @@ -447,6 +447,16 @@ IopInitializeDriverModule(
DPRINT("Driver name: '%wZ'\n", &DriverName);
+ /* + * Retrieve the driver's PE image NT header and perform some sanity checks. + * NOTE: We suppose that since the driver has been successfully loaded, + * its NT and optional headers are all valid and have expected sizes. + */ + PIMAGE_NT_HEADERS NtHeaders = RtlImageNtHeader(ModuleObject->DllBase); + ASSERT(NtHeaders); + ASSERT(ModuleObject->SizeOfImage == NtHeaders->OptionalHeader.SizeOfImage); + ASSERT(ModuleObject->EntryPoint == RVA(ModuleObject->DllBase, NtHeaders->OptionalHeader.AddressOfEntryPoint)); + /* Obtain the registry path for the DriverInit routine */ PKEY_NAME_INFORMATION nameInfo; ULONG infoLength; @@ -524,7 +534,11 @@ IopInitializeDriverModule( RtlZeroMemory(driverObject, ObjectSize); driverObject->Type = IO_TYPE_DRIVER; driverObject->Size = sizeof(DRIVER_OBJECT); - driverObject->Flags = DRVO_LEGACY_DRIVER; // TODO: check the WDM_DRIVER flag on the module + + /* Set the legacy flag if this is not a WDM driver */ + if (!(NtHeaders->OptionalHeader.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_WDM_DRIVER)) + driverObject->Flags |= DRVO_LEGACY_DRIVER; + driverObject->DriverSection = ModuleObject; driverObject->DriverStart = ModuleObject->DllBase; driverObject->DriverSize = ModuleObject->SizeOfImage;