Commit graph

122 commits

Author SHA1 Message Date
Timo Kreuzer 7611cc2b12 [REACTOS] Fix SIZE_T related warnings 2019-08-15 14:20:00 +02:00
Hermès Bélusca-Maïto 3625238ecb
[NTOS:MM] Add a MmChangeKernelResourceSectionProtection() helper. (#1649)
This allows setting the memory protection of the kernel's resource
section as will. MmMakeKernelResourceSectionWritable() is re-implemented
around this helper.
2019-07-14 22:23:49 +02:00
Serge Gautherie ccf8bff3ec [NTOS:MM] Fix MmGetFileNameForAddress() callers. (#1723)
MmGetFileNameForAddress() calls RtlCreateUnicodeString().
This also fixes a leak in MiQueryMemorySectionName().
2019-07-14 00:32:23 +02:00
Serge Gautherie 6ba611f39e [NTOS:MM] Fix MmSizeOfSystemCacheInPages value on AMD64
And add 'ASSERT(MmSystemCacheEnd == ...);'.

Addendum to d56a249089.
CORE-14259
2019-07-06 09:55:38 +02:00
Hermès Bélusca-Maïto 05616105a5
[NTOS:MM] Fix MiLocateKernelSections() and MmMakeKernelResourceSectionWritable().
- MiLocateKernelSections(): Fix the calculation of MiKernelResourceEndPte,
  MmPoolCodeEnd and MmPteCodeEnd.

- MmMakeKernelResourceSectionWritable(): Fix PTE looping upper limit;
  use MI_MAKE_HARDWARE_PTE_KERNEL to build the updated read-write PTE.
2019-06-26 00:57:53 +02:00
Hermès Bélusca-Maïto f694d12f0c
[NTOS:KE/MM] Some bug-fixes in the bugcheck code.
- Introduce the MmMakeKernelResourceSectionWritable() helper for
  making the kernel resource memory section writable, and use it
  in KeGetBugMessageText(). Indeed, this latter function patches
  in place the bugcheck resource message to trim any trailing
  newlines before displaying the message on screen.

  See also https://github.com/osresearch/uxen/blob/83bad53/dm/introspection-win7.c#L286
  that mentions it too.

  This fixes bugcheck text display (e.g. the MANUALLY_INITIATED_CRASH one)
  when using (at least) MSVC-built ReactOS, avoiding a Page-Fault
  exception during the bugcheck.

- Cover KeGetBugMessageText() in SEH since we are accessing kernel
  resources that could also be corrupted in bugcheck scenarii, and we
  don't want to further bugcheck.

- Fix newline trimming loop.

- KiDoBugCheckCallbacks():
  * Wrap the bugcheck CallbackRoutine call in SEH.
  * Add a FIXME concerning the need of further memory validation of CurrentRecord.

- Add a FIXME concerning the need to run the bugcheck-reason callbacks
  with the KbCallbackReserved1 reason, in KeBugCheckWithTf().
  Mentioned in http://blog.ptsecurity.com/2012/06/customizing-blue-screen-of-death.html
2019-06-25 21:01:49 +02:00
Serge Gautherie cf27695269 [NTOS:MM] PeFmtCreateSection(): Improve AMD64 image failure case
Addendum to 98638cc2df.

CORE-15981
2019-06-04 18:22:19 +02:00
Mark Jansen 98638cc2df
[NTOS/MM] Recognize AMD64 image in PeFmtCreateSection failure case 2019-05-15 19:39:56 +02:00
Thomas Faber f3a280f52b
[NTOS] Use correct buffer size when calling MiResolveImageReferences. CORE-15882 2019-05-05 10:39:11 +02:00
Mark Jansen 2450dec427
[NTOS/MM] Ensure ImageBase is not used uninitialized 2019-04-30 18:57:43 +02:00
Bernhard Feichtinger f5471b7b4b
[NTOS][USERSRV] Silence noisy debug output. 2019-04-22 17:41:17 +02:00
Maxim Smirnov d29e216f99 [NTOSKRNL] In MmCreateImageSection, properly check whether cache was initialized
This fixes a crash that occurs if nul is typed in cmd.exe
2019-03-31 13:51:06 +02:00
Timo Kreuzer 81727760e4 [NTOS::Mm] Fix inverted check in MiWriteProtectSystemImage 2019-02-24 20:34:02 +01:00
Serge Gautherie 84e76b1c4c [NTOS:MM] ExFreePoolWithTag(): Accept tag mismatch, on release build only (#1334)
"Release" builds should not BSoD on 'Freeing pool - invalid tag specified' case,
this is compatible with Windows behaviour.
Nothing changes otherwise concerning the "Debug" builds, where pool-tag mismatch
triggers a BSoD as expected.

CORE-15446
2019-02-07 16:57:56 +01:00
Thomas Faber 066ee4db3b
[NTOS:MM] Dump pool consumers at most once per second.
This should avoid some log spam during kmtest:ExPools, which
intentionally depletes pool.
2019-02-03 12:54:36 +01:00
Pierre Schweitzer a6dc1d69bc
[NTOS:MM] On big pool enumeration, return entry instead of base VA 2019-02-02 10:45:15 +01:00
Hermès Bélusca-Maïto 06d4fce5ee
[NTOS:MM] Some fixes for NtCreatePagingFile().
- Correctly probe the FileName user pointer before capturing its contents.
- A paging file name with zero length is invalid too.
- Remember (TODO!) in the code that the lower bounds of the Safe*Size values
  need to be checked too!
2019-01-28 22:22:56 +01:00
Timo Kreuzer 3410b25fde [NTOS] Turn broken assert into DPRINT 2019-01-19 13:38:24 +01:00
Timo Kreuzer 65dbfc2868
[NTOS:Mm] Rewrite MiWriteProtectSystemImage (#749)
* The previous version was overcomplicated and broken and therefore disabled.
* The new version also enforces NX protection on x64.
* Now that protecting works, also protect the boot loaded images.
2019-01-18 22:11:43 +01:00
Pierre Schweitzer d9a3fd16d4
[NTOSKRNL] Add support for callback when enumerating large pool allocations 2019-01-15 22:07:35 +01:00
Thomas Faber e7de564bfc
[NTOS:MM] Implement big pool table expansion. CORE-15051 2019-01-09 08:18:38 +01:00
Pierre Schweitzer a3f8813fff
[NTOSKRNL] Add support for large allocations in !poolfind 2019-01-08 08:43:23 +01:00
Pierre Schweitzer e1342127f0
[NTOSKRNL] In !irpfind, add info about current stack major/minor 2019-01-08 08:43:23 +01:00
Pierre Schweitzer e6a1851684
[NTOSKRNL] Misc fixes to !irpfind 2019-01-06 23:21:20 +01:00
Pierre Schweitzer 36f90e7e46
[NTOSKRNL] Move KDBG MM functions implementation to their own file 2019-01-06 22:50:57 +01:00
Pierre Schweitzer 28193399ee
[NTOSKRNL] Properly check for address validity in !poolfind 2019-01-06 12:58:14 +01:00
Pierre Schweitzer 47b48520b5
[NTOSKRNL] Reimplement !irpfind using !poolfind helpers
This allows avoiding one of the previous implementation limits:
leaked IRP not queued to a thread are now totally visible since
we look directly in the memory pool.
2019-01-06 12:49:57 +01:00
Pierre Schweitzer 12e579567c
[NTOSKRNL] Implement !poolfind command in KDBG
For now, it allows searching for pool allocations in
both paged and non paged pool.

It is based on Andreas Schuster work to identify POOL_HEADER
structures.
2019-01-06 11:56:38 +01:00
Timo Kreuzer 71fefa32db
[NDK][NTOS] Add global definition of INIT_FUNCTION/INIT_SECTION (#779)
* Add an NDK header to define INIT_FUNCTION/INIT_SECTION globally
* Use _declspec(allocate(x)) and _declspec(code_seg(x)) on MSVC versions that support it
* Use INIT_FUNCTION on functions only and INIT_SECTION on data only (required by MSVC)
* Place INIT_FUNCTION before the return type (required by MSVC)
* Make sure declarations and implementations share the same modifiers (required by MSVC)
* Add a global linker option to suppress warnings about defined but unused INIT section
* Merge INIT section into .text in freeldr
2018-12-30 12:19:11 +01:00
Andrew Boyarshin 3ba51dc218 [NTOS:MM] Fix typo in MiCheckForUserStackOverflow 2018-12-12 12:57:08 +01:00
Pierre Schweitzer 4d974e56ee
[NTOSKRNL] Return the amount of hits in system lookaside lists in ExQueryPoolUsage() 2018-12-09 18:25:11 +01:00
Bernhard Feichtinger 8a0495063b [NTOS:MM] Handle unimplemeted case for MiCheckForUserStackOverflow 2018-11-25 11:29:18 +01:00
Jérôme Gardou df25e4e791 [NTOS/MM] Properly handle page faults in regions marked with
PAGE_NOACCESS or PAGE_GUARD

ROSTESTS-110
2018-11-03 12:50:16 +01:00
Jérôme Gardou 47ac7a2b28 [NTOS/MM] Move up MmAlterViewAttributes for later use in MmNotPresentFaultSectionView
No code change
2018-11-03 12:50:16 +01: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 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
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
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
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