Commit graph

199 commits

Author SHA1 Message Date
Jérôme Gardou 838abc475c [NTOS:IO] Do not ignore RtlDuplicateUnicodeString return value
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou 3f16c8615c [NTOS:IO] Check RtlCreateUnicodeString return value when initializing PnP services
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou 24a4e12a76 [NTOS:IO] Check RtlAnsiStringToUnicodeString return value when initializing Arc names
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou 293f823053 [NTOS:IO] Check RtlAnsiStringToUnicodeString return value when initializing ramdisk
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou c6e9fea844 [NTOSKRNL] Deduplicate some symbols 2021-06-24 18:48:31 +02:00
Hermès Bélusca-Maïto 4864c874a2
[NTOS:IOPNP] Both PNP_PROPERTY_REMOVAL_POLICY_OVERRIDE and PNP_PROPERTY_LOCATION_PATHS are unimplemented, return such status.
Fixes CID 1441387: Uninitialized scalar variable (UNINIT),
in the case of PNP_PROPERTY_LOCATION_PATHS.
2021-06-17 00:35:22 +02:00
Hermès Bélusca-Maïto f2645e48b9
[NTOS:IO] Comment out (and explain why it is there) an unused LdrEntry assignment in IopInitializeBootDrivers(). CID 1237114 2021-06-17 00:35:22 +02:00
Hermès Bélusca-Maïto fe416b67dc
[NTOS:IO] Revert part of commit a82ff90b2: don't do direct ULONG data access: it might be unaligned.
Requested by Victor.
2021-06-17 00:35:21 +02:00
Hermès Bélusca-Maïto 32a82eb123
[NTOS:IO] Fix driverName.Buffer leak in some failure paths in IopGetDriverNames().
driverName.Buffer leaked when the "(!NT_SUCCESS(status) || ServiceName != NULL)"
case is taken because ServiceName != NULL, and some of the functions fail.
2021-06-16 22:18:02 +02:00
Hermès Bélusca-Maïto e09d1dec7a
[NTOS:IO] Fix basicInfo handling in IopGetDriverNames().
- Fix CID 1477246: Uninitialized pointer read (UNINIT) (happens in
  the last ExFreePoolWithTag(basicInfo, TAG_IO) call when the
  "(!NT_SUCCESS(status) || ServiceName != NULL)" case is not taken).

- Centralize all the ExFreePoolWithTag(basicInfo, TAG_IO) cleanups
  at the end of the function.

- Both cases "(driverName.Buffer == NULL)" and "(ServiceName != NULL)"
  can only be taken when basicInfo != NULL, so assert on this fact.
2021-06-16 22:18:02 +02:00
Hermès Bélusca-Maïto 0d28f27156
[NTOS:IO] Fix similar bugs in IopGetDriverNames(), IopInitializeBuiltinDriver() and IopLoadDriver().
- As they are initialized, some registry string values must be NULL-terminated.
- When retrieving REG_DWORD registry values, validate their length.
2021-06-16 22:14:01 +02:00
Hermès Bélusca-Maïto a82ff90b21
[NTOS:IO] Minor code style changes...
- Fix/add comments;
- Reduce indentation level;
- Direct copy for registry integer values;
- Use for-loops for linked lists;
- Use ULONG when the API uses it (sizes for Ob, or REG_DWORD data in registry).
2021-06-16 22:14:01 +02:00
Victor Perevertkin 34593d933b
[FORMATTING][NTOS][HAL][DRIVERS][SDK] Fix trailing spaces 2021-06-11 15:33:08 +03:00
Hermès Bélusca-Maïto 4b4ffa92f5
[NTOS:IO] Modify when 'PartitionBuffer' and how 'DriveLayout' are freed in IopCreateArcNamesDisk().
- Manage the lifetime of the temporary 'PartitionBuffer' buffer where
  it is locally used only, and free it as soon as possible, just after
  calculating the sector checksum. No need to then free it outside of
  the main for-loop.

- When the 'DriveLayout' buffer is freed, ensure the pointer is NULL-ed
  (and assert this at the top of the main for-loop), since it can also
  be freed at cleanup outside this for-loop, and in this case a NULL
  check is performed.
  This will avoid the scenario of possibly double-freeing a pointer,
  in the case the 'DriveLayout' was previously freed (when e.g. reading
  the sector for checksum calculation failed), then the for-loop goes to
  the next disk and stops early.
2021-06-11 02:21:48 +02:00
Hermès Bélusca-Maïto fdd74eb97e
[NTOS:IO/FSTUB] Fix the determination of 'SingleDisk' in IoGetBootDiskInformation().
The purpose of 'SingleDisk' is the same as in the IopCreateArcNames()
function. It is an optimization for that when looking up the
firmware-recognized ARC disks list, in order to match one of these with
the current NT disk being analysed (see e.g. also in IopCreateArcNamesDisk()),
we avoid a possible IopVerifyDiskSignature() call and directly build a
corresponding ARC name NT symbolic link for it.

'SingleDisk' will actually be TRUE, whether the DiskSignatureListHead
list is empty or contains only one element: Indeed in only both these
cases, 'DiskSignatureListHead.Flink->Flink' will refer to the list head.
(If the list is empty but 'SingleDisk' is TRUE, this does not matter,
because the DiskSignatureListHead looking-up loop never starts.)
2021-06-11 02:21:47 +02:00
Hermès Bélusca-Maïto 99078646c3
[NTOS:IO] Avoid hardcoding variable types in sizeofs when possible. 2021-06-11 02:21:47 +02:00
Hermès Bélusca-Maïto 6e65e6b28d
[NTOS:IO] Minor code style fixes (typos; improve comments/DPRINT; IN vs. OUT parameter). 2021-06-11 02:21:47 +02:00
George Bișoc a330b56787
[NTOS:PS] Enable alignment probing for thread/process information classes
In addition to that, here are some stuff done in this commit whilst testing:

- ICIF_QUERY_SIZE_VARIABLE and friends were badly misused, they should be used only when an information class whose information length size is dyanmic and not fixed. By removing such flags from erroneous classes, this fixes the STATUS_INFO_LENGTH_MISMATCH testcases.

- Use CHAR instead of UCHAR for classes that do not need alignment probing, as every other class in the table do, for the sake of consistency.

- ProcessEnableAlignmentFaultFixup uses BOOLEAN as type size, not CHAR. This fixes a testcase failure on ROS.

- Check for information length size before proceeding further on querying the process' cookie information.

- ProcessHandleTracing wants an alignment of a ULONG, not CHAR.

- Move PROCESS_LDT_INFORMATION and PROCESS_LDT_SIZE outside of NTOS_MODE_USER macro case. This fixes a compilation issue when enabling the alignment probing. My mistake of having them inside NTOS_MODE_USER case, sorry.

- On functions like NtQueryInformationThread and the Process equivalent, complete probing is not done at the beginning of the function, complete probing including if the buffer is writable alongside with datatype misalignment check that is. Instead such check is done on each information class case basis. With that said, we have to explicitly tell DefaultQueryInfoBufferCheck if we want a complete probing or not initially.
2021-06-06 17:14:22 +02:00
Jérôme Gardou b0ebf68d98 [NTOS:IO] Be more specific for chasing CORE-17587
Addendum to 42ec1388d7
2021-05-26 11:03:34 +02:00
Jérôme Gardou 42ec1388d7 [NTOS:IO] Break on IoRaiseInformationalHardError
This one will eventually be reverted. For now, this will help debugging CORE-17587
2021-05-26 10:48:29 +02:00
Jérôme Gardou 3adf450867 [REACTOS] Addendum to 5c7ce4475e - Fix MSVC 2015 build
Put data into PAGEDATA or INITDATA sections
Keep section declaration for prototypes

CORE-17540
2021-05-12 11:04:29 +02:00
George Bișoc 207543429b
[NTOSKRNL] Use IQS_SAME instead of ICI_SQ_SAME
And remove the redundant ICI_SQ_SAME macro as it's no longer needed in the codebase.
2021-05-02 21:00:51 +02:00
Jérôme Gardou 662774bca3 [NTOS] Do not force-align an integer value 2021-04-28 13:10:23 +02:00
Eric Kohl d8c38c4b4c [NTOS:PNP] PiSetDevNodeText: Do not overwrite existing DeviceDesc values
CORE-17513
2021-04-05 14:33:48 +02:00
Victor Perevertkin 0fed07b7e4
[NTOS:PNP] Initialize DeviceDesc and LocationInformation registry fields
for manually reported devices, as it is required by the newdev.dll
for installing drivers from INF files

CORE-17212 CORE-17398

Co-authored-by: Stanislav Motylkov <x86corez@gmail.com>
2021-03-19 07:57:41 +03:00
Victor Perevertkin aec3d9cc8f
[NTOS:IO][NTOS:PNP] Fix incorrect usage of IopGetRegistryValue
KEY_VALUE_FULL_INFORMATION was not always freed properly
2021-03-19 01:07:22 +03:00
Victor Perevertkin 59a5dba443
[NTOS:PNP] Implement PlugPlayControlStartDevice control class
This control class is triggered when a driver is being installed for a
non-critical device. The driver info should already be in the registry
so we just need to push the device through the state graph

Meanwhile, combine the code for similar control classes into
PiControlSyncDeviceAction routine

CORE-17463 CORE-17490
2021-03-16 03:17:57 +03:00
Victor Perevertkin 029accdcf7
[NDK] Change the data structure for PlugPlayControlResetDevice control class
PlugPlayControlResetDevice shares the input structure with several other
control classes.
Source: ProcessHacker sources e9c8121f41/ntpnpapi.h
2021-03-16 03:17:42 +03:00
Jérôme Gardou 2d3454a809 [NTOS:IO] VFAT sucks less now 2021-02-03 09:41:22 +01:00
Victor Perevertkin 91fceab36e
[NTOS:IO][NTOS:PNP] Add PiActionAddBootDevices device action
During the boot process, it makes possible to initalize the driver's
devices right after the driver is loaded. Moreover, this way one can be
sure that all critical devices are initialized before the
IopMarkBootPartition call (because we explicitly call the driver's
AddDevice routine now, after each driver is loaded)

CORE-7826
2021-01-27 05:15:16 +03:00
Victor Perevertkin 798fc13b48
[NTOS:PNP] Implement NT5.2-like DEVICE_NODE state management
- Use DeviceNode->State field and its values, instead of
  DeviceNode->Flags for tracking current node state
- Change DNF_* flags to the ones compatible with Windows XP+
- Simplify state changes for device nodes and encapsulate all the logic
  inside the PiDevNodeStateMachine routine. This makes the ground for
  future improvements in the device removal sequence and
  resource management
- Now values inside DeviceNode->State and ->Flags are compatible with
  the windbg !devnode macro and can be tracked using it
- BUGFIX: fixed cases where IRP_MN_START_DEVICE or
  IRP_MN_QUERY_DEVICE_RELATIONS may be sent to a device after a
  IRP_MN_REMOVE_DEVICE

CORE-7826
2021-01-27 05:15:15 +03:00
Victor Perevertkin b704292808
[NTOS:IO] Add more enumeration requests during the boot process
This is to ensure that all needed devices are initialized during the
early boot

CORE-7826
2021-01-27 05:15:15 +03:00
Victor Perevertkin e5254974d2
[NTOS:IO] Start loading drivers from the disk only after SystemRoot is initialized
Add another PnPBootDriversInitialized variable to indicate a point where
both disk subsystem and SystemRoot symlink are initialized, and use it
in a PiCallDriverAddDevice call.
2021-01-04 16:50:33 +03:00
Victor Perevertkin c4c0585f96
[NTOS:IO][NTOS:PNP] Implement PiCallDriverAddDevice
- Move the driver's name obtaining logic into the IopGetDriverNames
  function
- Create a new PiCallDriverAddDevice instead of PipCallDriverAddDevice
  and move it to pnpmgr/devaction.c file. Move around all its internal
  helpers too
- Support a proper Windows-compatible driver loading order for a PDO
  (lower filters, main service, upper filters, etc.)
- Set a correct Problem for the DeviceNode, in case of an error during
  driver loading
- Check the Start Type for all drivers before loading
- Do not try to load drivers during the early boot stage when there is
  no disk subsystem initialized
2021-01-04 16:50:33 +03:00
Victor Perevertkin 4c95339da0
[NTOS:IO] Refactoring of the driver initialization code (2)
- Do not hold the IopDriverLoadResource while trying to reference a
  driver object (but still acquire it when we actually need to load a
  driver)
- Change IopLoadDriver and IopInitializeDriverModule to use registry
  handle instead of a service name string and/or full registry path
- Do not try to reference a driver object inside IopLoadDriver. It's
  supposed to be done before the function call
2021-01-04 16:50:33 +03:00
Victor Perevertkin a6a3aa0f0d
[NTOS:IO] Refactor IopLoadUnloadDriver
- Split IopLoadUnloadDriver into IopLoadDriver and calling DriverUnload
- Schedule the worker for (un)loading driver in a separate routine
  (IopDoLoadUnloadDriver) this allows IopLoadDriver to be called
  separately (if we are sure that we're in the system process)
2021-01-04 16:50:32 +03:00
Victor Perevertkin e18a32df3a
[NTOS:IO] Refactoring of the driver initialization code
- Remove IopCreateDriver and put its code into IoCreateDriver and
  IopInitializeDriverModule. It's hard to extract a meaningful common
  part from it
- Refactor IopInitializeDriverModule. Extend and put the DriverName
  generation logic into it. Now this function frees the ModuleObject in
  case of failure and returns STATUS_FAILED_DRIVER_ENTRY in case of
  DriverInit failure (will be used later)
2021-01-04 16:50:32 +03:00
Victor Perevertkin 6f0e37b042
[NTOS:PNP][NTOS:IO] Do not create a device object + node on every driver load
- Remove the usage of IopCreateDeviceNode and change it to
  PipAllocateDeviceNode where required
2021-01-04 16:50:32 +03:00
Victor Perevertkin 8ee88d3bd5
[NTOS:PNP] Send removal IRPs to a file system device object for mounted devices
If a DeviceObject has VPB attached, it should be treated in a special way

CORE-16106
2020-12-27 18:40:33 +03:00
Hermès Bélusca-Maïto a748350fc9
[NTOS:IO] Fail if the driver name passed to NtLoadDriver() is an empty string.
Otherwise an assertion on the driver name is hit later on.
Can be reproduced by calling NtLoadDriver with a valid UNICODE_STRING
of Length == 0.
2020-12-27 00:52:00 +01:00
Hermès Bélusca-Maïto 44511f0809
[NTOS:IO] Minor formatting only.
Making IopLoadUnloadDriver() looking similar to IopUnloadDriver().
2020-12-27 00:51:59 +01:00
Jérôme Gardou ef4c7ae978 [NTOS:IO] Validate input parameters in NtQueryDirectoryFile
It turns out this is not the job of the FS driver
2020-12-22 11:06:38 +01:00
Jérôme Gardou 1d1dba51db [NTOS:IO] Do not set Shared property of the file if we are failing in IoCheckShareAccess 2020-12-22 11:05:00 +01:00
Jérôme Gardou a6c0af2e21 [NTOS:IO] Do not pass bogus file offset to the FS in NtReadFile & NtWriteFile 2020-12-22 11:02:33 +01:00
Victor Perevertkin 582ca68696
[NTOS:PNP] Improve and refactor PnP notifications
- BUGFIX: do not call IoGetRelatedTargetDevice while guarded mutex is acquired
  (the function issues an APC, but they are disabled inside a critical section)
- BUGFIX: only the beginning of a structure for GUID_PNP_CUSTOM_NOTIFICATION was copied and queued.
  Just pass it as-is to a subscriber, without copying
- Don't convert event GUID to string, store and compare GUID struct itself
- Split IopNotifyPlugPlayNotification into 3 functions for each type of notification
  (less stack usage and for future changes)
- Move initialization code for notifications into a separate routine
- Use separate lists and locks for every type of notification
- Put "TargetDeviceChange" notifications into their place inside DEVICE_NODE
2020-12-05 22:25:40 +03:00
Victor Perevertkin e3198fb644
[NTOS:PNP] Check if APCs are enabled before waiting inside IopSynchronousCall 2020-12-05 22:25:39 +03:00
Thomas Faber 828d5fa93e
[NTOS:IO] Reduce stack usage in IopLoadServiceModule. CORE-17215 2020-11-27 12:44:35 +01:00
Thomas Faber ae1d272add
[NTOS:PNP] Avoid recursion in IopTraverseDeviceTree(Node). CORE-17215 2020-11-27 10:31:41 +01:00
Hervé Poussineau 129e009a2c [NTOS:IO] Do not translate resources of type CmResourceTypeDevicePrivate
CmResourceTypeDevicePrivate resources are created the the bus driver, for its own later use,
when children devices will receive the IRP_MN_START_DEVICE.

Do not translate them, as they have no meaning outside bus driver.
2020-11-15 18:38:37 +01:00
Victor Perevertkin d6ef8f97e9
[NTOS:PNP] Enumerate the device tree after loading boot drivers and HAL 2020-11-10 01:59:49 +03:00