From 27917c14ed31ea24cf0a022200d9afd4e665009b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?George=20Bi=C8=99oc?= Date: Sun, 29 Oct 2023 20:34:54 +0100 Subject: [PATCH] [NTOS:CM] Flush the dirty data to disk if the SYSTEM hive has been recovered by FreeLdr If FreeLdr performed recovery against the SYSTEM hive with a log, all of its data is only present in volatile memory thus dirty. So the kernel is responsible to flush all the data that's been recovered within the SYSTEM hive into the backing storage. --- ntoskrnl/config/cmsysini.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ntoskrnl/config/cmsysini.c b/ntoskrnl/config/cmsysini.c index f65449d1962..d74fffe07da 100644 --- a/ntoskrnl/config/cmsysini.c +++ b/ntoskrnl/config/cmsysini.c @@ -1324,8 +1324,14 @@ CmpLoadHiveThread(IN PVOID StartContext) //ASSERT(FALSE); //} - /* Another thing we don't support is NTLDR-recovery */ - if (CmHive->Hive.BaseBlock->BootRecover) ASSERT(FALSE); + /* FreeLdr has recovered the hive with a log, we must do a flush */ + if (CmHive->Hive.BaseBlock->BootRecover == HBOOT_BOOT_RECOVERED_BY_HIVE_LOG) + { + DPRINT1("FreeLdr recovered the hive (hive 0x%p)\n", CmHive); + RtlSetAllBits(&CmHive->Hive.DirtyVector); + CmHive->Hive.DirtyCount = CmHive->Hive.DirtyVector.SizeOfBitMap; + HvSyncHive((PHHIVE)CmHive); + } /* Finally, set our allocated hive to the same hive we've had */ CmpMachineHiveList[i].CmHive2 = CmHive;