Commit graph

341 commits

Author SHA1 Message Date
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
Pierre Schweitzer b8e4af606a
[NTOSKRNL] Properly reset pinning state on pinning failure 2018-08-26 22:56:25 +02:00
Pierre Schweitzer 54f89baad4
[NTOSKRNL] When acquiring BCB shared, starve exclusive waiters 2018-08-26 22:47:48 +02:00
Pierre Schweitzer c1dd4c142f
[NTOSKRNL] Handle the PIN_WAIT flag in CcPinMappedData() 2018-08-26 22:05:11 +02:00