Commit graph

444 commits

Author SHA1 Message Date
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
Bernhard Feichtinger 8a0495063b [NTOS:MM] Handle unimplemeted case for MiCheckForUserStackOverflow 2018-11-25 11:29:18 +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 4f1e9252f1
[NTOSKRNL] ExfReleaseRundownProtectionCacheAware*() functions don't return anything 2018-11-17 17:36:18 +01:00
Pierre Schweitzer 7ed17cd714
[NTOSKRNL] Implement ExfReInitializeRundownProtectionCacheAware()
We're done with cache-aware rundown protections!
2018-11-17 16:44:37 +01:00
Pierre Schweitzer 05cca64448
[NTOSKRNL] Implement ExfRundownCompletedCacheAware() 2018-11-17 16:44:37 +01:00
Pierre Schweitzer fed61c6305
[NTOSKRNL] Replace ExGetRunRefForCurrentProcessor() by a more generic function 2018-11-17 16:44:36 +01:00
Pierre Schweitzer 7e849470af
[NTOSKRNL] Implement ExfWaitForRundownProtectionReleaseCacheAware() 2018-11-17 16:44:36 +01:00
Pierre Schweitzer acdf74aa3b
[NTOSKRNL] Properly align runrefs on SMP in ExInitializeRundownProtectionCacheAware() 2018-11-17 16:44:36 +01:00
Pierre Schweitzer c5db202bdc
[NTOSKRNL] Properly align allocation on SMP in ExAllocateCacheAwareRundownProtection() 2018-11-17 16:44:36 +01:00
Pierre Schweitzer 36fadc2dca
[NTOSKRNL] Implement ExfAcquireRundownProtectionCacheAwareEx(), ExfReleaseRundownProtectionCacheAwareEx() 2018-11-17 16:44:35 +01:00
Pierre Schweitzer afb2214154
[NTOSKRNL] Simplify implementation of ExfAcquireRundownProtectionCacheAware(), ExfReleaseRundownProtectionCacheAware() 2018-11-17 16:44:35 +01:00
Pierre Schweitzer 010b9b5469
[NTOSKRNL] Implement ExGetRunRefForCurrentProcessor() to get runref for a proc 2018-11-17 16:44:35 +01:00
Pierre Schweitzer 7e36e76d5d
[NTOSKRNL] Implement ExfAcquireRundownProtectionCacheAware(), ExfReleaseRundownProtectionCacheAware() 2018-11-17 16:44:35 +01:00
Pierre Schweitzer 47d309b262
[NTOSKRNL] Implement ExSizeOfRundownProtectionCacheAware() 2018-11-17 16:44:35 +01:00
Pierre Schweitzer ce94d37dbe
[NTOSKRNL] Implement ExInitializeRundownProtectionCacheAware() 2018-11-17 16:44:35 +01:00
Pierre Schweitzer bc77f83888
[NTOSKRNL] Implement ExAllocateCacheAwareRundownProtection() and ExFreeCacheAwareRundownProtection() 2018-11-17 16:44:34 +01:00
Pierre Schweitzer a0c33934fc
[NTOSKRNL] Properly check for negative values in IoCheckEaBufferValidity()
CID 1441355, 1441382
2018-11-16 22:07:08 +01:00
Pierre Schweitzer 95bc44e214
[NTOSKRNL] Don't leak DACL
Spotted by Thomas :-)
2018-11-11 23:21:36 +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 6747dacf10
[NTOSKRNL] Create a security descriptor for the \security directory object 2018-11-10 23:25:10 +01:00
Pierre Schweitzer 102ba75f15
[NTOSKRNL] Return security descriptor size when querying object basic info 2018-11-10 10:54:10 +01:00
Pierre Schweitzer 1fb32afefa
[NTOSKRNL] Return quota information when querying object basic info 2018-11-10 10:54:06 +01:00
Jérôme Gardou df25e4e791 [NTOS/MM] Properly handle page faults in regions marked with
PAGE_NOACCESS or PAGE_GUARD

ROSTESTS-110
2018-11-03 12:50:16 +01:00
Jérôme Gardou 47ac7a2b28 [NTOS/MM] Move up MmAlterViewAttributes for later use in MmNotPresentFaultSectionView
No code change
2018-11-03 12:50:16 +01:00
Pierre Schweitzer cf7969fbfa
[NTOSKRNL] Fix refcounting for BCBs
Now, we make sure that we update ref count and BCB list membership
with the BCB lock held, in a row.
This will avoid race conditions where the BCB was removed from the
list, then referenced again, leading to inconsistencies in memory
and crashes later on.
This could notably be triggered while building ReactOS on ReactOS
(one would call this a regression).

CORE-15235
2018-10-28 20:48:01 +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 07e6af6aa1
[NTOSKRNL] Properly handle "big" security descriptors in ObpCaptureObjectCreateInformation() 2018-10-27 19:36:15 +02:00
Pierre Schweitzer 2ce071d19a
[NTOSKRNL] Implement SeComputeQuotaInformationSize() 2018-10-27 19:36:14 +02:00
Pierre Schweitzer 9c6037182c
[NTOSKRNL] Add support for unsecure object names 2018-10-27 12:01:38 +02:00
Pierre Schweitzer 0f36353551
[NTOSKRNL] Implement the ObpIsUnsecureName() helper function 2018-10-27 12:01:38 +02:00
Pierre Schweitzer b9423f07d9
[NTOSKRNL] Add support for the ObUnsecureGlobalNames registry key 2018-10-27 12:01:38 +02:00
Pierre Schweitzer 8e51bb6510
[NTOSKRNL] Reduce noise 2018-10-27 10:04:22 +02:00
Pierre Schweitzer 18f3922725
[NTOSKRNL] Call internal helper to get VACB on mapping
We already properly round our offset
2018-10-27 09:38:55 +02:00
Hermès Bélusca-Maïto 83d5c711b3
[NTOS] Drastically reduce the hackish function CmpGetRegistryPath() for the text-mode setup case (it should ultimately completely disappear).
svn path=/branches/setup_improvements/; revision=75163
2018-10-25 00:40:03 +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 2ed65d1555
[NTOS] Configuration Manager fixes.
- Rework CmpSetSystemValues() and remove its 1st-stage text-mode setup hack, since a real registry hive will be used for 1st-stage either.
- Lock, then unlock the registry in NtInitializeRegistry when initializing the hives & flusher.
- Call CmpInitializeHiveList() (i.e., initialize the other hives like \Software, \User, \.Default) only when we are not in setup-mode.

svn path=/branches/setup_improvements/; revision=74747
2018-10-25 00:40:02 +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 f3b9beeb39
[NTOSKRNL] Translate pinning flags to mapping flags when first mapping a file 2018-10-23 22:07:53 +02:00
Hermès Bélusca-Maïto 0e6bc236a1
[NTOS:CM] CmpCmdHiveOpen(): Resolve FileAttributes->RootDirectory when a hive file name is provided relative to it.
Fixes registry hive loading. CORE-13448
2018-10-22 00:39:50 +02:00
Hermès Bélusca-Maïto d61c00c252
[NTOS:CM] Implement more support for force-unloading registry hives.
CORE-13448 CORE-10705
2018-10-22 00:05:13 +02:00
Hermès Bélusca-Maïto 16752875db
[NTOS:CM] Add extra validation for the information class parameter in NtEnumerateValueKey(). 2018-10-21 18:12:08 +02:00
Hermès Bélusca-Maïto 49e08b23ce
[NTOS:CM] Improve the capture of user-mode parameters.
- Improve the capture of OBJECT_ATTRIBUTES parameters that are passed
  (by pointer) to the Cm* helper functions, and the capture of
  UNICODE_STRINGs.

- Correctly differentiate user-mode vs. kernel-mode root directory handles
  (in OBJECT_ATTRIBUTES): note that most of the Cm* APIs expect their
  parameters to be kernel-mode (pointers, handles...).

CORE-13448
2018-10-21 17:11:50 +02:00
Hermès Bélusca-Maïto 29b2fdcc4d
[NTOS:CM] Minor fixes.
- Validate the information class parameter in NtQueryValueKey().
- Call the post-callback in NtSetValueKey() only if the callback
  has been registered and the CmSetValueKey() call is executed.
2018-10-20 19:52:34 +02:00
Hermès Bélusca-Maïto 5322969186
[NTOS:CM] Reuse the saved previous-mode from the ExGetPreviousMode() calls. 2018-10-20 19:52:32 +02:00
Hermès Bélusca-Maïto 4caf391324
[NTOS][MKHIVE] Minor code formatting. 2018-10-14 15:59:34 +02:00
Pierre Schweitzer 3d13a464f7
[NTOSKRNL] Add the CcPinMappedDataCount counter 2018-10-13 22:51:44 +02:00
Pierre Schweitzer 1afcbbd125
[NTOSKRNL] Rewrite the way we create BCB for pinning
We won't reuse a BCB created for mapping, we will now have
our own dedicated BCB.
This allows having a bit more cleaner implementation of CcPinMappedData()
2018-10-13 22:51:44 +02:00
Serge Gautherie a06b425839 [NTOS:KD] A few trivial code improvements 2018-10-12 08:43:02 +02:00
Serge Gautherie 561a10056b [NTOS:KD] Remove an unreachable "break;"
On behalf of Kudratov Olimjon.
CORE-8545
2018-10-12 08:43:02 +02:00
Pierre Schweitzer 1acb5a9fab
[NTOSKRNL] Don't keep the spin lock hold too long when we lost the BCB race
This will avoid a deadlock on unpin.
2018-10-12 08:20:32 +02:00
Pierre Schweitzer cf8ba3bd9c
[NTOSKRNL] Rewrite BCB handling to be more robust
We now handle race conditions when creating BCB to avoid
having duplicated BCB per shared maps.
Also, we already specify whether the memory will be pinned
when creating the BCB, to avoid potential duplications or
BCB misuse.
2018-10-11 23:15:01 +02:00
Pierre Schweitzer bd39459f89
[NTOSKRNL] Implement support for PIN_IF_BCB flag 2018-10-05 21:26:16 +02:00
Pierre Schweitzer 7fd2751c87
[NTOSKRNL] When pinning data, try to find an already pinned BCB
If found, attempt to lock it and return it.

This fixes a lot of CcPinRead tests (and seems to speed up a bit ReactOS)
2018-10-05 21:26:16 +02:00
Pierre Schweitzer 9fc75c1132
[NTOSKRNL] When mapping data, try to find if there's already a BCB
If so, return such BCB instead of creating a new one. This will
allow (at some point) to be more consistent in case of concurrent
mapping.

This fixes a few CcMapData tests.
2018-10-05 21:26:16 +02:00
Pierre Schweitzer f284947622
[NTOSKRNL] Move the PinCount out of the VACB to the BCB
Given current ReactOS implementation, a VACB can be pinned
several times, with different BCB. In next commits, a single
BCB will be able to be pinned several times. That would
lead to severe inconsistencies in counting and thus corruption.
2018-10-05 21:26:16 +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 fd8893e58f
[NTOSKRNL] Respect PFN cache attribute when required
This fixes noisy DPRINT1 being printed while reading
or writing files with NFS.
2018-10-01 20:59:37 +02:00
Pierre Schweitzer 890a293683
[NTOSKRNL] Fix remaining access computation on open 2018-09-30 10:55:44 +02:00
Pierre Schweitzer 6d0c07c44f
[NTOSKRNL] Implement access check for secure open 2018-09-30 10:55:43 +02:00
Pierre Schweitzer cf25432eed
[NTOSKRNL] Don't lock file object on close if we're not called by Ob
IopCloseFile can be called by IopDeleteFile. In that situation, it
doesn't set any process as first parameter. Furthermore, we are in a
situation where it's not required to lock the file object (see the
assert before the call).
2018-09-29 16:25:58 +02:00
Pierre Schweitzer 207ff9444e
[NTOSKRNL] Reference the file object before issuing the unlock all IRP
This fixes the last kmode assert triggered by httpd on ReactOS.

CORE-12045
2018-09-29 11:22:22 +02:00
Pierre Schweitzer 5472c1db82
[NTOSKRNL] Unlock file if required on last process handle close 2018-09-28 23:34:28 +02:00
Hermès Bélusca-Maïto 89c5191d3f
[NTOS:PS] In PspSetPrimaryToken(), check also for sibling token to determine whether it is required to have the SeAssignPrimaryTokenPrivilege.
In addition, it is the presence or absence of the 'Token' pointer that indicates whether or not we should use instead the provided token handle.
2018-09-28 00:45:03 +02:00
Hermès Bélusca-Maïto 7f9282927b
[NTOS:SE] Fixes for NT tokens.
- SeIsTokenChild(): Correctly check whether a caller-provided token
  is a child from the current process' primary token by looking at
  its ParentTokenId member.

- Add a SeIsTokenSibling() helper to determine whether a caller-provided
  token and the current process' primary token are siblings, by comparing
  their ParentTokenId's and AuthenticationId's.

NOTE: Children tokens are created through CreateRestrictedToken();
sibling tokens are created through DuplicateToken() (amongst others).

See slide 49 of https://www.slideshare.net/Shakacon/social-engineering-the-windows-kernel-by-james-forshaw
or https://googleprojectzero.blogspot.com/2016/01/raising-dead.html
for some details.
2018-09-28 00:45:01 +02:00
Pierre Schweitzer 2a80ae2bb6
[NTOSKRNL] Properly align VACB writes
Also simplify VACB reads alignment code.
Also add some sanity ASSERTs.
2018-09-23 10:32:14 +02:00
Eric Kohl e32a2cc026 [NTOSKRNL] IoGetDeviceProperty: Add support for the DevicePropertyRemovalPolicy property.
This could probably fix CORE-15068.
2018-09-22 11:22:22 +02:00
Eric Kohl e1b82b5b91 [NTOSKRNL] Create the 'Device Parameters' subkey and add the 'FirmwareIdentified' value for all ACPI-enumerated devices. 2018-09-21 15:37:34 +02:00
Eric Kohl 2550325577 [NTOSKRNL] Fix the indentation of some pnp manager functions. 2018-09-21 15:08:43 +02:00
Pierre Schweitzer 15a3ca08b0
[NTOSKRNL] Avoid integer overflow when computing VACB read/write size
This could be triggered when attempting to read/write to really big
files. It was causing an attempt to read 0 bytes in Cc, leading to
asserts failure in the kernel (and corrupted file).

CORE-15067
2018-09-21 08:37:20 +02:00
Pierre Schweitzer 108991a6fb
[NTOSKRNL] Stub IoInitializeCrashDump()
Also call it from NtCreatePagingFile() when we have successfully created
a paging file on the system boot partition.
2018-09-18 21:59:59 +02:00
Pierre Schweitzer 02da7b452c
[NTOSKRNL] Move data mapping implementation to an internel helper 2018-09-09 14:02:13 +02:00
Pierre Schweitzer 3dabca398f
[NTOSKRNL] Don't raise a status when parameters are invalid on file mapping 2018-09-05 22:06:29 +02:00
Pierre Schweitzer e17f61138c
[NTOSKRNL] When allocating a new BCB, save it in a list
This list is stored in the shared map. Later, this will allow
reusing BCB when appropriate
2018-09-05 22:06:25 +02:00
Pierre Schweitzer f96f1224a7
[NTOSKRNL] Fail on pinning when there's no pin access set
Instead of assert, now, CcPinRead will just fail. This is
not consistent without Windows behavior, but still better
than asserting while testing!
2018-09-01 12:41:01 +02:00
Pierre Schweitzer f0eb39084e
[NTOSKRNL] Fix a typo 2018-08-31 19:48:32 +02:00
Pierre Schweitzer e806d16b06
[NTOSKRNL] Warn about unimplemented feature in CcMapData() (in all callers)
Currently, our CcMapData() behavior (same goes for CcPinRead()) is broken
and is the total opposite of what Windows kernel does. By default, the later
will let you map a view in memory without even attempting to bring its
data in memory. On first access, there will be a fault and memory will
be read from the hardware and brought to memory. If you want to force read
on mapping/pinning, you have to set the MAP_NO_READ (or PIN_NO_READ) flag
where kernel will fault on your behalf (hence the need for MAP_WAIT/PIN_WAIT).

On ReactOS, by default, on mapping (and thus pinning), we will force a view
read so that data is in memory. The way our cache memory is managed at the
moment seems not to allow to fault on invalid access and if we don't force
read, the memory content will just be zeroed.
So trying to match Windows behavior, by default, now CcMapData() will enforce
the MAP_NO_READ flag and warn once about this behavior change.
2018-08-31 19:48:32 +02:00