From afc27ab1aabd7e715abfbec509381ea1c8a04476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gardou?= Date: Mon, 7 Jun 2021 14:29:37 +0200 Subject: [PATCH] [NTOS:MM] Handle PT references for page table faults in MmAccessFault Idea from Timo Kreuzer --- ntoskrnl/mm/ARM3/pagfault.c | 9 ++++++++- ntoskrnl/mm/ARM3/virtual.c | 8 -------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ntoskrnl/mm/ARM3/pagfault.c b/ntoskrnl/mm/ARM3/pagfault.c index b6e2f9e8287..4656828a3b0 100644 --- a/ntoskrnl/mm/ARM3/pagfault.c +++ b/ntoskrnl/mm/ARM3/pagfault.c @@ -2314,7 +2314,14 @@ UserFault: * Check if this is a real user-mode address or actually a kernel-mode * page table for a user mode address */ - if (Address <= MM_HIGHEST_USER_ADDRESS) + if (Address <= MM_HIGHEST_USER_ADDRESS +#if _MI_PAGING_LEVELS >= 3 + || MiIsUserPte(Address) +#if _MI_PAGING_LEVELS == 4 + || MiIsUserPde(Address) +#endif +#endif + ) { /* Add an additional page table reference */ MiIncrementPageTableReferences(Address); diff --git a/ntoskrnl/mm/ARM3/virtual.c b/ntoskrnl/mm/ARM3/virtual.c index 27e2daa4241..0910d080542 100644 --- a/ntoskrnl/mm/ARM3/virtual.c +++ b/ntoskrnl/mm/ARM3/virtual.c @@ -2532,10 +2532,6 @@ MiMakePdeExistAndMakeValid(IN PMMPDE PointerPde, // if (!PointerPpe->u.Hard.Valid) { -#if _MI_PAGING_LEVELS == 4 - if (PointerPpe->u.Long == 0) - MiIncrementPageTableReferences(PointerPde); -#endif MiMakeSystemAddressValid(PointerPde, TargetProcess); ASSERT(PointerPpe->u.Hard.Valid == 1); } @@ -2544,10 +2540,6 @@ MiMakePdeExistAndMakeValid(IN PMMPDE PointerPde, // // And finally, make the PDE itself valid. // -#if _MI_PAGING_LEVELS >= 3 - if (PointerPde->u.Long == 0) - MiIncrementPageTableReferences(PointerPte); -#endif MiMakeSystemAddressValid(PointerPte, TargetProcess); /* Do not increment Page table refcount here for the PDE, this must be managed by caller */