Commit graph

317 commits

Author SHA1 Message Date
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
Pierre Schweitzer 469e15c7ae
[NTOSKRNL] Stubplement CcPinMappedData() and simplify CcPinRead()
It's based on the code that was in CcPinRead() implementation. This
made no sense to have CcPinMappedData() doing nothing while implementing
everything in CcPinRead(). Indeed, drivers (starting with MS drivers)
can map data first and pin it afterwards with CcPinMappedData(). It was
leading to incorrect behavior with our previous noop implementation.
2018-08-26 22:05:11 +02:00
Denis Malikov 0cf5efc14c [NTOS:KE] Fix stub for KeAcquireInStackQueuedSpinLockForDpc (#814)
Error was found when building as 0x600+.
CORE-12596
2018-08-26 15:19:26 +02:00
Eric Kohl 06e7233134 [NTOSKRNL] IopGetDeviceProperty: Initialize power data struct and convert flags from device capabilities to power data 2018-08-25 19:49:29 +02:00
Pierre Schweitzer 5c10b02957
[NTOSKRNL] Add the OLE flag where appropriate in FsRtlLegalAnsiCharacterArray
This brings in the ability to check NTFS streams names (OLE | NTFS).
This fixes failing tests from previous commit.
2018-08-25 14:26:49 +02:00
Timo Kreuzer f43a7b81a7
[NTOS:Mm] Fix a 64 bit issue in MmMapViewOfArm3Section (#778)
Fixes a Clang-Cl warning
CORE-14306
2018-08-21 11:25:22 +02:00
Timo Kreuzer d5181e44dd
[NTOS] Fix MiFindInitializationCode (#751)
Short: The code was suffering from an off-by-one bug (inconsistency between inclusive end exclusive end address), which could lead to freeing one page above the initialization code. This led to freeing part of the kernel import section on x64. Now it is consistently using the aligned/exclusive end address.

Long:
* Initialization sections are freed both for the boot loaded images as well as for drivers that are loaded later. Obviously the second mechanism needs to be able to run at any time, so it is not initialization code itself. For some reason someone decided though, it would be a smart idea to implement the code twice, once for the boot loaded images, once for drivers and concluding that the former was initialization code itself and had to be freed.
* Since freeing the code that frees the initialization sections, while it is doing that is not possible, it uses a "smart trick", initially skipping that range, returning its start and end to the caller and have the caller free it afterwards.
* The code was using the end address in an inconsistent way, partly aligning it to the start of the following section, sometimes pointing to the last byte that should be freed. The function that freed each chunk was assuming the latter (i.e. that the end was included in the range) and thus freed the page that contained the end address. The end address for the range that was returned to the caller was aligned to the start of the next section, and the caller used it to free the range including the following page. On x64 this was the start of the import section of ntoskrnl. How that worked on x86 I don't even want to know.
2018-08-21 10:35:57 +02:00
Timo Kreuzer e97b95cc2e [NTOS:MM] Fix ASSERT when expanding paged pool
The page directory is double mapped on x86 in the system process, so writing to it will already write to the PDE.
2018-08-20 23:52:42 +02:00
Timo Kreuzer c219be9409 [NTOS:MM] Fix paged pool expansion 2018-08-20 18:07:35 +02:00
Stanislav Motylkov d033fe9bbf [NTOS:EX] Implement SystemFirmwareTableInformation class 2018-08-19 20:27:59 +02:00
Timo Kreuzer 094a90ad4e [NTOS:PS] Fix an issue with PROCESS_DEVICEMAP_INFORMATION size on 64 bit builds
The PROCESS_DEVICEMAP_INFORMATION  union has 2 fields, one is a handle, the other one is a structure of 36 bytes (independent of architecture). The handle forces 64 bit alignment on 64 bit builds, making the structure 4 bytes bigger than on 32 bit builds. The site is checked in NtQueryInformationProcess (case ProcessDeviceMap). The expected size on x64 is the size of the Query structure without alignment. autocheck correctly passes the site of the Query union member, while smss passes the full size of PROCESS_DEVICEMAP_INFORMATION. Packing the structure is not an option, since it is defined in public headers without packing. Using the original headers sizeof(PROCESS_DEVICEMAP_INFORMATION) is 0x28, sizeof(PROCESS_DEVICEMAP_INFORMATION::Query) is 0x24.
2018-08-17 22:08:37 +02:00
Timo Kreuzer 2c909db295 [NTOS:OB] Rename object types to their official names to satisfy WinDbg
- Rename ObDirectoryType to ObpDirectoryObjectType and remove it from NDK (this is not exported!)
- Rename ObSymbolicLinkType to ObpSymbolicLinkObjectType
- Remove duplicated ObpTypeObjectType from ob.h
2018-08-17 20:28:45 +02:00
Pierre Schweitzer 65f9783808
[NTOSKRNL] Properly initialize the IO_STATUS_BLOCK 2018-08-17 19:13:13 +02:00
Pierre Schweitzer 12e8d7fe0e
[NTOSKRNL] Only allow page file on a few specific device types 2018-08-16 19:00:22 +02:00
Pierre Schweitzer cc59c97308
[NTOSKRNL] Don't need all access for file object 2018-08-16 18:54:23 +02:00
Pierre Schweitzer 8281f4baa6
[NTOSKRNL] Add a check commented out for now.
It's to be enabled once page file handling is moved to ARM3
2018-08-16 18:49:55 +02:00
Pierre Schweitzer 7f0ad923d2
[NTOSKRNL] MmTotalCommitLimit and MmTotalCommitLimitMaximum are in pages, not bytes 2018-08-16 18:40:23 +02:00
Timo Kreuzer dd73d1b6d4 [NTOS:MM] Make SLIST handling for kernel stacks portable
Kernel stacks that re freed, can be placed on an SLIST for quick reuse. The old code was using a member of the PFN of the last stack page as the SLIST_ENTRY. This relies on the following (non-portable) assumptions:
- A stack always has a PTE associated with it.
- This PTE has a PFN associated with it.
- The PFN has an empty field that can be re-used as an SLIST_ENTRY.
- The PFN has another field that points back to the PTE, which then can be used to get the stack base.

Specifically: On x64 the PFN field is not 16 bytes aligned, so it cannot be used as an SLIST_ENTRY. (In a "usermode kernel" the other assumptions are also invalid).

The new code does what Windows does (and which seems absolutely obvious to do): Place the SLIST_ENTRY directly on the stack.
2018-08-16 16:52:02 +02:00
Timo Kreuzer 6c154c0625 [NTOS:SE] Fix SeSetSecurityDescriptorInfoEx to prevent pool corruption on x64 2018-08-16 16:32:49 +02:00
Serge Gautherie 20d4b2cfac [NTOS:MM] Update a DPRINT string (#760)
CORE-12729
2018-08-16 15:10:24 +02:00
Pierre Schweitzer 19318dcc1d
[NTOSKRNL] Start making our MMPAGING_FILE struct look like the real one 2018-08-16 14:04:27 +02:00
Pierre Schweitzer e392bdf962
[NTOSKRNL] Store page file sizes in pages, not in bytes 2018-08-16 13:50:16 +02:00
Pierre Schweitzer 2fe4e71383
[NTOSKRNL] Store page file minimum size and use it to prevent page file shrinking 2018-08-16 13:41:16 +02:00
Pierre Schweitzer bfc6a7957c
[NTOSKRNL] Page files don't have an init size, but a minimum size
NFC
2018-08-16 12:42:34 +02:00
Pierre Schweitzer 315867d4ff
[NTOSKRNL] Drop the MmPagingFile spin lock in favor of a guarded mutex 2018-08-16 12:39:24 +02:00