https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7c006df7e0ea1fe3215137...
commit 7c006df7e0ea1fe3215137199bca7f4a0215a351 Author: Jérôme Gardou jerome.gardou@reactos.org AuthorDate: Wed Aug 4 20:35:14 2021 +0200 Commit: Jérôme Gardou jerome.gardou@reactos.org CommitDate: Wed Aug 4 20:38:37 2021 +0200
[NTOS:MM] Do proper checks & acquire proper locks when sweeping user pages
CORE-17595 --- ntoskrnl/mm/balance.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/ntoskrnl/mm/balance.c b/ntoskrnl/mm/balance.c index 0eec51fbb88..fe882aff6c4 100644 --- a/ntoskrnl/mm/balance.c +++ b/ntoskrnl/mm/balance.c @@ -213,15 +213,22 @@ MmTrimUserMemory(ULONG Target, ULONG Priority, PULONG NrFreedPages)
MmLockAddressSpace(&Process->Vm);
- /* Be sure this is still valid. */ - PMMPTE Pte = MiAddressToPte(Address); - if (Pte->u.Hard.Valid) + if (!Process->VmDeleted) { - Accessed = Accessed || Pte->u.Hard.Accessed; - Pte->u.Hard.Accessed = 0; + MiLockProcessWorkingSetUnsafe(Process, PsGetCurrentThread());
- /* There is no need to invalidate, the balancer thread is never on a user process */ - //KeInvalidateTlbEntry(Address); + /* Be sure this is still valid. */ + if (MmIsAddressValid(Address)) + { + PMMPTE Pte = MiAddressToPte(Address); + Accessed = Accessed || Pte->u.Hard.Accessed; + Pte->u.Hard.Accessed = 0; + + /* There is no need to invalidate, the balancer thread is never on a user process */ + //KeInvalidateTlbEntry(Address); + } + + MiUnlockProcessWorkingSet(Process, PsGetCurrentThread()); }
MmUnlockAddressSpace(&Process->Vm);