Commit Graph

1739 Commits

Author SHA1 Message Date
Timo Kreuzer
96c65e94e1 [NTOS:MM] Properly handle execution in NX section
This prevents processes from looping forever, thinking the fault was already resolbed, because the page is writable.
2024-09-16 16:04:43 +03:00
Thomas Faber
bf6af0f52e [NTOS:SE] Mark output parameters as such. 2024-09-12 17:44:13 +03:00
Thomas Faber
156053cafd [NDK] Match AUX_ACCESS_DATA definition with publicly available version.
Looks like public symbols contain this structure starting with Win7,
so we can deduce what it looked like in Win2003.
Note that our previous definition was missing a second ULONG at the
end, which can be seen in the SeQueryInfoToken kmtest -- if you
allocated only sizeof(AUX_ACCESS_DATA), the test would crash with
a 4 byte buffer overflow.
2024-09-12 17:44:13 +03:00
Timo Kreuzer
2913ef5c93 [NTOS:KE/x64] Fix exception information on page faults
Pass a proper write/execute flag in the ExceptionInformation[0] field of the exception record instead of the raw fault code. This fixes comdlg:filedlg wine test, which writes to a write protected resource section, which needs to be handled by kernel32 UnhandledExceptionFilter, which relies on this parameter to be correct.
2024-09-12 17:07:59 +03:00
Timo Kreuzer
78e94a5083 [NTOS:MM] Increase x64 system view and session view size
We have plenty of address space and the desktop heap has grown, so we need some more space.
2024-09-08 10:33:55 +03:00
Serge Gautherie
4b051b914f
[NTOS:PO] Update a comment (#6443)
Addendum to 9e43518 (0.4.15-dev-7560).
2024-09-08 02:29:37 +02:00
Justin Miller
49e07292ed
[NTOS:KE] Clear NpxThread on rundown for SMP as well (#7151)
clear NpxThread on rundown for SMP as well
Fixes the crash whenever a usermode thread is destroyed on x86
2024-08-31 13:18:07 -07:00
Thamatip Chitpong
95c340dfb7
[NTOS:CC] CcRosCreateVacb: Return error code on pool allocation failure (#7275)
Return STATUS_INSUFFICIENT_RESOURCES error code instead of accessing the invalid pointer.
2024-08-30 07:34:48 +07:00
Oleg Dubinskiy
c59e2d20d9 [NTOS:FSRTL] Check for the correct return status when inserting a new Filter Context entry
According to our declaration/definition, IoChangeFileObjectFilerContext returns NTSTATUS, not BOOLEAN. Zero return (which was actually checked before) for BOOLEAN means failure, but for NTSTATUS it's success. So it should (and now actually does) free and fail appropriately only in failure case, but not in success, when it shouldn't.
This fixes most of problems with fltmgr.sys driver from Windows XP/Server 2003 and a lot of 3rd party filter drivers which use it from many apps (Avast Free Antivirus all versions, Avira AntiVir Personal 8.2, Dr. Web Security Space 8.0, Kaspersky Antivirus 2012 etc. etc.).
CORE-14157, CORE-14635, CORE-19318
2024-08-26 11:16:49 +02:00
Oleg Dubinskiy
5d96ba9217
[NTOS:MM] Implement MmProbeAndLockProcessPages (#7221)
Implement undocumented MmProbeAndLockProcessPages routine. Based on mm-implement-mappingaddress.patch by Thomas Faber from CORE-10147, with some improvements from me.
It's badly required by FltMgr.sys driver from Windows XP/Server 2003 and closely used by a lot of apps those are depending on this driver (e. g., Avast Free Antivirus several versions, Avira Antivir Personal 8.2 etc. etc.).
Fixes several asserts from MDL support routines when the 3rd-party minifilter drivers are loading FltMgr.
CORE-14157
2024-08-08 21:02:35 +02:00
Thamatip Chitpong
cf4138fa24 [NTOS:CC] Protect CcFlushCache call with a mutex
Fix crash when the function was called concurrently for the same file by BTRFS driver.
CORE-19664
2024-07-31 18:07:49 +07:00
Thamatip Chitpong
0899f4b2b1 [NTOS:CC] CcFlushCache: Call CcRosReleaseVacb when CcRosFlushVacb fails
CcRosLookupVacb adds a refcount.
2024-07-31 18:07:49 +07:00
Hermès Bélusca-Maïto
3fe12f1a7c
[NTOS:IO] IopCreateArcNamesDisk(): Fix the ArcName link creation condition check.
The bug was introduced in commit 6d0861e9e (r49131).
2024-06-19 17:26:40 +02:00
Hermès Bélusca-Maïto
5e3f3f59df
[NTOS:IO] IopVerifyDiskSignature(): simplify code and SAL2-annotate 2024-06-19 17:25:42 +02:00
Hermès Bélusca-Maïto
85d338ed65
[NTOS:IO] arcname.c: Minor formatting fixes and comments improvements 2024-06-19 17:25:34 +02:00
George Bișoc
fe23a4aaeb
[NTOS:CM] Lock the entire registry down when we unload a hive
The PR #6649 which fixed an issue with orphaned KCBs leaking in memory which also pointed to unloaded registry hives, it also brought a problem.
In CmpEnumerateOpenSubKeys there is a risk of getting hit by a deadlock as we enumerate the cache table to remove empty cache entries.

Fundamentally CmpEnumerateOpenSubKeys locks down a KCB from cache for exclusive use in order to tear down its contents from memory but it doesn't address the fact a KCB might have already been locked in the same calling thread, leading to a recursion.
This leads to random hangs when unloading a hive during system startup (tipically on a clean install).

The solution here is to simply lock the whole registry when we unload a hive so that we don't have to worry the KCBs are getting tampered by anybody else. This also simplifies the code.
Although locking the entire registry while other apps are doing registry related operations to other hives can cause overhead. If this turns out to be bad then we have to rethink the locking mechanism here.

CORE-19539
2024-06-01 16:17:47 +02:00
George Bișoc
5d0117de90
[NTOS:CM] Annotate CmUnloadKey with SAL2 2024-06-01 16:17:47 +02:00
Timo Kreuzer
4fb2fdbac6 [NTOS:CM] Properly unlock registry on failure in NtUnloadKey2 2024-05-23 21:21:35 +02:00
Timo Kreuzer
da64119fe6 [NTOS:CM] Add debug code for analyzing lock issues 2024-05-23 21:21:35 +02:00
Timo Kreuzer
e0495079cb [MSVCRT][NTDLL][NTOS] Add import aliases for _swprintf and _vswprintf 2024-05-22 17:55:38 +02:00
Serge Gautherie
a6298b5c7a
[NTOS:MM] section.c: some trivial cleanup (#5651)
* [NTOS:MM] section.c: Remove unused functions

MiSetControlAreaSymbolsLoaded(),
MiLoadUserSymbols():
Added on 436edb2 (r60802). Never used.

MiSubsectionConsistent():
Added on cda03c0 (r57209). Never used.

MiGetFileObjectForSectionAddress():
Added on 635d9ca (r67810). Calls removed on 0dfd233 (r68123).

MiSetProtectionOnSection():
Added on 9f28638 (r56317). Never used.

Plus,
MmCreateArm3Section():
Add an UNIMPLEMENTED on a specific case.

* [NTOS:MM] section.c: Use static instead of NTAPI for local functions
2024-05-21 11:08:40 +02:00
Doug Lyons
69ebfd671d
[NTOS:EX] Various fixes for Daylight Saving Time transitions (#5868)
* [NTOS:EX] Various fixes for Daylight Saving Time transitions

* Fix automatic time changes when DST starts and ends.
* Currently it takes two cycles of the update provided by w32time to make the actual change.
* Convert Eric Kohl's TimeZoneID code contained in ExRefreshTimeZoneInformation to a new function.
* Use this new function in ExpSetTimeZoneInformation and ExRefreshTimeZoneInformation functions.

CORE-19290
2024-05-05 21:32:04 -05:00
Serge Gautherie
cb6fc76b8b
[NTOS:IO] IoDisconnectInterrupt(): Switch to ExFreePoolWithTag() (#6503)
Follow-up to commit 24a14abf2 (r57412).

HBelusca's comment:
> If this ExFreePoolWithTag() call was left commented, it's probably
> because, back in the day where I introduced it, there was a pool
> corruption that was detected, the source of which was unknown at
> that time. In retrospect, it is most probably the interrupt disconnect
> bug in IoDisconnectInterrupt() that was causing it. Now that this
> bug has been fixed just previously, it should be safe to re-enable
> pool freeing with tag.
2024-05-05 17:03:42 +02:00
Serge Gautherie
347ca5f859
[NTOS:IO] IoConnectInterrupt(): Move InterruptObject assignment where it belongs (#6503)
Addendum to commit d1258e99f (r16229), supersedes commit adf534b28.

CORE-17256
2024-05-05 17:03:28 +02:00
Serge Gautherie
2d442956b4
[NTOS:IO] IoConnectInterrupt(): Fix default spinlock initialization (#6503)
Addendum to commit d1258e99f (r16229).
2024-05-05 17:03:20 +02:00
Serge Gautherie
cbc78e0629
[NTOS:IO] IoDisconnectInterrupt(): Fix disconnecting other interrupts (#6503)
Addendum to commit d1258e99f (r16229).
2024-05-05 17:03:13 +02:00
Hermès Bélusca-Maïto
603fd832d0
[NTOS:IO] IoConnectInterrupt(): Zero-out the allocated structure at the correct place (#6503)
Addendum to commit d1258e99f (r16229).
2024-05-05 17:02:34 +02:00
Serge Gautherie
35d46b23f1
[FORMATTING][NTOS:IO] iomgr/irq.c
- Add a few blank lines.
- Use 2 'continue'.
2024-05-05 16:35:22 +02:00
Timo Kreuzer
5c3b1c78a7 [NTOS:KE] Improve NtRaiseException and NtContinue
- Fix annotations
- Don't use KiServiceExit to return to the caller with an error code, instead just return from the function, that is the same thing.
- Refactor failure path
- Add DPRINTs on failure
2024-05-01 11:30:29 +02:00
Timo Kreuzer
4bc591c6f0 [NTOS:KE] Fix NtRaiseException and NtContinue on x64
- Implement KiExceptionExit, which works like KiServiceExit2, but takes an exception frame as 2nd parameter
- Add a local exception frame to NtRaiseException and NtContinue, which is needed to exit with a full context on x64 and arm
- Use KeContextToTrapFrame again instead of KiSetTrapContext, since we have a proper exception frame now.
2024-05-01 11:30:29 +02:00
Doug Lyons
0f9bf6abb4
[NTOS:CC] Restore unlock/reacquire locks around MmPageOutPhysicalAddress (#5735)
* [NTOS:CC] Restore unlock and reacquire locks around MmPageOutPhysicalAddress which was mistakenly lost in commit 2b14056

* Add bypass for problematic code path for now
2024-04-30 13:59:50 -05:00
Timo Kreuzer
c9864da823 [NTOS:IO] Fix broken pool allocations
ExAllocatePoolWithTag doesn't raise an exception on failure, only ExAllocatePoolWithQuotaTag does. Use that when quotas are relevant instead of silently continuing with a NULL pointer.
2024-04-28 14:06:07 +02:00
Timo Kreuzer
b8e50f787d [NTOS:KE/x64] On syscalls clear nested task flag
When this flag is not cleared and the system returns with an IRET, this causes a #GP. Randomly hit by the umkm:SystemCall test.
2024-04-27 15:12:40 +02:00
Timo Kreuzer
6ac260dcec [NTOS:KE/x64] Handle NMI vs swapgs race condition 2024-04-23 15:50:06 +02:00
Timo Kreuzer
72fd54a7f4 [NTOS:KE/x64] Implement Kd processor switching 2024-04-23 15:50:06 +02:00
Timo Kreuzer
9229709312 [NTOS:KE/x64] Implement processor freeze code 2024-04-23 15:50:06 +02:00
Timo Kreuzer
af2ce4d08f [NTOS:KE/x64] Implement KiSaveProcessorState / KiRestoreProcessorState 2024-04-23 15:50:06 +02:00
Timo Kreuzer
1d289fec77 [NTOS:KE] Improve freeze code in KeBugCheckWithTf
- Don't wait 1 second for each processor
- Use AFFINITY_MASK
- Use Prcb->Number, which is more future proof than KeGetCurrentProcessorNumber
- Improve for loop
2024-04-23 15:50:06 +02:00
Timo Kreuzer
d96f01b5dc [NTOS:KE/x64] Add KiNmiInterruptHandler
So far it only calls KiHandleNmi. It will also handle processor freeze later.

TODO: Pass TF_WITH_EF to directly generate a KEXCEPTION_FRAME
2024-04-23 15:50:06 +02:00
Timo Kreuzer
05456808e8 [NTOS:KE/x64] Fix handling of non-volatiles in trap vs exception frame
The registers that are saved/restored in the trap / exception frame need to be consistent between all entry/exit points as well as the functions that convert between trap/exception frame and context. The trap frame contains only the non-volatile registers and rbp, the rest is saved in the exception frame.
The previous code didn't save rbp in the syscall handler, which led to it being clobbered when exiting though KiServiceExit2 rather than returning back to the syscall exit path. Also KeContextToTrapFrame would use rbx, rsi and rdi from the trap frame, which wouldn't be saved there by the syscall handler.
2024-04-14 16:09:20 +02:00
Timo Kreuzer
c69371cced [NTOS:KE/x64] Improve KeGetTrapFrame 2024-04-10 23:27:53 +02:00
Timo Kreuzer
713a360c74 [NTOS:KE/x64] Remove pointless loop in KiInitiateUserApc
Only one user APC can be delivered here. The next one can only be delivered, when KiUserApcDispatcher returns to the previous context with NtContinue.
2024-04-07 09:14:26 +02:00
Timo Kreuzer
7589238b68 [NTOS:KE/x64] Fix user APC delivery on syscall exit
We need to save the missing registers in the trap frame before calling KiInitiateUserApc, because they will be used to create the CONTEXT that is saved on the user mode stack, where KiUserApcDispatcher returns back to using NtContinue. This fixes remaining failures in kernel32_apitest QueueUserAPC.
2024-04-07 09:14:26 +02:00
Timo Kreuzer
43b181309e [NTOS:KE] Fix calculation of timer expiration
Both due-times and interrupt time are unsigned, but were treated as signed in KiInsertTimerTable, which led to very long (e.g. INFINITE) waits being interpreted as having a negative due-time and being completed instantly.
Mostly fixes kernel32_apitest QueueUserAPC
2024-04-07 09:14:26 +02:00
Timo Kreuzer
34576c7015 [NTOS:KE/x64] Implement KiUserCallbackExit
This is used in KiUserModeCallout instead of KiServiceExit2. The latter is broken, leaks non-volatile registers and will need to be modified to handle an exception frame, which we don't need/have here. It will also use sysret instead of iret and is generally simpler/faster.
Eventually it would be desirable to skip the entire trap frame setup and do everything in KiCallUserMode. This requires some cleanup and special handling for user APC delivery.
2024-04-07 09:13:58 +02:00
Timo Kreuzer
5b82ada2ed [NTOS:Ke/x64] Improve KiDispatchExceptionToUser
Return back to the caller instead of exiting through KiServiceExit2, which is broken and needs to be changed to allow restoring of an exception frame.
2024-04-04 18:41:39 +02:00
Timo Kreuzer
24b4026ce8 [NTOS:KE/x64][SDK] Add HANDLE_USER_APCS asm macro
This also fixes delivering APCs from the system call handler, which previously would have clobbered rax. Also don't use the thread's TrapFrame member, which is not always set, when returning.
2024-04-01 20:15:49 +02:00
Timo Kreuzer
88e24bc463 [NTOS:KE/x64][SDK] Add some trap handling support asm macros 2024-04-01 20:15:49 +02:00
Thamatip Chitpong
5329e475db [NTOS:MM] MiDeleteVirtualAddresses: Update PrototypePte before exiting loop, when deleting PDE
Fix BSoD 0x1A introduced by commit c7e09061ca
CORE-18190
CORE-18818
CORE-19253
2024-04-02 00:14:57 +07:00
Thamatip Chitpong
588449c364 [NTOS:MM] Revert commit 0c612980ac
This revert commit 0c612980ac
2024-04-02 00:14:57 +07:00