Commit graph

1147 commits

Author SHA1 Message Date
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
Jérôme Gardou 04e9251612 [NTOS:PS] Use KD routine to safely read memory from thread stack
Should fix a crash when hitting TAB+(Whatever I typed that triggerred this)
2021-05-10 19:11:21 +02:00
George Bișoc f5dc1c77b5
[NDK][NTOS:SE] Add the missing "LogonSession" member to TOKEN structure
And also fix the wrong member offsets in comments. The said offset values are based upon the ones retrieved with WinDBG.
2021-05-09 17:34:02 +02:00
George Bișoc 11f239373d
[NTOS:SE] Add further remarks in SeQueryInformationToken
Explicitly mention under remarks that some classes are not implemented for that function, for documentation purposes. No code changes.
2021-05-08 18:11:42 +02:00
Stanislav Motylkov 83dbb6b27e
[NTOS:PS] Do not leak the Thread. Addendum to 0c8f0785 2021-05-08 00:32:14 +03:00
Stanislav Motylkov 0c8f07854b
[NTOS:PS] Fix misplaced Thread variable reference caught by RTC
Addendum to 2e88e2b9.
2021-05-07 21:54:10 +03:00
Jérôme Gardou f421bccbcc [NTOS:MM] First shot for Working Set list support
- Initialize
- Add private page (no shared page support yet)
- Remove pages
- Trim

Yes, this is C++ in the kernel.
2021-05-04 12:02:41 +02:00
Jérôme Gardou 31afbf1054 [NTOS] Make some internal headers C++ aware 2021-05-04 12:02:41 +02:00
Jérôme Gardou 8df48f9876 [NTOS:MM] Introduce MI_IS_PROCESS_WORKING_SET helper function 2021-05-04 12:02:41 +02:00
Jérôme Gardou 6b2f05f9dd [NTOS:MM] Implement turning working set shared lock to exclusive 2021-05-04 12:02:41 +02:00
Jérôme Gardou cd085ac12f [NTOS/MM] Implement Mi(Un)lockWorkingSetShared
Also fix checks when exclusively locking
2021-05-04 12:02:41 +02:00
George Bișoc 5dd93a8a5b
[NTOS:SE] Get the session ID and assign it to the new token
SeExchangePrimaryToken doesn't assign the session ID to the new token, which could lead to incorrect behaviour in the long run. Let's fix that.
2021-05-04 10:08:26 +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
George Bișoc 74e527b452
[NTOS:PS] Bring the threads/processes information classes table back
These were removed in bf493b9, for whatever apparent reason. It's time to import them back.
2021-05-02 20:52:18 +02:00
George Bișoc 39b266b728
[NTOSKRNL] Move the ICIF related code and stuff into a separate header file
For easier accessibility for the APITESTs and whatnot.
2021-05-02 20:49:06 +02:00
George Bișoc 242efae9a2
[NTOS:PS] Make sure we can impersonate the given token first
PsImpersonateClient blindly impersonates the requested client even though it doesn't know if the actual token given to the call can be impersonated for the thread of the client which we are going to begin impersonation. In the case where impersonation is not possible, make a copy of the given token and assign the newly one for impersonation instead.
CORE-17539
2021-05-02 16:55:20 +02:00
George Bișoc 18ddb6ba92
[NTOS:SE] Implement SeTokenCanImpersonate routine
SeTokenCanImpersonate ensures whether the client impersonation can occur, and if not, the call signals this to the caller.
2021-05-02 16:55:19 +02:00
Eric Kohl a7d6483e65 [NTOS:PS] Revert 4d7062abb6 on request 2021-05-02 16:26:11 +02:00
Eric Kohl 9fa31e0f9b [NTOS:PS] Add the missing privilege check to NtSetInformationThread:ThreadPriority
This fixes the remaining failure in the NtSetInformationThread test.
2021-05-02 15:28:26 +02:00
Eric Kohl 4d7062abb6 [NTOS:PS] Add ThreadInformation probing to NtSetInformationThread
Also get rid of unused buffer check code.
This fixes two test failures.
2021-05-02 13:55:29 +02:00
Eric Kohl 2e88e2b904 [NTOS:PS] Rewrite NtSetInformationThread to match NtQueryInformationThread
The Information length must always be checked before referencing the thread object. This fixes a test failure.
2021-05-02 13:46:22 +02:00
Eric Kohl 5585767460 [NTOS:PS] Rewrite NtQueryInformationThread to match NtQueryInformationProcess
The information length must always be checked before referencing the thread object. This fixes the remaining test failure.
2021-05-02 12:46:55 +02:00
Serge Gautherie 249f2388bd
[REACTOS] Fix parameter types on some exports (#3217)
Fix some wrong parameter types on some exports in NTDLL, KERNEL32, WTSAPI32, and NTOSKRNL.
2021-05-01 21:11:34 +02:00
Serge Gautherie 5d89643311 [NTOS:OB] ObQueryDeviceMapInformation(): Fix annotations 2021-05-01 11:26:07 +02:00
Serge Gautherie 8a61e4f08c [NTOS:PS] NtQueryInformationProcess(): Fix ProcessDeviceMap case
Fix Clang-Cl
'...\ntoskrnl\ps\query.c(583,33): warning: variable 'Status' is uninitialized when used here [-Wuninitialized]'

Addendum to 1074a9a.
2021-04-29 21:40:58 +02:00
Serge Gautherie c0961cac10 [NTOS:PS] NtQueryInformationProcess(): Sync' annotations 2021-04-29 21:40:58 +02:00
Jérôme Gardou b97d5fd2f7 [NTOS:KDBG] Fix invalid DBG print 2021-04-28 15:58:01 +02:00
Jérôme Gardou 3726b992ed [NTOS:KDBG] Begin port for amd64.
Not really functional, but it prints debug output.
Take this as an opportunity to add consistancy between some i386 & amd64 intrinsics
2021-04-28 13:10:23 +02:00
Jérôme Gardou 5e29e98f91 [NTOS:KE] Explicitly use sysretq instruction 2021-04-28 13:10:23 +02:00
Jérôme Gardou 662774bca3 [NTOS] Do not force-align an integer value 2021-04-28 13:10:23 +02:00
George Bișoc 44fb528fcc
[NTOS:SE] Implement the NtImpersonateAnonymousToken system call
Implement SepImpersonateAnonymousToken private helpers, which is necessary for the complete implementation of NtImpersonateAnonymousToken function and thus finally we're able to impersonate the anonymous logon token.
2021-04-27 12:25:03 +02:00
George Bișoc 12c69e6d63
[NTOS:SE] Add the declaration prototype of SepRegQueryHelper in the internal header 2021-04-27 12:25:03 +02:00
George Bișoc b68216e503
[NTOS:SE] Annotate the function parameters of SepRegQueryHelper with SAL
And add a documentation comment header
2021-04-27 12:25:03 +02:00
George Bișoc f9c603db6e
[NTOS:OB] Do not close the handle if it's granted access to ObpAccessProtectCloseBit
As of now the Object Manager private service, ObpCloseHandleTableEntry, looks for OBJ_PROTECT_CLOSE attribute if a handle should not be closed. However, in ObDuplicateObject if an attribute of OBJ_PROTECT_CLOSE is found as it's been filled to the caller (see L2466) this attribute is removed from the attributes list of the new handle and ObpAccessProtectCloseBit access is granted to the newly duplicated object handle.

With that being said ObpCloseHandleTableEntry indiscriminately closes the object handle albeit it shouldn't do so. As a matter of fact in Windows Server 2003 SP2 this service indeed checks for ObpAccessProtectCloseBit flag bit and if the condition is met then it returns STATUS_HANDLE_NOT_CLOSABLE as it should. Therefore we should do the same.

Now NtClose can properly warn the calling thread the object handle can't be closed which fixes a testcase failure within NtDuplicateObject NTDLL APITEST where this function gives handle close protection bit as requested by the caller.
2021-04-26 19:36:38 +02:00
Serge Gautherie 710acab83d [NTOS:MM] MiSetPagingOfDriver(): Add an explicit #if around unreachable code 2021-04-26 10:27:20 +02:00
George Bișoc 3d8dd932b1
[NTOS:SE] Lock the token in SeQueryInformationToken and do some cleanup
* Guard the token in a lock whilst querying stuff
* Remove the piece of code that checks if the information class provided is above the maximum information class threshold. That code literally duplicates the inner functionality of the default case in the switch block, where the code falls in that case if an invalid information class is provided anyway.
* Remove the redundant information classes. Internally, this function in Windows has 12 switch case blocks (11 token info classes + the default case) and the other classes are supported in NtQueryInformationToken only so it doesn't make any logical sense to keep them in the codebase.
* Annotate the argument parameters with SAL and add documentation header
2021-04-18 13:56:37 +02:00
Hermès Bélusca-Maïto 3ad573f92f
[NTOS:KE] Both KeFindConfigurationEntry() and KeFindConfigurationNextEntry() functions are exported by NTOSKRNL, so they definitively must NOT be in the discardable INIT section!!
Noticed while reviewing c7d1ff4a.
2021-04-10 00:43:52 +02:00
Victor Perevertkin f3e1697c2b
[NDK] DATA_SEG requires an extra #pragma on MSVC 2021-04-09 04:38:35 +03:00
Jérôme Gardou c48580135d [NTOS:MM] Fix a bit page fault handler with regard to COW sections 2021-04-08 15:40:37 +02:00
Jérôme Gardou a34d9bcfb6 [NTOS:MM] Share "page.c" between i386 & amd64 builds 2021-04-08 15:40:37 +02:00
Jérôme Gardou 7ea8312617 [NTOS:MM] Split MmCreateProcessAddressSpace in two parts
Generic one and arch-specific one.
Properly fail if we are out of resources.
Restore a lost assert.
2021-04-08 15:40:37 +02:00
Jérôme Gardou 6c027d28f9 [NTOS:MM] Properly track system process hyper space PDE page 2021-04-08 15:40:37 +02:00
Jérôme Gardou 370982aa1d [NTOS:MM] Make i386/page.c usable for all x86 variants
This includes PAE & amd64
2021-04-08 15:40:37 +02:00
Jérôme Gardou b10d92a16c [NTOS:MM] Use MI_MAKE_HARDWARE_PTE & friends in legacy Mm 2021-04-08 15:40:37 +02:00
Jérôme Gardou 43378411fb [NTOS:MM] Rewrite arch-specifics of the legacy Mm
Properly handle PDE refcounting
Clean-up of the internal API
Enforce attaching to the process when modifying its memory layout, instead of
making circonvoluted mappings which always end up being broken.
2021-04-08 15:40:37 +02:00
Jérôme Gardou b445005c70 [NTOS:MM] Get rid of MmRosFlushVirtualMemory
It's not used anywhere now, and it will eventually be gone
2021-04-08 15:40:37 +02:00
Jérôme Gardou 9e121fb6c2 [NTOS:MM] Get rid of MmSetCleanAllRmaps and MmIsDirtyPageRmap
Everything is wrong with them. Bad locking. Bad logic.
2021-04-08 15:40:37 +02:00
Jérôme Gardou 7bffb92099 [NTOS:MM] Let ARM3 handle invalid PDE for itself. 2021-04-08 15:40:37 +02:00
Jérôme Gardou 36a92e6ea5 [NTOS:MM] Fix a bit the page-out/page-in logic
- Do not lock the section segment when we are serving a fault for a process private page.
 - Do not keep the process address space lock while writing to pagefile.
 - Do not wait for an event that might never be set.
2021-04-08 15:40:37 +02:00
Jérôme Gardou 82c908195c Revert "[NTOS:MM] Allow MiMapPageInHyperSpace to be called from DISPATCH_LEVEL"
This reverts commit 8404d1a6ff.
Not ready for prime time, sorry.
2021-04-07 23:26:44 +02:00
Jérôme Gardou 8404d1a6ff [NTOS:MM] Allow MiMapPageInHyperSpace to be called from DISPATCH_LEVEL
Also annotate it to show its behaviour.
2021-04-07 23:09:26 +02:00
Oleg Dubinskiy 52f4d8019b [NTOS:MM][NTOS:SE] Mute some noisy stubs
Mute debug prints of MmDoesFileHaveUserWritableReferences and SeAuditingFileEventsWithContext stubs.
These stubs are very noisy and create a lot of spam in the log when using Microsoft NTFS driver in ReactOS (with some other improvements applied).
Implementing those functions isn't badly required for the proper work of this driver, so better way for now is just mute these stubs a bit.
After my changes, they will be displayed only once, and the log will be more clear, so it will seem to be enough to understand that the driver calls these routines.
CORE-17409
2021-04-07 13:16:03 +02:00
Jérôme Gardou 0d3825862f [NTOS:KE] Rewrite KiSystemCallTrampoline in assembly
Instead of making assumptions about what the compiler does with forced-inline functions
2021-04-06 17:57:18 +02:00
Eric Kohl d8c38c4b4c [NTOS:PNP] PiSetDevNodeText: Do not overwrite existing DeviceDesc values
CORE-17513
2021-04-05 14:33:48 +02:00
Mark Jansen 5e928e5c92
[NTOS:MM] Stubplement cookie generation for drivers 2021-04-03 18:08:53 +02:00
Eric Kohl c449929fef [NTOS:EX] Use RtlCutoverTimeToSystemTime to determine the current time zone id
CORE-14658
2021-04-03 09:38:07 +02:00
Jérôme Gardou 998870c5ea [NTOS:MM] Properly fail for invalid sizes of data section mappings 2021-03-30 22:20:15 +02:00
Jérôme Gardou 4c731adc04 [NTOS:MM] Fix compilation when PFN tracing is enabled 2021-03-30 17:22:09 +02:00
Jérôme Gardou 80f8beeeee [NTOS/MM] Remove an outdated check 2021-03-30 17:13:19 +02:00
Jérôme Gardou 0187c1e113 [NTOS:MM] Fix PFN tracing 2021-03-30 16:26:43 +02:00
George Bișoc eba68ffb9c [NTOS:SE] Specify the code section of SepCreateSystemProcessToken as INIT
This function is used during the Security kernel module phase initialisation to set up the system process token which the phase initialisation procedure in itself is stored in the INIT section. With that being said, do the same for SepCreateSystemProcessToken too and add a header documentation as an addition.
2021-03-25 02:30:46 +03:00
George Bișoc 5b5b814af8 [NTOS:SE] Create the anonymous logon tokens on Security initialisation phase 2021-03-25 02:30:46 +03:00
George Bișoc fe0f9d8646 [NTOS:SE] Implement SepCreateSystemAnonymousLogonToken and SepCreateSystemAnonymousLogonTokenNoEveryone functions
These private functions are needed to set up two different kinds of system's anonymous logon tokens: one that includes everyone in the group and the other that doesn't. These functions are needed as next step closer to the
implementation of NtImpersonateAnonymousToken system call.
2021-03-25 02:30:46 +03:00
George Bișoc b28530d4ac [NTOS:SE] Set up an ACL and SD for the anonymous logon 2021-03-25 02:30:46 +03:00
Jérôme Gardou 6e4f83da70 [NTOS:CC] Wake up lazy scan after inserting elements in the list. 2021-03-24 15:28:04 +01:00
Jérôme Gardou edd4a985d9 [NTOS:CC] Be verbose about why we defer writes 2021-03-24 15:27:36 +01:00
Jérôme Gardou 5c54fb9179 [NTOS:CC] Rewrite CcPostDeferredWrites
This allows to post small writes if there are any, and avoid holding the list lock for a long time.
2021-03-24 11:22:28 +01:00
Jérôme Gardou b13a696513 [NTOS:KE] Explicitly cast -1 to ULONG 2021-03-24 11:13:04 +01:00
Jérôme Gardou 94d175b7f2 [NTOS] Remove a definition which is redundant with ndk 2021-03-24 11:12:12 +01:00
Jérôme Gardou 187ca32175 [NTOS:KE] Use PNT_TIB as argument in KeSetTebBase 2021-03-24 11:09:20 +01:00
Jérôme Gardou 173cdcae8f [CMAKE] Use the "kernel" module type for ntoskrnl and ntkrnlmp 2021-03-23 11:18:43 +01:00
Jérôme Gardou d1d1260f5f [NTOS:MM] Fix integer arithmetics 2021-03-22 10:02:12 +01: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
Jérôme Gardou 42094071ee [NTOS:MM] Silence noisy DPRINTs 2021-03-18 12:24:21 +01:00
Jérôme Gardou 4ff5d39edb [NTOS:MM] Use a define for the big pool table occupation rate 2021-03-18 12:24:21 +01:00
Jérôme Gardou 8494688eeb [NTOS:MM] Do not use atomic operations to set a bit while holding a lock.
Saving your fingers from typing it doesn't make it better code.
2021-03-18 12:24:21 +01:00
Jérôme Gardou f06b58925d [NTOS:MM] Implement shrinking big pool allocation table
Shrink when using 1/8 of its allocated capacity (thus use 25% of it at the end of the process)
Expand when using 3/4 of its allocated capacity (thus use ~40% of it at the end of the process)
2021-03-18 12:24:21 +01:00
Jérôme Gardou 54354712e2 [NTOS:MM] Fail allocating non-paged pool when running out of available pages 2021-03-18 12:24:21 +01:00
Jérôme Gardou 34630a06ca [NTOS:MM] Do not bugcheck when we are freeing a big allocation for which we didn't manage to insert the tag 2021-03-18 12:24:21 +01:00
Jérôme Gardou d5fa0788d8 [NTOS:MM] Silence a DPRINT which became noisy 2021-03-16 13:23:21 +01: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
Serge Gautherie e0400e7810 [NTOS:KE] KiIdleLoop(): Propagate DECLSPEC_NORETURN to callers 2021-03-05 00:43:15 +03:00
Serge Gautherie 5f1d79f0c5 [NTOS:KE] KiIdleLoop(): Add DECLSPEC_NORETURN, Remove FASTCALL 2021-03-05 00:43:15 +03:00
George Bișoc 44b8e5caac [NTOS:SE] Complete the SepCompareTokens implementation
* Implement SepCompareSidAndAttributesFromTokens and SepComparePrivilegeAndAttributesFromTokens functions for array elements comparison
* Implement the token comparison code in SepCompareTokens function
* Add a missing PAGED_CODE() in SepCompareTokens as most of the token comparison code is paged
* Use SAL annotations for SepCompareTokens and NtCompareTokens
2021-03-04 16:22:56 +03:00
George Bișoc a340ec1767
[NTOS:PS] Guard the quota in a spin lock (#3419)
Prior to acquiring a quota from the process and do whatever it's needed to do (charge it or return it back), we must guard ourselves with a spinlock so that we may not get into potential race conditions. In Windows Server 2003, PspGivebackQuota and PspExpandQuota do the same thing and they're the equivalent to PspReturnProcessQuotaSpecifiedPool and PspChargeProcessQuotaSpecifiedPool in our codebase.
2021-03-04 04:43:30 +03:00
Serge Gautherie 7851ad8635 [NTOS:KD] KdpDebugLogInit(): Close the thread handle
Addendum to 07dc415 (r43331).
2021-03-03 09:01:37 +01:00
Serge Gautherie 802ad6d3ee [NTOS:KD] KdpLoggerThread(): Assert being in kernel mode
to be explicit that using Nt*() is safe.

Follow-up to 9537653.
2021-03-03 09:01:37 +01:00
George Bișoc 6170b574f0
[NTOS:PS] Implement PS_QUOTA_TYPE and let the quota code use it (#3389)
This will replace the PoolIndex variable and as such we'll only be using the PS_QUOTA_TYPE enumeration, as Windows does. Both QuotaEntry, QuotaUsage and QuotaPeak depend explicitly or implicitly on this enumeration. Further details about this enum can be found in the following articles.
https://www.geoffchappell.com/studies/windows/km/ntoskrnl/api/ps/psquota/type.htm?tx=68,143
https://www.geoffchappell.com/studies/windows/km/ntoskrnl/api/ps/psquota/block.htm?tx=68,142,143
https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/ps/eprocess/index.htm (see QuotaPeak and QuotaUsage)
2021-03-02 20:09:58 +01:00
Jérôme Gardou 4e4c47cccc [NTOS:KE] Generate proper frame info for trap handler in GCC builds
CORE-8531
2021-03-02 14:37:39 +01:00
Jérôme Gardou 7caf9e9d48 [NTOS:KD] Use Zw* syscall variants
The log file can be (re-)initialized when previous mode is User-Mode,
thus the calls fail on probing input parameters
2021-02-26 08:46:53 +01:00
Jérôme Gardou a93e065ebc [NTOS:MM] Do not chunk-read file when we are the modified-page-writer thread 2021-02-26 08:46:53 +01:00
Jérôme Gardou 35c091adaf [NTOS:MM] Do not chunk-read files marked with FO_RANDOM_ACCESS 2021-02-26 08:46:53 +01:00
Eric Kohl 9ff015f770 [NTOS:CM] Report key creation to the notify code 2021-02-21 15:49:06 +01:00
Jérôme Gardou 2a962eaf8c [NTOS:CC] Keep a reference on the shared cache map of the file when we are in lazy write
This should fix "Leaking VACB" debug prints
2021-02-19 15:48:31 +01:00
Jérôme Gardou d18634c026 [NTOS:WMI] Be consistent about potential NULL pointer use 2021-02-18 10:24:53 +01:00
Serge Gautherie 17a9041da1 [NTOS:WMI] IoWMIWriteEvent(): Add WNODE_FLAG_TRACED_GUID case
Addendum to d5f8964 (r23040).
CORE-17384
2021-02-17 18:59:09 +01:00
Serge Gautherie 495e22e0d5 [NTOS:WMI] IoWMIWriteEvent(): Fix annotation, Extend DPRINT1()
CORE-17384
2021-02-17 18:59:09 +01:00
Timo Kreuzer 4b4bff0642 [NTOS:MM] Handle demand zero PTEs with MM_EXECUTE_READWRITE and MM_READWRITE 2021-02-16 18:02:57 +01:00