Changeset 106945 in vbox for trunk/src/VBox/HostDrivers/Support
- Timestamp:
- Nov 12, 2024 2:41:36 AM (6 months ago)
- svn:sync-xref-src-repo-rev:
- 165871
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/Makefile.kmk
r106925 r106945 807 807 VBoxDrv_SOURCES.win += \ 808 808 win/SUPHardenedVerifyImage-win.cpp \ 809 win/SUPHardenedVerifyProcess-win.cpp \ 809 810 $(VBOX_SUP_WIN_CERTS_FILE) 810 ifdef VBOX_WITH_HARDENING811 VBoxDrv_SOURCES.win += \812 win/SUPHardenedVerifyProcess-win.cpp813 endif814 811 ifdef VBOX_WITHOUT_WINDOWS_KERNEL_CODE_SIGNING_CERT 815 812 VBoxDrv_DEFS.win += VBOX_WITHOUT_WINDOWS_KERNEL_CODE_SIGNING_CERT -
trunk/src/VBox/HostDrivers/Support/testcase/Makefile.kmk
r106061 r106945 78 78 SUPUninstall_LIBS = $(LIB_RUNTIME) 79 79 80 SUPLoggerCtl_TEMPLATE = VBoxR3 Exe80 SUPLoggerCtl_TEMPLATE = VBoxR3SignedExe 81 81 SUPLoggerCtl_SOURCES = SUPLoggerCtl.cpp 82 82 SUPLoggerCtl_LIBS = $(LIB_RUNTIME) 83 83 84 tstInt_TEMPLATE = VBoxR3 Exe84 tstInt_TEMPLATE = VBoxR3SignedExe 85 85 tstInt_DEFS = $(VMM_COMMON_DEFS) 86 86 tstInt_SOURCES = tstInt.cpp 87 87 tstInt_LIBS = $(LIB_RUNTIME) 88 88 89 tstContiguous_TEMPLATE = VBoxR3 TstExe89 tstContiguous_TEMPLATE = VBoxR3SignedTstExe 90 90 tstContiguous_SOURCES = tstContiguous.cpp 91 91 92 tstInit_TEMPLATE = VBoxR3 TstExe92 tstInit_TEMPLATE = VBoxR3SignedTstExe 93 93 tstInit_SOURCES = tstInit.cpp 94 94 95 tstLow_TEMPLATE = VBoxR3 TstExe95 tstLow_TEMPLATE = VBoxR3SignedTstExe 96 96 tstLow_SOURCES = tstLow.cpp 97 97 … … 100 100 tstNtQueryStuff_SOURCES = tstNtQueryStuff.cpp 101 101 102 tstPin_TEMPLATE = VBoxR3 TstExe102 tstPin_TEMPLATE = VBoxR3SignedTstExe 103 103 tstPin_SOURCES = tstPin.cpp 104 104 105 tstPage_TEMPLATE = VBoxR3 TstExe105 tstPage_TEMPLATE = VBoxR3SignedTstExe 106 106 tstPage_SOURCES = tstPage.cpp 107 107 … … 130 130 tstGIP-2_TEMPLATE := VBoxR3HardenedTstDll 131 131 else 132 tstGIP-2_TEMPLATE := VBoxR3 TstExe132 tstGIP-2_TEMPLATE := VBoxR3SignedTstExe 133 133 endif 134 134 tstGIP-2_SOURCES = tstGIP-2.cpp 135 135 136 tstGetPagingMode_TEMPLATE = VBoxR3 TstExe136 tstGetPagingMode_TEMPLATE = VBoxR3SignedTstExe 137 137 tstGetPagingMode_SOURCES = tstGetPagingMode.cpp 138 138 139 tstSupLoadModule_TEMPLATE = VBoxR3 TstExe139 tstSupLoadModule_TEMPLATE = VBoxR3SignedTstExe 140 140 tstSupLoadModule_SOURCES = tstSupLoadModule.cpp 141 141 142 tstSupSem_TEMPLATE = VBoxR3 TstExe142 tstSupSem_TEMPLATE = VBoxR3SignedTstExe 143 143 tstSupSem_SOURCES = tstSupSem.cpp 144 144 145 tstSupSem-Zombie_TEMPLATE = VBoxR3 TstExe145 tstSupSem-Zombie_TEMPLATE = VBoxR3SignedTstExe 146 146 tstSupSem-Zombie_SOURCES = tstSupSem-Zombie.cpp 147 147 148 tstSupTscDelta_TEMPLATE = VBoxR3 TstExe148 tstSupTscDelta_TEMPLATE = VBoxR3SignedTstExe 149 149 tstSupTscDelta_SOURCES = tstSupTscDelta.cpp 150 150 -
trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp
r106930 r106945 347 347 static NTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp); 348 348 static NTSTATUS VBoxDrvNtErr2NtStatus(int rc); 349 #if def VBOX_WITH_HARDENING349 #if defined(VBOX_WITH_HARDENING) || defined(VBOX_WITH_MINIMAL_HARDENING) 350 350 static NTSTATUS supdrvNtProtectInit(void); 351 351 static void supdrvNtProtectTerm(void); 352 #endif 353 #ifdef VBOX_WITH_HARDENING 352 354 static int supdrvNtProtectCreate(PSUPDRVNTPROTECT *ppNtProtect, HANDLE hPid, 353 355 SUPDRVNTPROTECTKIND enmProcessKind, bool fLink); … … 708 710 Log(("VBoxDrv::DriverEntry\n")); 709 711 710 #if def VBOX_WITH_HARDENING712 #if defined(VBOX_WITH_HARDENING) || defined(VBOX_WITH_MINIMAL_HARDENING) 711 713 /* 712 714 * Initialize process protection. … … 805 807 } 806 808 #endif 807 #if def VBOX_WITH_HARDENING809 #if defined(VBOX_WITH_HARDENING) || defined(VBOX_WITH_MINIMAL_HARDENING) 808 810 supdrvNtProtectTerm(); 809 811 #endif 810 812 } 811 #if def VBOX_WITH_HARDENING813 #if defined(VBOX_WITH_HARDENING) || defined(VBOX_WITH_MINIMAL_HARDENING) 812 814 else 813 815 DbgPrint("VBoxSup::DriverEntry: supdrvNtProtectInit failed with rcNt=%#x!\n", rcNt); … … 1260 1262 1261 1263 #else /* !VBOX_WITH_HARDENING */ 1264 # ifdef VBOX_WITH_MINIMAL_HARDENING 1262 1265 /* 1263 * Call common code to create a session. 1266 * Check that the process is allowed to access the device, i.e. the 1267 * process image is signed with the build certificate. 1264 1268 */ 1265 pFileObj->FsContext = NULL; 1266 PSUPDRVSESSION pSession; 1267 rc = supdrvCreateSession(pDevExt, true /*fUser*/, pDevObj == g_pDevObjSys /*fUnrestricted*/, &pSession); 1269 PRTERRINFOSTATIC pErrInfo = (PRTERRINFOSTATIC)RTMemAllocZ(sizeof(*pErrInfo)); 1270 rc = supHardenedWinVerifyProcess(NtCurrentProcess(), NtCurrentThread(), SUPHARDNTVPKIND_VERIFY_ONLY, 0 /*fFlags*/, 1271 NULL, pErrInfo ? RTErrInfoInitStatic(pErrInfo) : NULL); 1272 if (RT_FAILURE(rc)) 1273 SUPR0Printf("VBoxDrv: Checking process failed: %Rrc%#RTeim\n", rc, &pErrInfo->Core); 1274 RTMemFree(pErrInfo); 1275 1268 1276 if (RT_SUCCESS(rc)) 1269 { 1277 # endif 1278 { 1279 /* 1280 * Call common code to create a session. 1281 */ 1282 pFileObj->FsContext = NULL; 1283 PSUPDRVSESSION pSession; 1284 rc = supdrvCreateSession(pDevExt, true /*fUser*/, pDevObj == g_pDevObjSys /*fUnrestricted*/, &pSession); 1285 if (RT_SUCCESS(rc)) 1286 { 1270 1287 # ifdef VBOXDRV_WITH_SID_TO_UID_MAPPING 1271 rc = supdrvNtUserIdMakeForSession(pSession);1272 if (RT_SUCCESS(rc))1288 rc = supdrvNtUserIdMakeForSession(pSession); 1289 if (RT_SUCCESS(rc)) 1273 1290 # endif 1274 rc = supdrvSessionHashTabInsert(pDevExt, pSession, (PSUPDRVSESSION *)&pFileObj->FsContext, NULL); 1275 supdrvSessionRelease(pSession); 1276 if (RT_SUCCESS(rc)) 1277 return supdrvNtCompleteRequestEx(STATUS_SUCCESS, FILE_OPENED, pIrp); 1278 1291 rc = supdrvSessionHashTabInsert(pDevExt, pSession, (PSUPDRVSESSION *)&pFileObj->FsContext, NULL); 1292 supdrvSessionRelease(pSession); 1293 if (RT_SUCCESS(rc)) 1294 return supdrvNtCompleteRequestEx(STATUS_SUCCESS, FILE_OPENED, pIrp); 1295 1296 } 1279 1297 } 1280 1298 #endif /* !VBOX_WITH_HARDENING */ … … 5454 5472 5455 5473 # ifndef VBOX_WITHOUT_DEBUGGER_CHECKS 5456 5457 5474 /** 5458 5475 * Checks if the current process is being debugged. … … 5463 5480 return PsIsProcessBeingDebugged(PsGetCurrentProcess()) != FALSE; 5464 5481 } 5465 5466 5482 # endif /* !VBOX_WITHOUT_DEBUGGER_CHECKS */ 5467 5483 5484 #endif /* VBOX_WITH_HARDENING */ 5485 #if defined(VBOX_WITH_HARDENING) || defined(VBOX_WITH_MINIMAL_HARDENING) 5468 5486 5469 5487 /** … … 5472 5490 static void supdrvNtProtectTerm(void) 5473 5491 { 5492 # ifdef VBOX_WITH_HARDENING 5474 5493 /* 5475 5494 * Stop intercepting process and thread handle creation calls. … … 5508 5527 RTMemFree(pCur); 5509 5528 } 5529 # endif /* VBOX_WITH_HARDENING */ 5510 5530 5511 5531 supHardenedWinTermImageVerifier(); 5512 5532 } 5513 5533 5514 # ifdef RT_ARCH_X86 5534 # ifdef VBOX_WITH_HARDENING 5535 # ifdef RT_ARCH_X86 5515 5536 DECLASM(void) supdrvNtQueryVirtualMemory_0xAF(void); 5516 5537 DECLASM(void) supdrvNtQueryVirtualMemory_0xB0(void); … … 5529 5550 DECLASM(void) supdrvNtQueryVirtualMemory_0xBD(void); 5530 5551 DECLASM(void) supdrvNtQueryVirtualMemory_0xBE(void); 5531 # elif defined(RT_ARCH_AMD64)5552 # elif defined(RT_ARCH_AMD64) 5532 5553 DECLASM(void) supdrvNtQueryVirtualMemory_0x1F(void); 5533 5554 DECLASM(void) supdrvNtQueryVirtualMemory_0x20(void); … … 5536 5557 DECLASM(void) supdrvNtQueryVirtualMemory_0x23(void); 5537 5558 extern "C" NTSYSAPI NTSTATUS NTAPI ZwRequestWaitReplyPort(HANDLE, PVOID, PVOID); 5538 # endif 5559 # endif 5560 # endif /* VBOX_WITH_HARDENING */ 5539 5561 5540 5562 … … 5550 5572 */ 5551 5573 5574 # ifdef VBOX_WITH_HARDENING 5552 5575 /* Resolve methods we want but isn't available everywhere. */ 5553 5576 UNICODE_STRING RoutineName; … … 5582 5605 ZwReadFile with a different eax value. We figure the syscall number 5583 5606 by inspecting ZwQueryVolumeInformationFile as it's the next number. */ 5584 # ifdef RT_ARCH_X865607 # ifdef RT_ARCH_X86 5585 5608 uint8_t const *pbCode = (uint8_t const *)(uintptr_t)ZwQueryVolumeInformationFile; 5586 5609 if (*pbCode == 0xb8) /* mov eax, dword */ … … 5604 5627 case 0xbf: g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)supdrvNtQueryVirtualMemory_0xBE; break; /* just in case */ 5605 5628 } 5606 # elif defined(RT_ARCH_AMD64)5629 # elif defined(RT_ARCH_AMD64) 5607 5630 uint8_t const *pbCode = (uint8_t const *)(uintptr_t)ZwRequestWaitReplyPort; 5608 5631 if ( pbCode[ 0] == 0x48 /* mov rax, rsp */ … … 5646 5669 } 5647 5670 } 5648 # endif5671 # endif 5649 5672 } 5650 5673 if (!g_pfnNtQueryVirtualMemory) … … 5654 5677 } 5655 5678 5656 # ifdef VBOX_STRICT 5679 # else /* !VBOX_WITH_HARDENING */ 5680 /* Always present on arm64 and more recent systems. */ 5681 g_pfnNtQueryVirtualMemory = (PFNNTQUERYVIRTUALMEMORY)ZwQueryVirtualMemory; 5682 # endif /* !VBOX_WITH_HARDENING */ 5683 5684 NTSTATUS rcNt; 5685 int rc; 5686 5687 # ifdef VBOX_WITH_HARDENING 5688 # ifdef VBOX_STRICT 5657 5689 if ( g_uNtVerCombined >= SUP_NT_VER_W70 5658 5690 && ( g_pfnObGetObjectType == NULL … … 5662 5694 return STATUS_PROCEDURE_NOT_FOUND; 5663 5695 } 5664 # endif5696 # endif 5665 5697 5666 5698 /* LPC object type. */ … … 5668 5700 5669 5701 /* The spinlock protecting our structures. */ 5670 intrc = RTSpinlockCreate(&g_hNtProtectLock, RTSPINLOCK_FLAGS_INTERRUPT_UNSAFE, "NtProtectLock");5702 rc = RTSpinlockCreate(&g_hNtProtectLock, RTSPINLOCK_FLAGS_INTERRUPT_UNSAFE, "NtProtectLock"); 5671 5703 if (RT_FAILURE(rc)) 5672 5704 return VBoxDrvNtErr2NtStatus(rc); 5673 5705 g_NtProtectTree = NULL; 5674 5675 NTSTATUS rcNt;5676 5706 5677 5707 /* The mutex protecting the error information. */ … … 5680 5710 if (RT_SUCCESS(rc)) 5681 5711 { 5712 # endif /* VBOX_WITH_HARDENING */ 5682 5713 /* Image stuff + certificates. */ 5683 5714 rc = supHardenedWinInitImageVerifier(NULL); 5684 5715 if (RT_SUCCESS(rc)) 5685 5716 { 5717 # ifdef VBOX_WITH_HARDENING 5686 5718 /* 5687 5719 * Intercept process creation and termination. … … 5745 5777 if (NT_SUCCESS(rcNt)) 5746 5778 { 5779 # endif /* VBOX_WITH_HARDENING */ 5747 5780 /* 5748 5781 * Happy ending. 5749 5782 */ 5750 5783 return STATUS_SUCCESS; 5784 # ifdef VBOX_WITH_HARDENING 5751 5785 } 5752 5786 } … … 5801 5835 } 5802 5836 supHardenedWinTermImageVerifier(); 5837 # endif /* VBOX_WITH_HARDENING */ 5803 5838 } 5804 5839 else 5805 5840 rcNt = VBoxDrvNtErr2NtStatus(rc); 5806 5841 5842 # ifdef VBOX_WITH_HARDENING 5807 5843 RTSemMutexDestroy(g_hErrorInfoLock); 5808 5844 g_hErrorInfoLock = NIL_RTSEMMUTEX; … … 5813 5849 RTSpinlockDestroy(g_hNtProtectLock); 5814 5850 g_NtProtectTree = NIL_RTSPINLOCK; 5851 # endif 5815 5852 return rcNt; 5816 5853 } 5817 5854 5818 #endif /* VBOX_WITH_HARDENING */5819 5855 #endif /* VBOX_WITH_HARDENING || VBOX_WITH_MINIMAL_HARDENING */ 5856 -
trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyProcess-win.cpp
r106893 r106945 74 74 #endif 75 75 76 #ifdef VBOX_WITH_MINIMAL_HARDENING 77 # define IMAGE_LOG_NAME_FMT "%ls" 78 # define IMAGE_LOG_NAME(pImage) ((pImage)->Name.awcBuffer) 79 #else 80 # define IMAGE_LOG_NAME_FMT "%s" 81 # define IMAGE_LOG_NAME(pImage) ((pImage)->pszName) 82 #endif 76 83 77 84 … … 104 111 uintptr_t cbImage; 105 112 113 #ifndef VBOX_WITH_MINIMAL_HARDENING 106 114 /** The name from the allowed lists. */ 107 115 const char *pszName; 116 #endif 108 117 /** Name structure for NtQueryVirtualMemory/MemorySectionName. */ 109 118 struct … … 256 265 "tstRTR0TimerDriver.exe", 257 266 "tstSSM.exe", 267 "tstInt.exe", 258 268 }; 259 269 … … 484 494 if (!NT_SUCCESS(rcNt)) 485 495 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_MEMORY_READ_ERROR, 486 "%s: Error reading %#x bytes at %p (rva %#x, #%u, %.8s) from memory: %#x",487 pImage->pszName, cbThis, pImage->uImageBase + uRva, uRva, iSh + 1,496 IMAGE_LOG_NAME_FMT ": Error reading %#x bytes at %p (rva %#x, #%u, %.8s) from memory: %#x", 497 IMAGE_LOG_NAME(pImage), cbThis, pImage->uImageBase + uRva, uRva, iSh + 1, 488 498 iSh >= 0 ? (char *)pThis->aSecHdrs[iSh].Name : "headers", rcNt); 489 499 … … 492 502 { 493 503 const char *pachSectNm = iSh >= 0 ? (char *)pThis->aSecHdrs[iSh].Name : "headers"; 494 SUP_DPRINTF(("%s: Differences in section #%u (%s) between file and memory:\n", pImage->pszName, iSh + 1, pachSectNm)); 504 SUP_DPRINTF((IMAGE_LOG_NAME_FMT ": Differences in section #%u (%s) between file and memory:\n", 505 IMAGE_LOG_NAME(pImage), iSh + 1, pachSectNm)); 495 506 496 507 uint32_t off = 0; … … 521 532 else 522 533 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_MEMORY_VS_FILE_MISMATCH, 523 "%s: Failed to restore %#x bytes at %p (%#x, #%u, %s): %#x (cDiffs=%#x, first=%#x)",524 pImage->pszName, cbThis, pvRestoreAddr, uRva, iSh + 1, pachSectNm, rcNt,534 IMAGE_LOG_NAME_FMT ": Failed to restore %#x bytes at %p (%#x, #%u, %s): %#x (cDiffs=%#x, first=%#x)", 535 IMAGE_LOG_NAME(pImage), cbThis, pvRestoreAddr, uRva, iSh + 1, pachSectNm, rcNt, 525 536 cDiffs, uRva + off); 526 537 } … … 528 539 #endif /* IN_RING3 */ 529 540 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_MEMORY_VS_FILE_MISMATCH, 530 "%s: %u differences between %#x and %#x in #%u (%.8s), first: %02x != %02x",531 pImage->pszName, cDiffs, uRva + off, uRva + offLast, iSh + 1,541 IMAGE_LOG_NAME_FMT ": %u differences between %#x and %#x in #%u (%.8s), first: %02x != %02x", 542 IMAGE_LOG_NAME(pImage), cDiffs, uRva + off, uRva + offLast, iSh + 1, 532 543 pachSectNm, pbFile[off], pbMemory[off]); 533 544 } … … 567 578 || pImage->aRegions[i].fProt != PAGE_WRITECOPY)) 568 579 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_SECTION_PROTECTION_MISMATCH, 569 "%s: RVA range %#x-%#x protection is %#x, expected %#x. (cb=%#x)",570 pImage->pszName, uRva, uRva + cbLeft - 1, pImage->aRegions[i].fProt, fProt, cb);580 IMAGE_LOG_NAME_FMT ": RVA range %#x-%#x protection is %#x, expected %#x. (cb=%#x)", 581 IMAGE_LOG_NAME(pImage), uRva, uRva + cbLeft - 1, pImage->aRegions[i].fProt, fProt, cb); 571 582 if (cbLeft >= cb) 572 583 return VINF_SUCCESS; … … 589 600 590 601 return supHardNtVpSetInfo2(pThis, cbOrg == cb ? VERR_SUP_VP_SECTION_NOT_MAPPED : VERR_SUP_VP_SECTION_NOT_FULLY_MAPPED, 591 "%s: RVA range %#x-%#x is not mapped?", pImage->pszName, uRva, uRva + cb - 1); 592 } 593 602 IMAGE_LOG_NAME_FMT ": RVA range %#x-%#x is not mapped?", IMAGE_LOG_NAME(pImage), uRva, uRva + cb - 1); 603 } 604 605 #ifndef VBOX_WITH_MINIMAL_HARDENING 594 606 595 607 DECLINLINE(bool) supHardNtVpIsModuleNameMatch(PSUPHNTVPIMAGE pImage, const char *pszModule) … … 658 670 } 659 671 672 #endif /* !VBOX_WITH_MINIMAL_HARDENING */ 673 660 674 661 675 /** … … 665 679 PRTLDRADDR pValue, void *pvUser) 666 680 { 681 /*SUP_DPRINTF(("supHardNtVpGetImport: %s / %#x / %s.\n", pszModule, uSymbol, pszSymbol));*/ 682 PSUPHNTVPSTATE const pThis = (PSUPHNTVPSTATE)pvUser; 683 684 #ifndef VBOX_WITH_MINIMAL_HARDENING 667 685 RT_NOREF1(hLdrMod); 668 /*SUP_DPRINTF(("supHardNtVpGetImport: %s / %#x / %s.\n", pszModule, uSymbol, pszSymbol));*/669 PSUPHNTVPSTATE pThis = (PSUPHNTVPSTATE)pvUser;670 686 671 687 int rc = VERR_MODULE_NOT_FOUND; … … 738 754 uSymbol, pszSymbol, pszModule, rc)); 739 755 return rc; 756 757 #else /* VBOX_WITH_MINIMAL_HARDENING */ 758 /* 759 * We don't care about correct imports here, as we will skip the import 760 * table while comparing image bits. (If we wanted to produce correct 761 * imports, we'd have to track all the DLLs in the process, which would be 762 * bothersome and expensive while not really gaining any better certainty 763 * that we are actually executing the image we're looking at.) 764 */ 765 RT_NOREF(hLdrMod, pszModule, pszSymbol, uSymbol); 766 *pValue = pThis->aImages[0].uImageBase - PAGE_SIZE; 767 return VINF_SUCCESS; 768 #endif /* VBOX_WITH_MINIMAL_HARDENING */ 740 769 } 741 770 … … 759 788 if (RT_FAILURE(rc)) 760 789 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_IMAGE_HDR_READ_ERROR, 761 "%s: Error reading image header: %Rrc", pImage->pszName, rc);790 IMAGE_LOG_NAME_FMT ": Error reading image header: %Rrc", IMAGE_LOG_NAME(pImage), rc); 762 791 763 792 uint32_t offNtHdrs = 0; … … 768 797 if (offNtHdrs > 512 || offNtHdrs < sizeof(*pDosHdr)) 769 798 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_MZ_OFFSET, 770 "%s: Unexpected e_lfanew value: %#x", pImage->pszName, offNtHdrs);799 IMAGE_LOG_NAME_FMT ": Unexpected e_lfanew value: %#x", IMAGE_LOG_NAME(pImage), offNtHdrs); 771 800 } 772 801 PIMAGE_NT_HEADERS pNtHdrs = (PIMAGE_NT_HEADERS)&pThis->abFile[offNtHdrs]; … … 774 803 if (pNtHdrs->Signature != IMAGE_NT_SIGNATURE) 775 804 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_IMAGE_SIGNATURE, 776 "%s: No PE signature at %#x: %#x", pImage->pszName, offNtHdrs, pNtHdrs->Signature);805 IMAGE_LOG_NAME_FMT ": No PE signature at %#x: %#x", IMAGE_LOG_NAME(pImage), offNtHdrs, pNtHdrs->Signature); 777 806 778 807 /* … … 794 823 #endif 795 824 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_UNEXPECTED_IMAGE_MACHINE, 796 "%s: Unexpected machine: %#x (expected %#x)",797 pImage->pszName, pNtHdrs->FileHeader.Machine, uExpectedMachine);825 IMAGE_LOG_NAME_FMT ": Unexpected machine: %#x (expected %#x)", 826 IMAGE_LOG_NAME(pImage), pNtHdrs->FileHeader.Machine, uExpectedMachine); 798 827 bool const fIs32Bit = pNtHdrs->FileHeader.Machine == IMAGE_FILE_MACHINE_I386; 799 828 800 829 if (pNtHdrs->FileHeader.SizeOfOptionalHeader != (fIs32Bit ? sizeof(IMAGE_OPTIONAL_HEADER32) : sizeof(IMAGE_OPTIONAL_HEADER64))) 801 830 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_OPTIONAL_HEADER, 802 "%s: Unexpected optional header size: %#x",803 pImage->pszName, pNtHdrs->FileHeader.SizeOfOptionalHeader);831 IMAGE_LOG_NAME_FMT ": Unexpected optional header size: %#x", 832 IMAGE_LOG_NAME(pImage), pNtHdrs->FileHeader.SizeOfOptionalHeader); 804 833 805 834 if (pNtHdrs->OptionalHeader.Magic != (fIs32Bit ? IMAGE_NT_OPTIONAL_HDR32_MAGIC : IMAGE_NT_OPTIONAL_HDR64_MAGIC)) 806 835 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_OPTIONAL_HEADER, 807 "%s: Unexpected optional header magic: %#x", pImage->pszName, pNtHdrs->OptionalHeader.Magic);836 IMAGE_LOG_NAME_FMT ": Unexpected optional header magic: %#x", IMAGE_LOG_NAME(pImage), pNtHdrs->OptionalHeader.Magic); 808 837 809 838 uint32_t cDirs = (fIs32Bit ? pNtHdrs32->OptionalHeader.NumberOfRvaAndSizes : pNtHdrs->OptionalHeader.NumberOfRvaAndSizes); 810 839 if (cDirs != IMAGE_NUMBEROF_DIRECTORY_ENTRIES) 811 840 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_OPTIONAL_HEADER, 812 "%s: Unexpected data dirs: %#x", pImage->pszName, cDirs);841 IMAGE_LOG_NAME_FMT ": Unexpected data dirs: %#x", IMAGE_LOG_NAME(pImage), cDirs); 813 842 814 843 /* … … 818 847 if (cSections > RT_ELEMENTS(pThis->aSecHdrs)) 819 848 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_TOO_MANY_SECTIONS, 820 "%s: Too many section headers: %#x", pImage->pszName, cSections);849 IMAGE_LOG_NAME_FMT ": Too many section headers: %#x", IMAGE_LOG_NAME(pImage), cSections); 821 850 suplibHardenedMemCopy(pThis->aSecHdrs, (fIs32Bit ? (void *)(pNtHdrs32 + 1) : (void *)(pNtHdrs + 1)), 822 851 cSections * sizeof(IMAGE_SECTION_HEADER)); … … 825 854 if (uImageBase & PAGE_OFFSET_MASK) 826 855 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_IMAGE_BASE, 827 "%s: Invalid image base: %p", pImage->pszName, uImageBase);856 IMAGE_LOG_NAME_FMT ": Invalid image base: %p", IMAGE_LOG_NAME(pImage), uImageBase); 828 857 829 858 uint32_t const cbImage = fIs32Bit ? pNtHdrs32->OptionalHeader.SizeOfImage : pNtHdrs->OptionalHeader.SizeOfImage; … … 840 869 if (pImage->cbImage < cbImagePgAligned) 841 870 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_IMAGE_SIZE, 842 "%s: SizeOfImage (%#x) is larger than the mapping size (%#x)",843 pImage->pszName, cbImage, pImage->cbImage);871 IMAGE_LOG_NAME_FMT ": SizeOfImage (%#x) is larger than the mapping size (%#x)", 872 IMAGE_LOG_NAME(pImage), cbImage, pImage->cbImage); 844 873 845 874 /* This code has to be paranoid, so we must put some kind of limit on this extra … … 847 876 if (pImage->cbImage > cbImagePgAligned + _64K) 848 877 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_IMAGE_SIZE, 849 "%s: SizeOfImage (%#x) isn't close enough to the mapping size (%#x) - diff %#x bytes; max expected is 64KB",850 pImage->pszName, cbImage, pImage->cbImage, pImage->cbImage - cbImage);878 IMAGE_LOG_NAME_FMT ": SizeOfImage (%#x) isn't close enough to the mapping size (%#x) - diff %#x bytes; max expected is 64KB", 879 IMAGE_LOG_NAME(pImage), cbImage, pImage->cbImage, pImage->cbImage - cbImage); 851 880 852 881 /* Locate the mapping region for the extra pages: */ 853 882 if (pImage->cRegions <= 1) 854 883 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_IMAGE_SIZE, 855 "%s: SizeOfImage (%#x) is smaller than the mapping size (%#x) and there are less than two mapping regions!",856 pImage->pszName, cbImage, pImage->cbImage);884 IMAGE_LOG_NAME_FMT ": SizeOfImage (%#x) is smaller than the mapping size (%#x) and there are less than two mapping regions!", 885 IMAGE_LOG_NAME(pImage), cbImage, pImage->cbImage); 857 886 uint32_t iRegion = pImage->cRegions - 1; 858 887 while (iRegion > 0 && pImage->aRegions[iRegion].uRva > cbImagePgAligned) … … 860 889 if (pImage->aRegions[iRegion].uRva != cbImagePgAligned) 861 890 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_IMAGE_SIZE, 862 "%s: SizeOfImage (%#x) is smaller than the mapping size (%#x) and we cannot locate the region(s) for the extra space! (iRegion=%d: uRva=%#x, expected %#x)",863 pImage->pszName, cbImage, pImage->cbImage, iRegion, pImage->aRegions[iRegion].uRva,891 IMAGE_LOG_NAME_FMT ": SizeOfImage (%#x) is smaller than the mapping size (%#x) and we cannot locate the region(s) for the extra space! (iRegion=%d: uRva=%#x, expected %#x)", 892 IMAGE_LOG_NAME(pImage), cbImage, pImage->cbImage, iRegion, pImage->aRegions[iRegion].uRva, 864 893 cbImagePgAligned); 865 894 … … 868 897 if (pImage->aRegions[i].fProt & PAGE_EXECUTE_READWRITE) 869 898 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_IMAGE_SIZE, 870 "%s: SizeOfImage (%#x) is smaller than the mapping size (%#x) and extra page %#x LB %#x are RWX (%#x)!",871 pImage->pszName, cbImage, pImage->cbImage,899 IMAGE_LOG_NAME_FMT ": SizeOfImage (%#x) is smaller than the mapping size (%#x) and extra page %#x LB %#x are RWX (%#x)!", 900 IMAGE_LOG_NAME(pImage), cbImage, pImage->cbImage, 872 901 pImage->aRegions[i].uRva, pImage->aRegions[i].cb, pImage->aRegions[i].fProt); 873 902 /** @todo more restrictions on this? */ … … 876 905 if (cbImage != RTLdrSize(pImage->pCacheEntry->hLdrMod)) 877 906 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_IMAGE_SIZE, 878 "%s: SizeOfImage (%#x) differs from what RTLdrSize returns (%#zx)",879 pImage->pszName, cbImage, RTLdrSize(pImage->pCacheEntry->hLdrMod));907 IMAGE_LOG_NAME_FMT ": SizeOfImage (%#x) differs from what RTLdrSize returns (%#zx)", 908 IMAGE_LOG_NAME(pImage), cbImage, RTLdrSize(pImage->pCacheEntry->hLdrMod)); 880 909 881 910 uint32_t const cbSectAlign = fIs32Bit ? pNtHdrs32->OptionalHeader.SectionAlignment : pNtHdrs->OptionalHeader.SectionAlignment; … … 884 913 || cbSectAlign > (pImage->fApiSetSchemaOnlySection1 ? _64K : (uint32_t)PAGE_SIZE) ) 885 914 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_SECTION_ALIGNMENT_VALUE, 886 "%s: Unexpected SectionAlignment value: %#x", pImage->pszName, cbSectAlign);915 IMAGE_LOG_NAME_FMT ": Unexpected SectionAlignment value: %#x", IMAGE_LOG_NAME(pImage), cbSectAlign); 887 916 888 917 uint32_t const cbFileAlign = fIs32Bit ? pNtHdrs32->OptionalHeader.FileAlignment : pNtHdrs->OptionalHeader.FileAlignment; 889 918 if (!RT_IS_POWER_OF_TWO(cbFileAlign) || cbFileAlign < 512 || cbFileAlign > PAGE_SIZE || cbFileAlign > cbSectAlign) 890 919 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_FILE_ALIGNMENT_VALUE, 891 "%s: Unexpected FileAlignment value: %#x (cbSectAlign=%#x)",892 pImage->pszName, cbFileAlign, cbSectAlign);920 IMAGE_LOG_NAME_FMT ": Unexpected FileAlignment value: %#x (cbSectAlign=%#x)", 921 IMAGE_LOG_NAME(pImage), cbFileAlign, cbSectAlign); 893 922 894 923 uint32_t const cbHeaders = fIs32Bit ? pNtHdrs32->OptionalHeader.SizeOfHeaders : pNtHdrs->OptionalHeader.SizeOfHeaders; … … 897 926 if (cbHeaders < cbMinHdrs) 898 927 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_SIZE_OF_HEADERS, 899 "%s: Headers are too small: %#x < %#x (cSections=%#x)",900 pImage->pszName, cbHeaders, cbMinHdrs, cSections);928 IMAGE_LOG_NAME_FMT ": Headers are too small: %#x < %#x (cSections=%#x)", 929 IMAGE_LOG_NAME(pImage), cbHeaders, cbMinHdrs, cSections); 901 930 uint32_t const cbHdrsFile = RT_ALIGN_32(cbHeaders, cbFileAlign); 902 931 if (cbHdrsFile > sizeof(pThis->abFile)) 903 932 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_SIZE_OF_HEADERS, 904 "%s: Headers are larger than expected: %#x/%#x (expected max %zx)",905 pImage->pszName, cbHeaders, cbHdrsFile, sizeof(pThis->abFile));933 IMAGE_LOG_NAME_FMT ": Headers are larger than expected: %#x/%#x (expected max %zx)", 934 IMAGE_LOG_NAME(pImage), cbHeaders, cbHdrsFile, sizeof(pThis->abFile)); 906 935 907 936 /* … … 948 977 uint32_t cSkipAreas = 0; 949 978 SUPHNTVPSKIPAREA aSkipAreas[7]; 979 #ifndef VBOX_WITH_MINIMAL_HARDENING 950 980 if (pImage->fNtCreateSectionPatch) 951 981 { … … 982 1012 aSkipAreas[cSkipAreas++].cb = 14; 983 1013 984 # ifndef VBOX_WITHOUT_HARDENDED_XCPT_LOGGING1014 # ifndef VBOX_WITHOUT_HARDENDED_XCPT_LOGGING 985 1015 /* Ignore our patched KiUserExceptionDispatcher hack. */ 986 1016 rc = RTLdrGetSymbolEx(pImage->pCacheEntry->hLdrMod, pbBits, 0, UINT32_MAX, "KiUserExceptionDispatcher", &uValue); … … 989 1019 aSkipAreas[cSkipAreas].uRva = (uint32_t)uValue + (HC_ARCH_BITS == 64); 990 1020 aSkipAreas[cSkipAreas++].cb = HC_ARCH_BITS == 64 ? 13 : 12; 991 # endif1021 # endif 992 1022 993 1023 /* LdrSystemDllInitBlock is filled in by the kernel. It mainly contains addresses of 32-bit ntdll method for wow64. */ … … 1001 1031 Assert(cSkipAreas <= RT_ELEMENTS(aSkipAreas)); 1002 1032 } 1033 1034 #else /* VBOX_WITH_MINIMAL_HARDENING */ 1035 # if 0 /* This is .rdata stuff, which it turns out contains more random stuff modified via the loadcfg. So, skipping it .rdata. */ 1036 /* Skip the IAT as we don't process fixups correctly. */ 1037 uint32_t const offAfterHdrs = offNtHdrs 1038 + (!fIs32Bit ? pNtHdrs->OptionalHeader.SizeOfHeaders : pNtHdrs32->OptionalHeader.SizeOfHeaders); 1039 aSkipAreas[cSkipAreas].uRva = !fIs32Bit 1040 ? pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress 1041 : pNtHdrs32->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress; 1042 aSkipAreas[cSkipAreas].cb = !fIs32Bit 1043 ? pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].Size 1044 : pNtHdrs32->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].Size; 1045 if ( aSkipAreas[cSkipAreas].cb > 0 1046 && aSkipAreas[cSkipAreas].cb < pImage->cbImage / 4 1047 && aSkipAreas[cSkipAreas].uRva > offAfterHdrs 1048 && aSkipAreas[cSkipAreas].uRva < pImage->cbImage 1049 && aSkipAreas[cSkipAreas].uRva + aSkipAreas[cSkipAreas].cb <= pImage->cbImage) 1050 cSkipAreas++; 1051 # endif 1052 #endif /* VBOX_WITH_MINIMAL_HARDENING */ 1003 1053 1004 1054 /* … … 1030 1080 if (uSectRva < uRva || uSectRva > cbImage || RT_ALIGN_32(uSectRva, cbSectAlign) != uSectRva) 1031 1081 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_SECTION_RVA, 1032 "%s: Section %u: Invalid virtual address: %#x (uRva=%#x, cbImage=%#x, cbSectAlign=%#x)",1033 pImage->pszName, i, uSectRva, uRva, cbImage, cbSectAlign);1082 IMAGE_LOG_NAME_FMT ": Section %u: Invalid virtual address: %#x (uRva=%#x, cbImage=%#x, cbSectAlign=%#x)", 1083 IMAGE_LOG_NAME(pImage), i, uSectRva, uRva, cbImage, cbSectAlign); 1034 1084 uint32_t cbMap = pThis->aSecHdrs[i].Misc.VirtualSize; 1035 1085 if (cbMap > cbImage || uRva + cbMap > cbImage) 1036 1086 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_SECTION_VIRTUAL_SIZE, 1037 "%s: Section %u: Invalid virtual size: %#x (uSectRva=%#x, uRva=%#x, cbImage=%#x)",1038 pImage->pszName, i, cbMap, uSectRva, uRva, cbImage);1087 IMAGE_LOG_NAME_FMT ": Section %u: Invalid virtual size: %#x (uSectRva=%#x, uRva=%#x, cbImage=%#x)", 1088 IMAGE_LOG_NAME(pImage), i, cbMap, uSectRva, uRva, cbImage); 1039 1089 uint32_t cbFile = pThis->aSecHdrs[i].SizeOfRawData; 1040 1090 if (cbFile != RT_ALIGN_32(cbFile, cbFileAlign) || cbFile > RT_ALIGN_32(cbMap, cbSectAlign)) 1041 1091 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_SECTION_FILE_SIZE, 1042 "%s: Section %u: Invalid file size: %#x (cbMap=%#x, uSectRva=%#x)",1043 pImage->pszName, i, cbFile, cbMap, uSectRva);1092 IMAGE_LOG_NAME_FMT ": Section %u: Invalid file size: %#x (cbMap=%#x, uSectRva=%#x)", 1093 IMAGE_LOG_NAME(pImage), i, cbFile, cbMap, uSectRva); 1044 1094 1045 1095 /* Validate the protection and bits. */ … … 1078 1128 default: 1079 1129 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_UNEXPECTED_SECTION_FLAGS, 1080 "%s: Section %u: Unexpected characteristics: %#x (uSectRva=%#x, cbMap=%#x)",1081 pImage->pszName, i, pThis->aSecHdrs[i].Characteristics, uSectRva, cbMap);1130 IMAGE_LOG_NAME_FMT ": Section %u: Unexpected characteristics: %#x (uSectRva=%#x, cbMap=%#x)", 1131 IMAGE_LOG_NAME(pImage), i, pThis->aSecHdrs[i].Characteristics, uSectRva, cbMap); 1082 1132 } 1083 1133 … … 1087 1137 if ( ( (pThis->aSecHdrs[i].Characteristics & (IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_CNT_CODE)) 1088 1138 && !(pThis->aSecHdrs[i].Characteristics & IMAGE_SCN_MEM_WRITE)) 1139 #ifndef VBOX_WITH_MINIMAL_HARDENING /* only executable segments */ 1089 1140 || (pThis->aSecHdrs[i].Characteristics & (IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE)) == IMAGE_SCN_MEM_READ 1090 1141 || (pThis->enmKind == SUPHARDNTVPKIND_VERIFY_ONLY && pImage->fDll) 1091 || pThis->enmKind == SUPHARDNTVPKIND_CHILD_PURIFICATION) 1142 || pThis->enmKind == SUPHARDNTVPKIND_CHILD_PURIFICATION 1143 #endif 1144 ) 1092 1145 { 1093 1146 rc = VINF_SUCCESS; … … 1376 1429 cwcDirName--; 1377 1430 1431 #ifndef VBOX_WITH_MINIMAL_HARDENING 1378 1432 /* 1379 1433 * Match it against known DLLs. … … 1386 1440 pImage->fDll = true; 1387 1441 1388 # ifndef VBOX_PERMIT_VISUAL_STUDIO_PROFILING1442 # ifndef VBOX_PERMIT_VISUAL_STUDIO_PROFILING 1389 1443 /* The directory name must match the one we've got for System32. */ 1390 1444 if ( ( cwcDirName * sizeof(WCHAR) != g_System32NtPath.UniStr.Length 1391 1445 || suplibHardenedMemComp(pLongName->Buffer, g_System32NtPath.UniStr.Buffer, cwcDirName * sizeof(WCHAR)) ) 1392 # ifdef VBOX_PERMIT_MORE1446 # ifdef VBOX_PERMIT_MORE 1393 1447 && ( pImage->pszName[0] != 'a' 1394 1448 || pImage->pszName[1] != 'c' 1395 1449 || !supHardViIsAppPatchDir(pLongName->Buffer, pLongName->Length / sizeof(WCHAR)) ) 1396 # endif1450 # endif 1397 1451 ) 1398 1452 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_NON_SYSTEM32_DLL, 1399 1453 "Expected %ls to be loaded from %ls.", 1400 1454 pLongName->Buffer, g_System32NtPath.UniStr.Buffer); 1401 # ifdef VBOX_PERMIT_MORE1455 # ifdef VBOX_PERMIT_MORE 1402 1456 if (g_uNtVerCombined < SUP_NT_VER_W70 && i >= VBOX_PERMIT_MORE_FIRST_IDX) 1403 1457 pImage->pszName = NULL; /* hard limit: user32.dll is unwanted prior to w7. */ 1404 # endif1405 1406 # endif /* VBOX_PERMIT_VISUAL_STUDIO_PROFILING */1458 # endif 1459 1460 # endif /* VBOX_PERMIT_VISUAL_STUDIO_PROFILING */ 1407 1461 break; 1408 1462 } 1409 1463 if (!pImage->pszName) 1464 #endif /* !VBOX_WITH_MINIMAL_HARDENING */ 1410 1465 { 1411 1466 /* 1412 1467 * Not a known DLL, is it a known executable? 1413 1468 */ 1469 #ifdef VBOX_WITH_MINIMAL_HARDENING 1470 pImage->fDll = true; 1471 #endif 1414 1472 for (uint32_t i = 0; i < RT_ELEMENTS(g_apszSupNtVpAllowedVmExes); i++) 1415 1473 if (supHardNtVpAreNamesEqual(g_apszSupNtVpAllowedVmExes[i], pwszFilename)) 1416 1474 { 1475 #ifndef VBOX_WITH_MINIMAL_HARDENING 1417 1476 pImage->pszName = g_apszSupNtVpAllowedVmExes[i]; 1477 #endif 1418 1478 pImage->fDll = false; 1419 1479 break; 1420 1480 } 1421 1481 } 1482 #ifndef VBOX_WITH_MINIMAL_HARDENING 1422 1483 if (!pImage->pszName) 1423 1484 { … … 1429 1490 * as in "may you live in interesting times". 1430 1491 */ 1431 # ifdef IN_RING31492 # ifdef IN_RING3 1432 1493 if ( pMemInfo->AllocationBase == pMemInfo->BaseAddress 1433 1494 && pThis->enmKind == SUPHARDNTVPKIND_CHILD_PURIFICATION) … … 1447 1508 return VINF_OBJECT_DESTROYED; 1448 1509 } 1449 # endif1510 # endif 1450 1511 /* 1451 1512 * Special error message if we can. … … 1479 1540 "Duplicate image entries for %s: %ls and %ls", 1480 1541 pImage->pszName, pImage->Name.UniStr.Buffer, pThis->aImages[i].Name.UniStr.Buffer); 1542 #endif /* !VBOX_WITH_MINIMAL_HARDENING */ 1481 1543 1482 1544 /* … … 1485 1547 if (pMemInfo->AllocationBase != pMemInfo->BaseAddress) 1486 1548 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_IMAGE_MAPPING_BASE_ERROR, 1487 "Invalid AllocationBase/BaseAddress for %s: %p vs %p.",1488 pImage->pszName, pMemInfo->AllocationBase, pMemInfo->BaseAddress);1549 "Invalid AllocationBase/BaseAddress for " IMAGE_LOG_NAME_FMT ": %p vs %p.", 1550 IMAGE_LOG_NAME(pImage), pMemInfo->AllocationBase, pMemInfo->BaseAddress); 1489 1551 1490 1552 /* … … 1493 1555 if (pMemInfo->RegionSize >= _2G) 1494 1556 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_TOO_LARGE_REGION, 1495 "Region 0 of image %s is too large: %p.", pImage->pszName, pMemInfo->RegionSize); 1557 "Region 0 of image " IMAGE_LOG_NAME_FMT " is too large: %p.", 1558 IMAGE_LOG_NAME(pImage), pMemInfo->RegionSize); 1496 1559 1497 1560 /* … … 1506 1569 pImage->aRegions[0].fProt = pMemInfo->Protect; 1507 1570 1571 #ifndef VBOX_WITH_MINIMAL_HARDENING 1508 1572 if (suplibHardenedStrCmp(pImage->pszName, "ntdll.dll") == 0) 1509 1573 pImage->fNtCreateSectionPatch = true; 1510 1574 else if (suplibHardenedStrCmp(pImage->pszName, "apisetschema.dll") == 0) 1511 1575 pImage->fApiSetSchemaOnlySection1 = true; /** @todo Check the ApiSetMap field in the PEB. */ 1512 # ifdef VBOX_PERMIT_MORE1576 # ifdef VBOX_PERMIT_MORE 1513 1577 else if (suplibHardenedStrCmp(pImage->pszName, "acres.dll") == 0) 1514 1578 pImage->f32bitResourceDll = true; 1515 #endif 1579 # endif 1580 #endif /* !VBOX_WITH_MINIMAL_HARDENING */ 1516 1581 1517 1582 return VINF_SUCCESS; … … 1534 1599 if (pImage->uImageBase != (uintptr_t)pMemInfo->AllocationBase) 1535 1600 return supHardNtVpSetInfo2(pThis, VERR_SUPLIB_NT_PROCESS_UNTRUSTED_3, 1536 "Base address mismatch for %s: have %p, found %p for region %p LB %#zx.",1537 pImage->pszName, pImage->uImageBase, pMemInfo->AllocationBase,1601 "Base address mismatch for " IMAGE_LOG_NAME_FMT ": have %p, found %p for region %p LB %#zx.", 1602 IMAGE_LOG_NAME(pImage), pImage->uImageBase, pMemInfo->AllocationBase, 1538 1603 pMemInfo->BaseAddress, pMemInfo->RegionSize); 1539 1604 … … 1544 1609 if (pMemInfo->RegionSize >= _2G) 1545 1610 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_TOO_LARGE_REGION, 1546 "Region %u of image %s is too large: %p/%p.", pImage->pszName, pMemInfo->RegionSize, uRva); 1611 "Region %u of image " IMAGE_LOG_NAME_FMT " is too large: %p/%p.", 1612 IMAGE_LOG_NAME(pImage), pMemInfo->RegionSize, uRva); 1547 1613 if (uRva >= _2G) 1548 1614 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_TOO_HIGH_REGION_RVA, 1549 "Region %u of image %s is too high: %p/%p.", pImage->pszName, pMemInfo->RegionSize, uRva); 1615 "Region %u of image " IMAGE_LOG_NAME_FMT " is too high: %p/%p.", 1616 IMAGE_LOG_NAME(pImage), pMemInfo->RegionSize, uRva); 1550 1617 1551 1618 … … 1556 1623 if (iRegion + 1 >= RT_ELEMENTS(pImage->aRegions)) 1557 1624 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_TOO_MANY_IMAGE_REGIONS, 1558 "Too many regions for %s.", pImage->pszName);1625 "Too many regions for " IMAGE_LOG_NAME_FMT ".", IMAGE_LOG_NAME(pImage)); 1559 1626 pImage->aRegions[iRegion].uRva = (uint32_t)uRva; 1560 1627 pImage->aRegions[iRegion].cb = (uint32_t)pMemInfo->RegionSize; … … 1818 1885 uintptr_t cbAdvance = 0; 1819 1886 uintptr_t uPtrWhere = 0; 1820 #if def VBOX_PERMIT_VERIFIER_DLL1887 #if defined(VBOX_PERMIT_VERIFIER_DLL) || defined(VBOX_WITH_MINIMAL_HARDENING) 1821 1888 for (uint32_t i = 0; i < 10240; i++) 1822 1889 #else … … 1882 1949 if (fNew) 1883 1950 { 1951 #ifdef VBOX_WITH_MINIMAL_HARDENING 1952 /* Prune non-executable images before trying to add another. We only want the executable. */ 1953 if (iImg > 0 && pThis->aImages[iImg - 1].fDll) 1954 { 1955 pThis->cImages = --iImg; 1956 RT_ZERO(pThis->aImages[iImg]); 1957 pThis->aImages[iImg].Name = pThis->aImages[iImg + 1].Name; 1958 pThis->aImages[iImg].Name.UniStr.Buffer = pThis->aImages[iImg].Name.awcBuffer; 1959 } 1960 #endif 1884 1961 int rc = supHardNtVpNewImage(pThis, &pThis->aImages[iImg], &MemInfo); 1885 1962 if (RT_SUCCESS(rc)) … … 2336 2413 PSUPHNTVPIMAGE pImage = &pThis->aImages[i]; 2337 2414 2415 #ifdef VBOX_WITH_MINIMAL_HARDENING 2416 /* Only the process executable image is verified here, so don't bother open all the other ones. */ 2417 if (pImage->fDll) 2418 continue; 2419 #endif 2420 2338 2421 #ifdef IN_RING3 2339 2422 /* … … 2358 2441 #endif 2359 2442 2360 int rc = supHardNtLdrCacheNewEntry(pImage->pCacheEntry, pImage->pszName, &pImage->Name.UniStr, 2443 #ifndef VBOX_WITH_MINIMAL_HARDENING 2444 const char * const pszName = pImage->pszName; 2445 #else 2446 const char * const pszName = "ignored.exe"; 2447 #endif 2448 int rc = supHardNtLdrCacheNewEntry(pImage->pCacheEntry, pszName, &pImage->Name.UniStr, 2361 2449 pImage->fDll, pImage->f32bitResourceDll, pThis->pErrInfo); 2362 2450 if (RT_FAILURE(rc)) … … 2486 2574 2487 2575 2576 #ifndef VBOX_WITH_MINIMAL_HARDENING 2488 2577 /** 2489 2578 * Check the integrity of the DLLs found in the process. … … 2548 2637 return VINF_SUCCESS; 2549 2638 } 2639 #endif /* !VBOX_WITH_MINIMAL_HARDENING */ 2550 2640 2551 2641 … … 2683 2773 uint32_t *pcFixes, PRTERRINFO pErrInfo) 2684 2774 { 2775 RT_NOREF(hThread); 2685 2776 if (pcFixes) 2686 2777 *pcFixes = 0; … … 2691 2782 */ 2692 2783 int rc = VINF_SUCCESS; 2784 #ifndef VBOX_WITH_MINIMAL_HARDENING 2693 2785 if ( enmKind != SUPHARDNTVPKIND_CHILD_PURIFICATION 2694 2786 && enmKind != SUPHARDNTVPKIND_SELF_PURIFICATION_LIMITED) … … 2697 2789 rc = supHardNtVpDebugger(hProcess, pErrInfo); 2698 2790 if (RT_SUCCESS(rc)) 2791 #endif /* !VBOX_WITH_MINIMAL_HARDENING */ 2699 2792 { 2700 2793 /* … … 2718 2811 if (RT_SUCCESS(rc)) 2719 2812 rc = supHardNtVpCheckExe(pThis); 2813 #ifndef VBOX_WITH_MINIMAL_HARDENING 2720 2814 if (RT_SUCCESS(rc)) 2721 2815 rc = supHardNtVpCheckDlls(pThis); 2722 # ifdef IN_RING32816 # ifdef IN_RING3 2723 2817 if (enmKind == SUPHARDNTVPKIND_SELF_PURIFICATION_LIMITED) 2724 2818 rc = supHardNtVpCheckHandles(pThis); 2725 #endif 2819 # endif 2820 #endif /* !VBOX_WITH_MINIMAL_HARDENING */ 2821 2726 2822 2727 2823 if (pcFixes)
Note:
See TracChangeset
for help on using the changeset viewer.