Commit graph

131 commits

Author SHA1 Message Date
Joachim Henze b1d5a3913c [0.4.13][NTOS:MM] Ignore sections either PointerToRawData or SizeOfRawData is zero
VC1 Linker fills BSS.SizeOfRawData with data in IMAGE_OPTIONAL_HEADER.SizeOfUninitializedData but keeps PointerToRawData to zero.

Fixes CORE-18797 and some duplicates of that. (Apps, e.g. Doom95, compiled with Watcom-C-compilers wouldn't run otherwise.)
which regressed by
0.4.10-dev-136-g c7eb46d9fd
fix picked from
0.4.15-dev-5589-g 0d4a8d0ea6
----------
Port back also some unrelated formatting-improvements within section.c, e.g.: return(xyz) -> return xyz
A *partial* port of
0.4.15-dev-1793-g b7eb0fddf3
2023-02-28 04:06:46 +01:00
Joachim Henze c1a59f6d2e [0.4.13][NTOS:MM] Copy the WorkingSet page when initializing "hand-built" process CORE-16737
(and part of the duplicated ticket CORE-17642 which covers a bit more changes in master)

fix picked from 0.4.15-dev-3018-g 34662e2f6f
2022-10-15 17:25:40 +02:00
Joachim Henze 04c7635c9e [0.4.13][NTOSKRNL] Mute noisy DPRINT 'SectionObject has ImageSection' during shutdown CORE-18029
All releases/0.4.8 until and including releases/0.4.14 were affected by the following logspam
during shutdown:
(../ntoskrnl/mm/section.c:4839) SectionObject has ImageSection
triggered 2 times for bootcd, but triggered 83 times for livecd.

Today I found out by chance, that we started to trigger it with the switch from CDFS to CDFS_NEW with
0.4.8-dev-164-g ec6b3ecbe4

We 'suffered' from that logspam for many years now and it did never help us in any way.
And during 0.4.15-dev'ing with the MM rewrite, the logging was entirely removed in the NTOSKRNL.
2022-01-27 20:16:40 +01:00
Joachim Henze 928625ccfa [0.4.13][NTOSKRNL] Workaround CORE-16387 & CORE-16449
Both most likely was introduced by activating feature
MiWriteProtectSystemImage() once.
Imho this feature is not stable yet, therefore I disable
it for releases.
Confirmation of reporters will have to be collected after
the commit.

Both problems most likely got visible by 0.4.12-dev-386-g
65dbfc2868

Master remains affected for now.
If no fix will appear during 0.4.14-dev'ing, then I will
commit this to master as well in 3months.
2019-12-17 00:06:05 +01:00
Timo Kreuzer 09d3029dd8 [NTOS] Fix a regression in the PE loader CORE-11717
which caused images to be loaded up to MmHighestUserAddress,
thus overwriting the shared user page.

This is now fixed by using MM_HIGHEST_VAD_ADDRESS as the margin instead.
This commit allows again to load WIN32K.sys of Win2K3SP2
which regressed by SVN 67793 == git
3565260212

cherry picked from commit 0.4.14-dev-143-g
56da95671c
2019-10-27 02:19:51 +02:00
Pierre Schweitzer 3b78ca210e
[NTOSKRNL] Simplify buffer definition in MiQueryMemorySectionName().
Also take into account the UNICODE_STRING structure while computing whole size
This is based on Thomas' patch.

CORE-12043
2019-09-29 14:16:44 +02:00
Timo Kreuzer 41250d1028 [NTOS:MM] Fix MmspCompareSegments
On x64 the previous implementation would only compare the upper 32 bits and ignore the lower 32 bits.
2019-09-01 14:15:07 +02:00
Serge Gautherie 66bf74d228 [NTOSKRNL] Move DPRINT1("Thread wants too much stack\n") around
To KiUserModeCallout() from MmGrowKernelStackEx().

As suggested by Thomas Faber:
"MmGrowKernelStackEx really shouldn't be DPRINT'ing."

CORE-14494
2019-08-15 18:18:59 +02:00
Timo Kreuzer de679e8f33 [NTOS:MM] MmSizeOfSystemCacheInPages is ULONG_PTR, not ULONG
Fixes failed assertion on x64.
2019-08-15 18:04:57 +02:00
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