Commit graph

187 commits

Author SHA1 Message Date
Nguyen Trung Khanh 37c63770d7
[NTOS:IO] Fix pool memory disclosure in IopQueueTargetDeviceEvent (#2966) 2020-07-04 15:41:18 +02:00
Victor Perevertkin 21e9e2baa5
[NTOS:IO] Move device manipulation functions from pnpmgr/pnpmgr.c to pnpmgr/devaction.c
And rearrange them in more logical order.

This effectively splits the file, leaving public "Io" functions in
pnpmgr.c along with some things not related do device object management.
Functions which manipulate the device tree are left in devaction.c.
In future all these functions will only be accessed from
DeviceActionWorker.
While being public API, IoRequestDeviceEject and IoInvalidateDeviceState
have been moved to devaction.c as well. In next commits they will be
converted to DeviceActionWorker routines and their callers will be put
in pnpmgr.c
2020-06-24 04:03:35 +03:00
Victor Perevertkin b5815efe83
[NTOS:IO] Move device node functions from pnpmgr/pnpmgr.c to pnpmgr/devnode.c
Add SAL2 annotations to functions while moving
Convert IopCreateDeviceNode description to a Doxygen format
2020-06-21 09:39:13 +03:00
Serge Gautherie b20f815126
[NTOSKRNL] Place INIT_FUNCTION before the return type (#2823)
(but after 'static' or SAL 2 annotation.)
Follow-up to 71fefa32, which mentions that it's actually required by the compiler in some circumstances.
2020-05-23 15:56:10 +02:00
Thomas Faber c60d25fb26
[NTOS:PNP] Directly accept a UNICODE_STRING in LocateChildDevice. CORE-15882 2020-05-17 20:56:16 +02:00
Thomas Faber 2242ca6920
[NTOS:PNP] Avoid an unnecessary stack buffer in PnpRootCreateDevice. CORE-15882 2020-05-17 20:56:16 +02:00
Thomas Faber 1b0fe76d0d
[NTOS:PNP] Avoid an unnecessary stack buffer in EnumerateDevices. CORE-15882 2020-05-17 20:56:16 +02:00
Thomas Faber ac52401d74
[NTOS:PNP] Move child device creation into its own function
Also fix some leaks and a DPRINT format string.
2020-05-17 20:56:11 +02:00
Timo Kreuzer b82bf8ce16
[NTOS:IO] Fix parsing of resource lists
Also add a hack to avoid failing on now occurring resource conflict detection and try to fix at least one resource in ACPI hal.

CORE-10146
CORE-12892
2020-04-24 13:58:09 +03:00
Vadim Galyant 374f2b4d98
[NTOS][SDK:LIB] Add a Resources Arbiter library, to be used by bus drivers (acpi, pci), kernel and legacy hal (PIC HAL). (#2471) 2020-04-09 19:41:11 +02:00
Vadim Galyant 7db342f8a1
[NTOS:PNP] Add set functions for debugging PNP and IO managers. (#2457)
Useful functions for debugging IO and PNP managers:

PipDumpDeviceNodes() - displays information about a node(s) in the device tree;
PipDumpResourceRequirementsList() - displays information about a Io List;
PipDumpCmResourceList() - displays information about a Cm List

The tree list of devices (DEVICE_NODE structures) is perhaps the main one in the PnP manager. They also store information about the hardware resources required and assigned to devices.
These functions can help with debugging. For example, you can call PipDumpDeviceNodes() before and after device enumeration and compare the resulting information.

For PipDumpDeviceNodes() it is possible to optionally output:
- allocated resources and boot configuration resources
- resources required
- translated resources
It is possible to displays both a single node and the entire tree.
Optionally, you can display child nodes.

The information output format for resource lists is maximally compressed, since often the only debugging port is a monitor.

The DebugLevel parameter allows dumping in two modes:
0 - unconditional;
1 - if NDEBUG is not defined in "debug.c".
2020-04-04 14:30:40 +02:00
Eric Kohl 93e72ed3d6 [NTOS:IO] Fix indentation. No code changes! 2020-03-21 14:32:18 +01:00
Eric Kohl 52d22630f5 [NTOS:PNP] Fix indentation. No code changes! 2020-03-21 13:23:23 +01:00
Eric Kohl a8846037e1 [NTOS:PNP] Map device capabilities to capability flags
This fixes a devices Capabilities value in the registry.
2020-03-21 13:23:22 +01:00
Thomas Faber 72c51aabba
[NTOS:IO][GDI32][CMD] Fix some under-sized variables. CORE-14922
Fixes x64 boot with RTC.
2020-03-13 20:45:06 +01:00
Eric Kohl 7a7212f984 [NTOS:IO] Fix indentation. No code changes! 2020-03-01 23:34:30 +01:00
Eric Kohl 9a07cde37f [NTOS:IO] Improve the device action worker
- Improve the device action worker to support more than just a single action
- Move the action queue code from IoInvalidateDeviceRelations to a new function IopQueueDeviceAction.
2020-03-01 23:32:25 +01:00
Eric Kohl a05051f554 [NTOS:IO] Move IopRemovePlugPlayEvent around and add the ResponseData parameter (not used yet) 2020-02-29 14:26:16 +01:00
Eric Kohl 9538c3ccd7 [NTOS:IO] Fix indentation. No code changes! 2020-01-02 23:25:26 +01:00
Thomas Faber c904983b49
[NTOS:IO] Use UNICODE_STRING operations in IopUnloadDriver.
Fixes several overflow vulnerabilities.
2019-12-31 15:18:17 +01:00
Timo Kreuzer 53f8cbad97 [NTOS:IO] Fix list enumeration in IopShutdownBaseFileSystems 2019-12-30 15:48:38 +01:00
Eric Kohl 8faf38ed22 [NTOS:IO] Fix indentation. No code changes! 2019-12-29 14:37:13 +01:00
Victor Perevertkin 3d046e0ed2 [NTOS:IO] Fix result length for DevicePropertyRemovalPolicy request
in IoGetDeviceProperty.
Classpnp expects it to be sizeof(DEVICE_REMOVAL_POLICY)
see ClasspInitializeHotplugInfo in classpnp.sys

CORE-6264
2019-11-17 18:36:28 +03:00
Pierre Schweitzer 80cc287cf6
[NTOSKRNL] Declare IoRemoteBootClient in internal headers 2019-10-21 14:16:58 +02:00
Thomas Faber 934484ea3e
[NTOS:PNP] When traversing the device tree, keep a reference to the current device. CORE-15874 2019-09-26 10:26:10 +02:00
Eric Kohl 0b129da05c [NTOSKRNL] Fix indentation. No code changes! 2019-08-24 10:02:55 +02:00
Mark Jansen 1539fb1414
[NTOSKRNL] Demote some noisy dprints 2019-08-23 13:03:36 +02:00
Serge Gautherie 87a625bd6c [NTOS:IO] iomgr.c: Add a missing '#if defined(KDBG)' 2019-08-17 17:36:49 +02:00
Timo Kreuzer 98a8e8f862 [NTOS:IO] In IopSynchronousCall first check IrpStack->MajorFunction before checking minor
Minor function indices are not unique, they are subfunctions, so without first checking the major function, they are ambiguous.
2019-08-15 18:04:57 +02:00
Timo Kreuzer e50873376d [NTOS:IO] Improve an alignment 2019-08-15 18:04:57 +02:00
Thomas Faber 2d419e90f9
[NTOS:PNP] Reduce the default buffer size in EnumerateDevices. CORE-15882 2019-07-10 10:58:47 +02:00
Thomas Faber b8e091a44c
[NTOS:PNP] Handle arbitrary subkey name lengths in EnumerateDevices. CORE-15882
This also makes it necessary to fix a bug in the previous code:
ZwEnumerateKey will not account for space for a null terminator, so to
ensure we have space, we must allocate the additional WCHAR, but not
include it in the buffer size passed to the function.
2019-07-10 10:58:45 +02:00
Bișoc George 42ce8519b6 [FASTFAT][FLTMGR][NTOS] Do not explicitly call ObfDereferenceObject() (#1636)
"Most code should not directly call the platform-specific ObfDereferenceObject() function but use the ObDereferenceObject() macro instead."

CORE-16081
2019-06-22 16:20:58 +02:00
Eric Kohl 6866c0aede [NTOSKRNL][USETUP][UMPNPMGR] Pass user response data to NtPlugPlayControl(PlugPlayControlUserResponse).
- Windows requires 16 bytes of response data.
- Add the PLUGPLAY_CONTROL_USER_RESPONSE_DATA type.
- Usetup and Umpnpmgr must fail if NtPlugPlayControl(PlugPlayControlUserResponse) does not return STATUS_SUCCESS.
2019-06-12 13:48:27 +02:00
Hermès Bélusca-Maïto 9060b0cb7a
Fix build (forgot a comma ;) 2019-06-11 22:36:10 +02:00
Hermès Bélusca-Maïto 41e7c818d1
[NTOS] IoSetHardErrorOrVerifyDevice(): Check whether the IRP is not associated with any thread. 2019-06-11 22:29:34 +02:00
Eric Kohl 8319c73e2e [NTOS:IO] Implement the PlugPlayControl.PlugPlayControlEnumerateDevice request
Drivers for Intel Pro/1000 NICs seem to install properly.
2019-06-08 20:42:38 +02:00
Pierre Schweitzer 9c3c0d123b
[NTOSKRNL] In case IopMountVolume call is a success, return its VPB
This fixes an extra (erroneous) reference being set on the VPB.

Based on a patch by Vadim Galyant

CORE-16080
2019-06-02 10:48:35 +02:00
Thomas Faber 5706f6e9f4
[NTOS:PNP] Reduce the size of the pool buffer in IopGetParentIdPrefix. CORE-15882 2019-05-05 10:39:29 +02:00
Thomas Faber f3a280f52b
[NTOS] Use correct buffer size when calling MiResolveImageReferences. CORE-15882 2019-05-05 10:39:11 +02:00
Thomas Faber ccb91bebbe
[NTOS:PNP] Avoid a fixed-length stack buffer in IopActionConfigureChildServices. CORE-15882 2019-05-05 10:39:07 +02:00
Thomas Faber e1b20681f5
[NTOS:IO] Avoid a fixed-length buffer in IopGetDriverObject. CORE-15882 2019-05-05 10:39:01 +02:00
Thomas Faber d605b5063f
[NTOS:IO] Send IRPs to the correct device in IoVolumeDeviceToDosName. CORE-15415 2019-03-30 10:13:27 +01:00
Pierre Schweitzer ef8b1a1907
[NTOSKRNL] We don't need an event if we don't issue an IRP 2019-03-29 21:47:34 +01:00
Pierre Schweitzer 28ba29e457
[NTOSKRNL] Implement support for FileFsDriverPathInformation in NtQueryVolumeInformationFile 2019-03-29 21:42:42 +01:00
Pierre Schweitzer 092c37f845
[NTOSKRNL] Do. Not. L. E. A. K. 2019-03-29 19:51:38 +01:00
Pierre Schweitzer d75ccd01f7
[NTOSKRNL] Only allow direct device open for FileFsDeviceInformation 2019-03-28 22:39:38 +01:00
Pierre Schweitzer ce6488df31
[NTOSKRNL] Add a quick path for FileFsDeviceInformation in NtQueryVolumeInformationFile
This allows querying volume information without issuing an IRP to the owner device.
The kernel is supposed to already have all the required information to return
to the caller.

Side effect: this allows querying volume information for devices not implementing
IRP_MJ_QUERY_VOLUME_INFORMATION such as null.sys
This fixes opening null device in Python.

Fix based on debugging by Maxim Smirnov in PR #1442

CORE-14551
2019-03-28 22:39:38 +01:00
Thomas Faber a976ebb031
[NTOS:IO] Avoid an unnecessary stack buffer in OpenRegistryHandlesFromSymbolicLink. CORE-15882 2019-03-25 08:43:47 +01:00
Thomas Faber 57225adaac
[NTOS:IO] Fix always-false condition in IoCheckEaBufferValidity.
Spotted by clang.
2019-03-25 08:41:51 +01:00
Thomas Faber 938f0e469d
[NTOS:IO] Enable privilege check in NtLoadDriver. 2019-03-11 08:30:14 +01:00
Thomas Faber cf40421041
[NTOS:PNP] Correctly respect data size in PnpRegSzToString. CORE-15766
Spotted by Vadim Galyant.
2019-02-20 12:23:33 +01:00
Thomas Faber 63977328b1
[NTOSKRNL] Guard against negative InformationClass enum values. CORE-15651 2019-02-02 22:50:02 +01:00
Hermès Bélusca-Maïto fefb982d64
[NTOS] Don't use TAG_IO_NAME when calling ExFreePoolWithTag() for freeing FileObject->FileName.Buffer .
This may look strange, since this buffer is originally allocated using
the TAG_IO_NAME tag. However, it happens that file-system drivers are
allowed to re-allocate this buffer: this is what the MS' open-sourced
CDFS driver does, see e.g. CdCommonCreate() and CdNormalizeFileNames()
in cdfs/create.c .

This fixes a pool tag mismatch 'mNoI' != 'nFdC' BSOD when resources
are freed when closing a file that has been opened with a relative name
on a CDFS-mounted volume.
2018-12-30 15:26:42 +01:00
Hermès Bélusca-Maïto d3a97e2228
[NTOS] Code formatting only. 2018-12-30 15:26:35 +01:00
Timo Kreuzer 71fefa32db
[NDK][NTOS] Add global definition of INIT_FUNCTION/INIT_SECTION (#779)
* Add an NDK header to define INIT_FUNCTION/INIT_SECTION globally
* Use _declspec(allocate(x)) and _declspec(code_seg(x)) on MSVC versions that support it
* Use INIT_FUNCTION on functions only and INIT_SECTION on data only (required by MSVC)
* Place INIT_FUNCTION before the return type (required by MSVC)
* Make sure declarations and implementations share the same modifiers (required by MSVC)
* Add a global linker option to suppress warnings about defined but unused INIT section
* Merge INIT section into .text in freeldr
2018-12-30 12:19:11 +01:00
Eric Kohl aecc523b6a [NTOS:IO] Fix indentation. No code changes. 2018-12-29 17:49:38 +01:00
Mark Jansen ec5c0c926b
[NTOS] When checking something for NULL, let's initialize it to NULL... 2018-12-27 23:03:22 +01:00
Eric Kohl 079f7027f6 [NTOS:IO] When a device has been started, create an Enum sub key to its service key and add the device instance name to the Enum sub key. 2018-12-25 23:04:27 +01:00
Pierre Schweitzer daf9743c7b
[NTOSKRNL] Check that caller has the priviliege to unload a driver
Also, probe the service name when unloading a driver if called from
user-mode. This will avoid that userland applications can trigger an
invalid read in the kernel (and thus, a BSOD).

CORE-15468
2018-12-20 08:50:51 +01:00
Eric Kohl b67dbdbea5 [NTOSKRNL] Fix indentation. No code changes. 2018-12-19 19:18:21 +01:00
Eric Kohl 7e56b21ad6 [NTOSKRNL] Fix indentation. No code changes. 2018-12-19 19:18:20 +01:00
Eric Kohl e8d16d0a7d [NTOSKRNL] Fix indentation. No code changes. 2018-12-16 10:30:23 +01:00
Eric Kohl 12fdc129cf [NTOSKRNL] IopGetDeviceProperty: Send an IRP_MN_QUERY_CAPABILITIES request to the device in order to query the power capabilities. 2018-12-10 00:37:04 +01:00
Pierre Schweitzer 67e7399164
[NTOSKRNL] Use proper enum type for IopCreateSecurityDescriptorPerType() 2018-12-04 19:20:47 +01:00
Pierre Schweitzer 73e7a5d474
[NTOSKRNL] Use the appropriated security descriptor when creating a device
CORE-9176
2018-12-04 19:13:57 +01:00
Pierre Schweitzer 36c38c45ee
[NTOSKRNL] Implement IopCreateDefaultDeviceSecurityDescriptor() and IopCreateSecurityDescriptorPerType()
CORE-9176
2018-12-04 19:13:57 +01:00
Andrew Boyarshin 198601a101 [NTOS:IO] Tiny improvement to debug message
Add quotes around string, since it is often empty, thus confusing in log.
2018-11-25 11:31:12 +01:00
Hermès Bélusca-Maïto f87d9caf77 [NTOS:IO] Finally remove the dreadful IopParseDevice() hack! \o/ 2018-11-25 09:00:40 +01:00
Pierre Schweitzer a0c33934fc
[NTOSKRNL] Properly check for negative values in IoCheckEaBufferValidity()
CID 1441355, 1441382
2018-11-16 22:07:08 +01:00
Hermès Bélusca-Maïto cbaa8e7dfb
[NTOS:IO] RAW-FS: Few improvements.
- Simplify the volume-deletion code in RawCheckForDismount().

- Fixes the OpenCount check in RawClose(): the VCB mutex must be
  released when the volume has not been dismounted, either because
  OpenCount != 0 or because RawCheckForDismount() returned FALSE.

- Explicitly use VCB_STATE_LOCKED instead of hardcoding its value.

- In IRP_MN_VERIFY_VOLUME handling, lock the volume before playing
  with it, and again let the volume be dismounted only if OpenCount == 0
  (and the IoDeleteDevice() call is done by RawCheckForDismount()).
2018-11-11 21:56:18 +01:00
Hermès Bélusca-Maïto a5ead049d9
[NTOS:IO] RAW-FS: Minor code formatting only. 2018-11-11 21:56:17 +01:00
Pierre Schweitzer 03294dd097
[NTOSKRNL] Rewrite IoCheckEaBufferValidity() so that it's less magic
And make its coding style consistent with our rules
2018-10-27 22:16:37 +02:00
Pierre Schweitzer 8e51bb6510
[NTOSKRNL] Reduce noise 2018-10-27 10:04:22 +02:00
Hermès Bélusca-Maïto cb69c4c691
[NTOS] Add some DPRINTs in IopLoadServiceModule() and IopOpenRegistryKeyEx() to investigate why these 1st-stage text-mode hacks may be, or are (respectively) still needed.
svn path=/branches/setup_improvements/; revision=74748
2018-10-25 00:40:03 +02:00
Hermès Bélusca-Maïto e2cb7b50b4
[NTOS] Remove some hacks that are not needed anymore, since a real registry hive will be used in 1st-stage as well.
This reverts a7c26408 (r53255) and ff75ae1b (r53694), and a hack from 6075ae9a (r46690).

svn path=/branches/setup_improvements/; revision=74745
svn path=/branches/setup_improvements/; revision=74746
2018-10-25 00:40:00 +02:00
Pierre Schweitzer 0b713d4fa0
[NTOSKRNL] On open, verify and validate the hint device object if any 2018-10-05 10:49:59 +02:00
Pierre Schweitzer 779d87b483
[NTOSKRNL] Implement IopCheckTopDeviceHint() 2018-10-05 10:49:59 +02:00
Pierre Schweitzer 670a7ac718
[NTOSKRNL] In IoGetRelatedDeviceObject(), validate hint is on the stack before returning it 2018-10-05 10:49:59 +02:00
Pierre Schweitzer 161b6728ef
[NTOSKRNL] Implement IopVerifyDeviceObjectOnStack() 2018-10-05 10:49:59 +02:00
Pierre Schweitzer 2a182931b6
[NTOSKRNL] A bit of cleanup in Io*FilterContext() 2018-10-04 22:24:52 +02:00
Pierre Schweitzer 5f0d02eb52
[NTOSKRNL] Implement IoChangeFileObjectFilterContext() 2018-10-04 19:30:39 +02:00
Pierre Schweitzer a43fb5e054
[NTOSKRNL] Implement IoGetFileObjectFilterContext() 2018-10-04 19:30:38 +02:00
Pierre Schweitzer e19e907a2c
[NTOSKRNL] Quickly check for alignment in NtRead/WriteFile
This quick check based on bits and operation is for 2^ based
sector sizes (most of the cases) and will perform faster than
the modulo operation which is still used in fallback in case
the sector size wouldn't be a power of 2.
2018-10-04 10:45:10 +02:00
Pierre Schweitzer 44155053cd
[NTOSKRNL] Use captured variable to check parameters in NtRead/WriteFile 2018-10-04 10:45:10 +02:00
Pierre Schweitzer bf59669065
[NTOSKRNL] On read/write, also check buffer respects device alignment requirements 2018-10-04 07:56:23 +02:00
Pierre Schweitzer 1bd25c5c24
[NTOSKRNL] When checking for byte offset alignment, tolerate some magic values 2018-10-04 07:53:12 +02:00
Eric Kohl fd33402104 [NTOSKRNL] NtReadFile/NtWriteFile: If a file has been opened for non-cached access, Length and ByteOffset must be sector size aligned.
This fixed two ntdll apitests.
2018-10-04 01:17:58 +02:00
Pierre Schweitzer d8f22735ed
[NTOSKRNL] In IopQueryNameInternal(), enclose output copy in a SEH statement 2018-10-03 22:55:23 +02:00
Pierre Schweitzer 15b9a6aa4c
[NTOSKRNL] Call IoCreateFileSpecifyDeviceObjectHint with the hint if it was specified 2018-10-03 21:29:12 +02:00
Pierre Schweitzer 520f404e9c
[NTOSKRNL] In IoQueryFileDosDeviceName(), in case of an error, return appropriate status 2018-10-03 17:08:42 +02:00
Pierre Schweitzer 8c6c5a92e8
[NTOSKRNL] Implement DOS name query in IopQueryNameInternal() 2018-10-03 13:56:18 +02:00
Pierre Schweitzer 769157f6ff
[NTOSKRNL] Allow FileNameInformation not to be implemented in storage stack 2018-10-03 13:52:05 +02:00
Pierre Schweitzer 46bda8a4c6
[NTOSKRNL] In IopQueryNameInternal() don't copy name if it's not valid 2018-10-03 13:50:16 +02:00
Pierre Schweitzer 4a7e89770e
[NTOSKRNL] Implement IoQueryFileDosDeviceName() 2018-10-03 11:56:21 +02:00
Pierre Schweitzer abfddca8bb
[NTOSKRNL] Stub support for querying DOS name when parsing FO name 2018-10-03 11:45:08 +02:00
Pierre Schweitzer a1401a7577
[NTOSKRNL] Use faster internal helper to query name
This only applies if we're called from kernel mode
with a synchronous file.
2018-10-03 10:22:33 +02:00
Pierre Schweitzer 1348f62f20
[NTOSKRNL] Rename IopQueryNameFile to IopQueryNameInternal 2018-10-03 10:22:33 +02:00
Thomas Faber 8fbc488050
[NTOS:IO] Implement IopAcquireFileObjectLock and use it to fix IopLockFileObject 2018-10-02 09:56:55 +02:00
Pierre Schweitzer 890a293683
[NTOSKRNL] Fix remaining access computation on open 2018-09-30 10:55:44 +02:00