Commit graph

1397 commits

Author SHA1 Message Date
George Bișoc 982ee872dd
[NTOS:SE] Privileges adjusting private routine must be paged
SepAdjustPrivileges is a private helper call that must be paged, alongside with its syscall -- NtAdjustPrivilegesToken.
2021-09-21 17:40:53 +02:00
Victor Perevertkin 62d1a2c884
[CMAKE] Fixes for clang-cl build
- User lib.exe instead of llvm-lib due to incompatibility
- Avoid wrapping resource compiler with cmcldeps
- Fix several conditional flags
2021-09-14 17:58:23 +03:00
Hermès Bélusca-Maïto 9393fc320e
[FORMATTING] Remove trailing whitespace. Addendum to 34593d93.
Excluded: 3rd-party code (incl. wine) and most of the win32ss.
2021-09-13 03:52:22 +02:00
Hermès Bélusca-Maïto 9b1edceae1
[REACTOS] Fix some instances of DPRINTs with trailing whitespace before newlines. 2021-09-13 03:52:19 +02:00
Hermès Bélusca-Maïto 6e9ff14e26
[NTOS:KD64,KE] IRQL is automatically adjusted during calls to KdEnterDebugger() and KdExitDebugger(). (#3942)
Addendum to 608032bd and 835c3023.

The IRQL is actually raised by KeFreezeExecution() and lowered by
KeThawExecution(), always to HIGH_IRQL on MP systems, or if necessary
on UP. These functions are called respectively by KdEnterDebugger()
and KdExitDebugger().
2021-09-12 18:20:32 +02:00
Hermès Bélusca-Maïto 05590079cc
[NTOS:KD64] First unlock the KD port then lower the IRQL, instead of doing the reverse. (#3942)
This properly reverses the operation of first raising the IRQL before
locking the KD port.
2021-09-12 18:19:59 +02:00
Hermès Bélusca-Maïto c9f335e996
[NTOS:KD64] KdPollBreakIn(): Use the KeRestoreInterrupts() inline. 2021-09-12 18:16:13 +02:00
George Bișoc fc5bc55fbb
[NTOS:SE] Use the captured security descriptor when access checking
When performing access security check, use the security descriptor that we've captured it to determine based on that descriptor if the client can be granted access or not.
2021-09-12 16:07:44 +02:00
George Bișoc d7255f1584
[NTOS:SE] Explicitly check the auto inherit flags right away
As we now have the SEF_* flags declared within the SDK we can simply check for such flags directly wihout having to check for the hard-coded flag values.
2021-09-09 19:29:53 +02:00
Stanislav Motylkov 3f4c98a425
[ARM] Fix some compilation errors for ARM
CORE-17634 CORE-17604
2021-09-09 19:40:20 +03:00
Hermès Bélusca-Maïto 4795d953c0
[NTOS:IO] Fix an ASSERT. Addendum to commit 1fd730b7. 2021-09-06 01:05:14 +02:00
Hermès Bélusca-Maïto fe9ac14aa3
[NTOS] Move two CODE_SEG("INIT") to a better place. 2021-09-05 21:22:45 +02:00
Hermès Bélusca-Maïto 1fd730b781
[NTOS:IO] IopInitializeDriverModule(): Set the DRVO_LEGACY_DRIVER flag if the driver is not WDM. (#3749) 2021-09-05 20:31:08 +02:00
George Bișoc c407460f6a
[NTOS:SE] Implement effective token option upon duplication
This implements the EffectiveOnly option of SepDuplicateToken routine (used by NtDuplicateToken syscall and other functions alike) which makes the access token effective by removing the disabled parts like privileges and groups.
2021-09-05 17:01:21 +02:00
George Bișoc 84f7bee18f
[NTOS:SE] SepSinglePrivilegeCheck doesn't expect a NT status code value
Fix a wrong returned datatype of the function, as SepSinglePrivilegeCheck calls the internal private SepPrivilegeCheck function which returns a BOOLEAN value.
2021-08-22 11:31:57 +02:00
George Bișoc 8567d8145e
[NTOS:SE] Annotate the remaining functions with SAL 2021-08-22 10:29:58 +02:00
George Bișoc 6413009c10
[NTOS:SE] Document the whole subsystem in Doxygen format
And update the file comment headers.
2021-08-22 10:29:47 +02:00
Victor Perevertkin 6ef6fabfc5
[FREELDR][NTOS][HALPPC][SDK] Remove PowerPC code
Remove PowerPC-related code from the kernel, HAL, SDK and
Freeloader.
2021-08-15 15:35:51 +03:00
James Tabor a81ad376a1 Check for PAE
Checking for PAE and set some logic later to support it.
2021-08-08 20:37:06 -05:00
Jérôme Gardou 589016ddb9 [NTOS:MM] Implement MmFlushImageSection(MmFlushForWrite) 2021-08-07 09:34:58 +02:00
Jérôme Gardou 6618d978cd [CMAKE] Do not disable optimisations on ntoskrnl build 2021-08-06 15:17:49 +02:00
Jérôme Gardou acf28dbc1e [NTOS:MM] Fix the mess created by the "balancer thread"
When processing:
  Make sure that the process is not terminating.
  Make sure that the process WorkingSet is still valid
  Protect accessing & writing to PTEs by acquiring the working set lock

CORE-17595 CORE-17642
2021-08-05 10:06:19 +02:00
Jérôme Gardou 676dc4b441 Revert "[NTOS:MM] Do proper checks & acquire proper locks when sweeping user pages"
This reverts commit 7c006df7e0.
Note to self: This is what happens when you have too many branch and push the wrong one.
2021-08-04 23:57:39 +02:00
Jérôme Gardou 7c006df7e0 [NTOS:MM] Do proper checks & acquire proper locks when sweeping user pages
CORE-17595
2021-08-04 20:38:37 +02:00
Jérôme Gardou 789d7a7741 [NTOS:MM] When mapping pages for zeroing them, disable cache, enable write through
Idea from Thomas Faber
2021-08-04 17:48:39 +02:00
Jérôme Gardou 98e62b9bca [NTOS:MM] In page zeroing thread, zero more than one page at a time. 2021-08-04 17:48:39 +02:00
Jérôme Gardou e98de5ef1f [NTOS:MM] Use KeZeroPages in zeroing thread 2021-08-04 17:48:39 +02:00
Jérôme Gardou 708dc6b7d6 [NTOS:MM] Do not zero-fill pages when not needed 2021-08-04 17:48:39 +02:00
Jérôme Gardou 42bec35f65 [NTOS:KE] Also rewrite KeZeroPages in assembly for amd64
Let's stick with "rep movsq" until we are able to have more precise benchmarks
2021-08-04 17:48:39 +02:00
Jérôme Gardou 51258295bd [NTOS:KE] Rewrite KeZeroPages in assembly
We spend a lot of time in this function, let's optimize it.
2021-08-04 17:48:39 +02:00
Jérôme Gardou 34662e2f6f [NTOS:MM] Copy the WorkingSet page when initializing "hand-built" process
CORE-17642
2021-08-04 11:49:38 +02:00
Jérôme Gardou be6a6b806a [NTOS:MM] Remove dead code 2021-08-03 10:57:12 +02:00
Victor Perevertkin 5176f580e5
[CMAKE] Add memcmp to libntoskrnl for both clang and clang-cl 2021-08-02 20:23:22 +03:00
George Bișoc 632fa1cfbe
[NTOS:SE] Handle the reference logon session of the token
When creating or duplicating an access token object, make sure that the logon session is getting referenced by the token must be inserted onto the logon reference member (a.k.a LogonSession) for proper logon session referencing tracking.

Also when a token object is about to be destroyed or that we are taking away a reference session from it, we must ensure that the referenced logon session data gets removed from the token in question.
CORE-17700
2021-07-31 17:23:05 +02:00
George Bișoc 5e51f8dad2
[NTOS:SE] Implement logon reference insertion/removal to tokens 2021-07-31 16:11:03 +02:00
George Bișoc 7692c10527
[NTOS:SE] Unify all the SRM tags in one place
And rename SEP_LOGON_SESSION_TAG and SEP_LOGON_NOTIFICATION_TAG to TAG_LOGON_SESSION and TAG_LOGON_NOTIFICATION respectively.
2021-07-31 16:10:50 +02:00
Jérôme Gardou b0dfe20981 [NTOS:MM] Fix MiIsUserPte inline 2021-07-30 18:54:54 +02:00
Jérôme Gardou ce65553eaa [NTOS:MM] Annotate some functions with regards to MmPfnLock
Also fix MI_ASSERT_PFN_LOCK_HELD macro.
Now in debug builds, SpinLocks are always non-zero when held.
2021-07-27 15:36:55 +02:00
Jérôme Gardou 6150dc994a [NTOS:MM] Always release PFN lock in MmDereferenceSegmentWithLock
All callers release it after calling it.
CORE-17698
2021-07-27 15:36:55 +02:00
George Bișoc e2a8585edc
[NTOS:SE] Remove redundant commented call on token duplication
When duplicating an access token, the authentication ID is already copied from the existing token to the new one anyway so there's no point on having the commented call still left in the code.
2021-07-25 18:02:32 +02:00
Timo Kreuzer a3763c61dc [PSDK][NDK] Use hex to define MIN/MAX constants like in native SDK
This fixes use of unary minus operator on unsigned type warning.
2021-07-23 22:03:48 +02:00
Hervé Poussineau ad370238d7 [NTOS:PS] Support using QUOTA_LIMITS_EX in NtSetInformationProcess(ProcessQuotaLimits)
Both QUOTA_LIMITS and QUOTA_LIMITS_EX are already supported in PspSetQuotaLimits,
but this was broken by a330b56787
2021-07-15 19:33:45 +02:00
George Bișoc 506cee3219 [NTOS:SE] Implement logon session termination notification
Note to SELF and EVERYONE: the commit implements the initial logon session termination notification implementation, the SeMarkLogonSessionForTerminationNotification function, but as it currently stands there are several other tasks to be addressed in the future in order for the logon termination notification to be fully completed. The tasks as of which are.

1. Our SepRmDereferenceLogonSession is not fully implemented, as it doesn't inform the LSA and filesystems of logon deletion notification
2. Implement two worker routines that are actually in charge of such tasks of informing LSA and FSDs
3. Perform logon deletion
4. Do further investigations and check whatever that is left to address, if any
2021-07-15 19:31:46 +02:00
Timo Kreuzer 47372e2ac9 [NTOS:MM] Fix MiSetSystemCodeProtection
CORE-16387 CORE-17638
Windows only makes the header RO for session space mapped drivers (win32k, dx and display drivers)
2021-07-11 21:43:07 +02:00
George Bișoc 7fb0d13a46
[NTOS:SE] Move SQOS capturing in its own file
* Quality of service kernel stuff bears nothing with security descriptors in anyway, so just have a file specifically for it
* Annotate the function arguments parameters with SAL
* Document the functions
2021-07-05 09:39:06 +02:00
George Bișoc ff0a325116
[NTOS:SE] Allocate pool memory for security descriptor based on the caller pool type request
We're indiscriminately allocate the pool as non paged all the time, thus further ignoring the pool type parameter of the function.
2021-07-04 11:01:54 +02:00
Oleg Dubinskiy 94054a5735 [NTOS:IO] OpenRegistryHandlesFromSymbolicLink: Use REG_OPTION_NON_VOLATILE
Use REG_OPTION_NON_VOLATILE instead of REG_OPTION_VOLATILE in all ZwCreateKey calls of OpenRegistryHandlesFromSymbolicLink, since the keys created/opened by this function, should be non-volatile (in other words, be saved after reboot).
Also Device Parameters subkey that is created in IoOpenDeviceInterfaceRegistryKey (which uses that routine as well), is non-volatile too, so the parent keys whose contain it, cannot be volatile.
It will fix an error with status 0xc0000181 (STATUS_CHILD_MUST_BE_VOLATILE) occuring during loading kernel mode audio drivers from Windows XP/2003, especially checked (debug) versions, with my IoGetDeviceInterfaceAlias implementation. Also it may fix other error cases.
CORE-17361
2021-07-03 21:44:33 +02:00
George Bișoc c869c4778d
[NTOS:SE] Assign the control flag bits to the newly created security descriptor
We allocate memory pool for a new security descriptor with specific info filled by the caller but we don't set the control flag bits for the newly allocated descriptor, which is wrong. Originally spotted by Vadim Galyant.
CORE-17650
2021-07-03 17:20:48 +02:00
Jérôme Gardou 37d0a9c3f4 [NTOS:KE] Unconditionally check IRQL when acquiring & releasing spinlock at DISPATCH_LEVEL 2021-06-29 11:49:20 +02:00
Jérôme Gardou f30136bc79 [NTOS:KE] Test spinlock ownership on both UP & MP build
There is no reason not to, and this avoids introducing bugs stupidly.
2021-06-29 11:49:20 +02:00
Jérôme Gardou 835c30232e [NTOS:KD][NTOS:KD64][NTOS:KDBG] Fix IRQL & spinlock use
KD64: Raise to HIGH_LEVEL when entering trap
KDBG: lower to DISPATCH_LEVEL when applying IRQL hack & use a worker thread to load symbols
KD&KDBG: Actually unload symbols when required
2021-06-29 11:49:20 +02:00
Jérôme Gardou 79c2972035 [NTOS:KD] Release lock before calling KdpPrint
Avoiding resursive spinlock acquisition
2021-06-29 11:49:20 +02:00
Jérôme Gardou 608032bd08 [NTOS:KD64][NTOS:KDBG] Fix spinlocks use
Raise IRQL before entering debugger, so that KeAcquireSpinLockAtDpcLevel works as expected.
 - HIGH_LEVEL since we don't know where we are coming from.

Do not try to read debug symbol from files in KDBG.
 - There is no reason that this works if Mm didn't map it in the first place.
2021-06-29 11:49:20 +02:00
Jérôme Gardou 66dea86d68 [NTOS:KDBG] Use internal KdpDPrintf instead of DbgPrint
DbgPrint is implemented through a breakpoint, and then KD tries to recursively
lock its own spinlock. Call a lower level routine instead.
2021-06-29 11:49:20 +02:00
Jérôme Gardou e312a40ae2 [NTOS:KE] Implement KeAcquireInStackQueuedSpinLockForDpc & KeReleaseInStackQueuedSpinLockForDpc 2021-06-29 11:49:20 +02:00
Jérôme Gardou 91587a432b [NTOS:MM] Fix another instance of reentrant spinlock acquisition 2021-06-29 11:49:20 +02:00
Victor Perevertkin 1c7f3476a0
[CMAKE] Use BUILD_MP CMake option correctly 2021-06-28 17:54:09 +03:00
Jérôme Gardou d1f5c31820 [SDK] Add GCC overrides for SAL annotations
GCC has some functions, variables & type attributes which can be used as aliases
for some of the SAL annotations. Although it's not as rich & precise, it's still useful
since we actually enable -Werror on GCC builds whereas we don't use such an option
on MSVC builds.

For now, _Must_inspect_result_ is aliased to warn_result_unused attribute.
2021-06-28 10:20:57 +02:00
Jérôme Gardou 46af941c4c [NTOS:FSRTL] Check return status of FsRtl locking functions
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou d924cb8271 [NTOS:CONFIG] Do not ignore Rtl*String functions return value
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou 3ad38f29b5 [NTOS:OB] Use RtlInitUnicodeString for constant string
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou 8178996559 [NTOS:SE] Do not ignore SepAccessCheckAndAuditAlarmWorker return value
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou 07d38cd4c5 [NTOS:PO] Do not ignore IoRegisterPlugPlayNotification return value
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou 230e6b9492 [NTOS:INBV] Do not ignore RtlUnicodeStringToOemString return value
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou 838abc475c [NTOS:IO] Do not ignore RtlDuplicateUnicodeString return value
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou cf1a95a588 [NTOS:EX] Do not ignore PsCreateSystemThread return value
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou 93c0d324e0 [NTOS:EX] Do not ignore RtlAnsiStringToUnicodeString return value
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou 376fbc5242 [NTOS:MM] Check result of RtlCreateUnicodeString in MmGetFileNameForAddress
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou 3f16c8615c [NTOS:IO] Check RtlCreateUnicodeString return value when initializing PnP services
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou 24a4e12a76 [NTOS:IO] Check RtlAnsiStringToUnicodeString return value when initializing Arc names
CORE-17637
2021-06-28 10:20:57 +02:00
Jérôme Gardou 293f823053 [NTOS:IO] Check RtlAnsiStringToUnicodeString return value when initializing ramdisk
CORE-17637
2021-06-28 10:20:57 +02:00
George Bișoc 2791ecd303
[NTOS:PS] Fix several issues within info classes in AMD64 build
ProcessUserModeIOPL, ProcessWow64Information and ThreadZeroTlsCell classes fail on AMD64 build because of wrong IQS values assigned to them. Also explicitly tell the compiler that ProcessUserModeIOPL is strictly for x86 as user mode I/O privilege level is 32-bit stuff.
In addition to that, implement IQS_NO_TYPE_LENGTH macro which it'll be used for classes such as ProcessUserModeIOPL where type length is not required and that it should be 0. With that said, we indirectly fix a size length mismatch issue with ProcessUserModeIOPL on 32-bit of ReactOS as well.
2021-06-25 10:33:18 +02:00
Jérôme Gardou 59cddd15e2 [NTOS:MM] Implement MmFlushImageSection(MmFlushForDelete)
CORE-17544
2021-06-25 10:28:51 +02:00
Jérôme Gardou b3e9c89725 [NTOS:MM] Simplify refcounting when adding/deleting a page in a shared segment
CORE-17544
2021-06-25 10:28:51 +02:00
Jérôme Gardou bec42b6530 [NTOS:MM] Do not call ExAllocatePool* with PFN lock acquired
Unsurprisingly, it actually might acquire it
2021-06-25 10:28:51 +02:00
Jérôme Gardou aa2697df2d [NTOSKRNL] Enforce -fno-common on GCC & CLang builds 2021-06-24 18:48:31 +02:00
Jérôme Gardou c6e9fea844 [NTOSKRNL] Deduplicate some symbols 2021-06-24 18:48:31 +02:00
Jérôme Gardou 1c5ce8d11c [NTOS:MM] Fix-up call site of traced PFNs when serving a page fault 2021-06-24 18:48:31 +02:00
Jérôme Gardou 146337cc50 [NTOS:MM] Save caller address when tracing PFNs 2021-06-24 18:48:31 +02:00
Jérôme Gardou c8ce0cc434 [NTOS:MM] Fix one occurrence of MiDeletePte instead of MiDeletePde 2021-06-22 12:05:20 +02:00
Serge Gautherie c2e454b439 [NTOS:CC] CcRosFlushVacb(): Fix Iosb annotation
Addendum to 2ba1926.
2021-06-22 10:33:45 +02:00
Serge Gautherie eab2bb4b20 [NTOS:MM] MmFlushSegment(): Fix Iosb annotation
Addendum to 90c6a65.
2021-06-22 10:33:45 +02:00
Jérôme Gardou 41de1bd724 [NTOS:KE] Do not allow waiting at IRQL >= DISPATCH_LEVEL when providing a timeout in KeWaitForMultipleObjects
CORE-6473
2021-06-21 11:42:01 +02:00
Timo Kreuzer b627352815 [NTOS][SETUP] Add x64 SMP kernel and make SMP the default boot mode on x64 2021-06-19 12:17:18 +02:00
Timo Kreuzer 396167bc7e [NTOS:MM] Improve an ASSERT 2021-06-19 12:17:18 +02:00
Timo Kreuzer 33949028fb [NTOS:MM] Fix PFN lock usage 2021-06-19 12:17:18 +02:00
Timo Kreuzer f4d47faeb7 [NTOS:KE] Fix usage of KTHREAD::SwapBusy 2021-06-19 12:17:18 +02:00
Timo Kreuzer a011d19ed2 [NTOS:KE] Fix some locking issues 2021-06-19 12:17:18 +02:00
Timo Kreuzer 62f62da8ba [NTOS:KE] Fix KxReleaseSpinLock for 64 bit SMP builds 2021-06-19 12:17:18 +02:00
Timo Kreuzer 2ed56fa794 [NTOS] Fix build with CONFIG_SMP 2021-06-19 12:17:18 +02:00
Timo Kreuzer e6fa62a8d2 [NTOS:MM/x64] Fix Interlocked(Compare)ExchangePte and PAGE_FROM_SSE for x64
This fixes using PFNs with more than 20 bits.
2021-06-19 12:01:24 +02:00
George Bișoc 5912c11650
[NTOS:SE] Minor refactor on NtOpenThreadTokenEx
- Remove a redundant call of ObReferenceObjectByHandle. Not only it didn't make much sense (we reference the object from thread handle and the new thread object referencing the same handle!), specifying a request access of THREAD_ALL_ACCESS for the thread object is kind of suspicious and all of these access rights are unwanted.
- Add some failure checks involving the CopyOnOpen code paths
- Add some DPRINT1 debug prints (concerning the CopyOnOpen code paths as usual)
2021-06-18 18:38:12 +02:00
Hermès Bélusca-Maïto 4864c874a2
[NTOS:IOPNP] Both PNP_PROPERTY_REMOVAL_POLICY_OVERRIDE and PNP_PROPERTY_LOCATION_PATHS are unimplemented, return such status.
Fixes CID 1441387: Uninitialized scalar variable (UNINIT),
in the case of PNP_PROPERTY_LOCATION_PATHS.
2021-06-17 00:35:22 +02:00
Hermès Bélusca-Maïto f2645e48b9
[NTOS:IO] Comment out (and explain why it is there) an unused LdrEntry assignment in IopInitializeBootDrivers(). CID 1237114 2021-06-17 00:35:22 +02:00
Hermès Bélusca-Maïto fe416b67dc
[NTOS:IO] Revert part of commit a82ff90b2: don't do direct ULONG data access: it might be unaligned.
Requested by Victor.
2021-06-17 00:35:21 +02:00
Hermès Bélusca-Maïto 32a82eb123
[NTOS:IO] Fix driverName.Buffer leak in some failure paths in IopGetDriverNames().
driverName.Buffer leaked when the "(!NT_SUCCESS(status) || ServiceName != NULL)"
case is taken because ServiceName != NULL, and some of the functions fail.
2021-06-16 22:18:02 +02:00
Hermès Bélusca-Maïto e09d1dec7a
[NTOS:IO] Fix basicInfo handling in IopGetDriverNames().
- Fix CID 1477246: Uninitialized pointer read (UNINIT) (happens in
  the last ExFreePoolWithTag(basicInfo, TAG_IO) call when the
  "(!NT_SUCCESS(status) || ServiceName != NULL)" case is not taken).

- Centralize all the ExFreePoolWithTag(basicInfo, TAG_IO) cleanups
  at the end of the function.

- Both cases "(driverName.Buffer == NULL)" and "(ServiceName != NULL)"
  can only be taken when basicInfo != NULL, so assert on this fact.
2021-06-16 22:18:02 +02:00
Hermès Bélusca-Maïto 0d28f27156
[NTOS:IO] Fix similar bugs in IopGetDriverNames(), IopInitializeBuiltinDriver() and IopLoadDriver().
- As they are initialized, some registry string values must be NULL-terminated.
- When retrieving REG_DWORD registry values, validate their length.
2021-06-16 22:14:01 +02:00
Hermès Bélusca-Maïto a82ff90b21
[NTOS:IO] Minor code style changes...
- Fix/add comments;
- Reduce indentation level;
- Direct copy for registry integer values;
- Use for-loops for linked lists;
- Use ULONG when the API uses it (sizes for Ob, or REG_DWORD data in registry).
2021-06-16 22:14:01 +02:00
Victor Perevertkin 3f601122bc [NTOS:MM] Fix placing entries into MmNonPagedPoolFreeListHead
When freeing pages, free page entries with pages num == 3 were
incorrectly treated as entries with pages num >= 4 and thus
their re-insertion was not triggered. That lead to non paged pool
fragmentation (can be triggered by kmtest:ExPools, for example)

Also, altered the index acquisition code for MmNonPagedPoolFreeList
entries so it looks more clear
2021-06-16 12:14:27 +02:00
Victor Perevertkin 34593d933b
[FORMATTING][NTOS][HAL][DRIVERS][SDK] Fix trailing spaces 2021-06-11 15:33:08 +03:00
Hermès Bélusca-Maïto 4b4ffa92f5
[NTOS:IO] Modify when 'PartitionBuffer' and how 'DriveLayout' are freed in IopCreateArcNamesDisk().
- Manage the lifetime of the temporary 'PartitionBuffer' buffer where
  it is locally used only, and free it as soon as possible, just after
  calculating the sector checksum. No need to then free it outside of
  the main for-loop.

- When the 'DriveLayout' buffer is freed, ensure the pointer is NULL-ed
  (and assert this at the top of the main for-loop), since it can also
  be freed at cleanup outside this for-loop, and in this case a NULL
  check is performed.
  This will avoid the scenario of possibly double-freeing a pointer,
  in the case the 'DriveLayout' was previously freed (when e.g. reading
  the sector for checksum calculation failed), then the for-loop goes to
  the next disk and stops early.
2021-06-11 02:21:48 +02:00
Hermès Bélusca-Maïto fdd74eb97e
[NTOS:IO/FSTUB] Fix the determination of 'SingleDisk' in IoGetBootDiskInformation().
The purpose of 'SingleDisk' is the same as in the IopCreateArcNames()
function. It is an optimization for that when looking up the
firmware-recognized ARC disks list, in order to match one of these with
the current NT disk being analysed (see e.g. also in IopCreateArcNamesDisk()),
we avoid a possible IopVerifyDiskSignature() call and directly build a
corresponding ARC name NT symbolic link for it.

'SingleDisk' will actually be TRUE, whether the DiskSignatureListHead
list is empty or contains only one element: Indeed in only both these
cases, 'DiskSignatureListHead.Flink->Flink' will refer to the list head.
(If the list is empty but 'SingleDisk' is TRUE, this does not matter,
because the DiskSignatureListHead looking-up loop never starts.)
2021-06-11 02:21:47 +02:00
Hermès Bélusca-Maïto 99078646c3
[NTOS:IO] Avoid hardcoding variable types in sizeofs when possible. 2021-06-11 02:21:47 +02:00
Hermès Bélusca-Maïto 6e65e6b28d
[NTOS:IO] Minor code style fixes (typos; improve comments/DPRINT; IN vs. OUT parameter). 2021-06-11 02:21:47 +02:00
Jérôme Gardou afc27ab1aa [NTOS:MM] Handle PT references for page table faults in MmAccessFault
Idea from Timo Kreuzer
2021-06-09 11:27:18 +02:00
Jérôme Gardou c7e09061ca [NTOS:MM] Get rid of MiQueryPageTableReferences 2021-06-09 11:27:18 +02:00
Timo Kreuzer 6a2eeaa5ae [NTOS] Implement MiIsPageTablePresent as a replacement for the abused MiQueryPageTableReferences 2021-06-09 11:27:18 +02:00
Jérôme Gardou 678923bf4b [NTOS:MM] In MiMakePdeExistAndValid, do not overly check PDE validity
It's "okay" to not #ifdef, but it's useless and confusing.
2021-06-09 11:27:18 +02:00
Jérôme Gardou c8fb3f7514 [NTOS:MM] Implement proper refcounting of page tables on amd64
CORE-17552
2021-06-09 11:27:18 +02:00
Jérôme Gardou 3aa346c21f [NTOS:MM] Make MiIsEntireRangeCommitted 64-bits aware 2021-06-09 11:27:18 +02:00
Jérôme Gardou 8bfba59b3e [NTOS:MM] Add some DPRINTs when incrementing or decrementing PFN share count 2021-06-09 11:27:18 +02:00
Jérôme Gardou a80ae8f2ea [NTOS:MM] Make MiCalculatePageCommitment 64-bits aware 2021-06-09 11:27:18 +02:00
Jérôme Gardou b48e27ada1 [NTOS:MM] Add a few MiP*eToP*e helpers
And turn some of the existing ones into inline functions for the sake of type checking
2021-06-09 11:27:18 +02:00
Jérôme Gardou ed1038ff9c [NTOS:MM] Properly initialize initial process address space on amd64
By applying the same kludge on the relevant MMPFNs than on x86
2021-06-09 11:27:18 +02:00
Jérôme Gardou f9ea58dc97 [NTOS:MM] Unconditionally delete the PFN in MiDeletePte when PTE is in transition
When we will have a modified page writer, it will have to know if the written
page is stale when being done, and act accordingly.

CORE-8552
2021-06-09 11:27:18 +02:00
Jérôme Gardou 82dd1afe33 [NTOS:MM] Remove some dead code from legacy Mm 2021-06-09 11:27:18 +02:00
George Bișoc 7ca6bfb994
[NTOS:SE] Use IQS_NONE for the first class which is not existent and barely used 2021-06-08 09:26:11 +02:00
George Bișoc 672c9068bb
[NTOS:PS] Use IQS_NONE for classes that do not exist 2021-06-08 09:26:11 +02:00
George Bișoc bbdb4d6340
[NTOSKRNL] Use CHAR for non existent classes
An alignment of 1 means no alignment required and the class doesn't exist. 0 shouldn't be used for alignment requirement in IQS_NONE!
2021-06-08 09:25:30 +02:00
Jérôme Gardou a5ea259b28 [NTOS:MM] Fix remnants of CORE-17587 2021-06-07 17:04:18 +02:00
Jérôme Gardou 4ddc66f224 [NTOS:MM] Make MI_MAKE_HARDWARE_PTE_KERNEL actually respect the protection it is given
This one would set a page as writable & dirty even if MM_READONLY was passed
CORE-17587
2021-06-07 17:04:18 +02:00
George Bișoc a330b56787
[NTOS:PS] Enable alignment probing for thread/process information classes
In addition to that, here are some stuff done in this commit whilst testing:

- ICIF_QUERY_SIZE_VARIABLE and friends were badly misused, they should be used only when an information class whose information length size is dyanmic and not fixed. By removing such flags from erroneous classes, this fixes the STATUS_INFO_LENGTH_MISMATCH testcases.

- Use CHAR instead of UCHAR for classes that do not need alignment probing, as every other class in the table do, for the sake of consistency.

- ProcessEnableAlignmentFaultFixup uses BOOLEAN as type size, not CHAR. This fixes a testcase failure on ROS.

- Check for information length size before proceeding further on querying the process' cookie information.

- ProcessHandleTracing wants an alignment of a ULONG, not CHAR.

- Move PROCESS_LDT_INFORMATION and PROCESS_LDT_SIZE outside of NTOS_MODE_USER macro case. This fixes a compilation issue when enabling the alignment probing. My mistake of having them inside NTOS_MODE_USER case, sorry.

- On functions like NtQueryInformationThread and the Process equivalent, complete probing is not done at the beginning of the function, complete probing including if the buffer is writable alongside with datatype misalignment check that is. Instead such check is done on each information class case basis. With that said, we have to explicitly tell DefaultQueryInfoBufferCheck if we want a complete probing or not initially.
2021-06-06 17:14:22 +02:00
Timo Kreuzer 20c1da7963 [RTL][KMTEST] RtlPcToFileHeader doesn't handle user mode images in kernel mode 2021-06-05 14:39:29 +02:00
Timo Kreuzer 7f2e0ece5a [NTOS:KE/x64] Handle shared interrupts 2021-06-04 09:19:13 +02:00
Timo Kreuzer e8496b4fbf [NTOS:PS/x64] Fix PspGetOrSetContextKernelRoutine
It now uses KiSetTrapContext to set the non-volatile context on the stack and the volatile context in the trap frame.
2021-06-02 18:25:36 +02:00
Timo Kreuzer f1ed97d6cc [NTOS:KE/x64] Implement KiSetTrapContext
KiSetTrapContext is an asm wrapper around RtlSetUnwindContext, which first stores an exception frame to assure that all non-volatile registers were put on the stack, then calls RtlSetUnwindContext to update their first saving positions on the stack and finally restore the exception frame to potentially load any updated registers, that haven't been saved elsewhere on the stack.
2021-06-02 18:25:36 +02:00
George Bișoc 06b0d2e380
[NTOS:SE] Implement logon session deletion
And declare a prototype for SepCleanupLUIDDeviceMapDirectory and annotate it with SAL.
2021-06-02 11:09:01 +02:00
George Bișoc 3140dac3fe
[NTOS:SE] Do some cleanup on ICIF flags in token information classes
A few of these classes have fixed size lengths, the rest are arbitrary. Also the TokenAuditPolicy class hasn't a size length type specified in the table, which is wrong (and move the corresponding TOKEN_AUDIT_POLICY_INFORMATION structure into the private header).
2021-05-29 12:44:03 +02:00
Timo Kreuzer 90a0e426ed [NTOS:KE] Add IRQL checks and fix KiInitiateUserApc 2021-05-28 11:52:42 +02:00
Timo Kreuzer 3d18831c19 [NTOS:KE] Improve KiSystemCallEntry64 2021-05-28 11:52:42 +02:00
Timo Kreuzer 69e8cb635a [NTOS:KE] Fix stack alignment issues 2021-05-28 11:52:42 +02:00
Timo Kreuzer 2a2d0903bf [NTOS:KE] Remove duplicated EFlag definitions 2021-05-28 11:52:42 +02:00
Jérôme Gardou b0ebf68d98 [NTOS:IO] Be more specific for chasing CORE-17587
Addendum to 42ec1388d7
2021-05-26 11:03:34 +02:00
Jérôme Gardou 42ec1388d7 [NTOS:IO] Break on IoRaiseInformationalHardError
This one will eventually be reverted. For now, this will help debugging CORE-17587
2021-05-26 10:48:29 +02:00
Hervé Poussineau 831cad3410 [NTOS:MM] Remove wrong cleaning of PDEs at session cleanup 2021-05-25 21:13:32 +02:00
Hervé Poussineau 98882fb089 [NTOS:MM] Finish implementation of MmSessionDelete 2021-05-25 18:48:16 +02:00
Hervé Poussineau eac0afc6fe [NTOS:MM] MiDereferenceSession: return as soon as session is destroyed
This leads to some simplifications in the following code.
2021-05-25 18:48:16 +02:00
Timo Kreuzer dd08ae2c0f [NTOS:CC] Fix use of unintialized variable (caught by RTC1) 2021-05-24 22:00:11 +02:00
Timo Kreuzer 184d3a6849 [NTOS:MM] MiIsPdeForAddressValid is NOT an INIT function! 2021-05-24 18:45:47 +02:00
Jérôme Gardou 0395049986 [NTOS:KE] Do not call MmSetPageProtect for the Pentium Lock Errata
CORE-17589
2021-05-21 10:52:55 +02:00
Jérôme Gardou 7eff8a36d5 Revert "[NTOS:MM] Add private pages to process working sets"
This is so full of bugs, I don't know what to say.
This reverts commit 374fef2d59.
2021-05-20 00:19:43 +02:00
Jérôme Gardou 969e60a06d [NTOS:MM] Move software PTE specific check after it's been tested for being one
Caught by The_DarkFire, only soul on earth actually *running* our SMP kernel
2021-05-19 23:56:21 +02:00
Jérôme Gardou 7d0d14965e [NTOS:MM] Do not map Process Working Set List in kernel space
This is not needed anymore and causes havoc on amd64
2021-05-19 23:17:27 +02:00
Dmitry Borisov 2193031133 [NTOS:PO] Check for optional parameter in the completion routine
The CompletionFunction parameter is really optional.
This fixes a bugcheck caused by shutdown with IDE driver stack.

CORE-17401
2021-05-19 20:14:29 +02:00
Jérôme Gardou 826aec48de [NTOS:MM] Fix build on whatever MSVC version triggered this
There is no real need to put static or extern "C" function in a special namespace anyway
2021-05-19 00:12:05 +02:00
Jérôme Gardou 374fef2d59 [NTOS:MM] Add private pages to process working sets 2021-05-18 23:42:19 +02:00
Jérôme Gardou 6a5fd8f487 [NTOS:MM] Relax requirements with regards to PFN lock when adding & removing entries in Working Sets
Once a page is used, holding the WS lock is enough until you want to free it.
2021-05-18 23:42:19 +02:00
Jérôme Gardou aeffd16b38 [NTOS] Introduce KiQueuedSpinLockGuard, similar to std::lock_guard for Queued Spin lock
And use it in Mm as MiPfnLockGuard
2021-05-18 23:42:19 +02:00
George Bișoc 99d776894a
[NTOS:SE] Capture the groups length when creating a token
The groups length is already returned by SeCaptureSidAndAttributesArray, it doesn't make sense to not use it.
2021-05-16 17:18:29 +02:00
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