Changeset 60700 in vbox for trunk/src/VBox/HostDrivers/Support
- Timestamp:
- Apr 25, 2016 10:20:55 PM (9 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h
r59810 r60700 461 461 # endif 462 462 DECLHIDDEN(void) supR3HardenedWinInitImportsEarly(uintptr_t uNtDllAddr); 463 DECLHIDDEN(void) supR3HardenedWinInitSyscalls(bool fReportErrors );463 DECLHIDDEN(void) supR3HardenedWinInitSyscalls(bool fReportErrors, PRTERRINFO pErrInfo); 464 464 DECLHIDDEN(PFNRT) supR3HardenedWinGetRealDllSymbol(const char *pszDll, const char *pszProcedure); 465 465 DECLHIDDEN(void) supR3HardenedWinEnableThreadCreation(void); -
trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerify-win.h
r60480 r60700 169 169 /** Pointer to a loader cache entry. */ 170 170 typedef SUPHNTLDRCACHEENTRY *PSUPHNTLDRCACHEENTRY; 171 DECLHIDDEN(int) supHardNtLdrCacheOpen(const char *pszName, PSUPHNTLDRCACHEENTRY *ppEntry );171 DECLHIDDEN(int) supHardNtLdrCacheOpen(const char *pszName, PSUPHNTLDRCACHEENTRY *ppEntry, PRTERRINFO pErrInfo); 172 172 DECLHIDDEN(int) supHardNtLdrCacheEntryVerify(PSUPHNTLDRCACHEENTRY pEntry, PCRTUTF16 pwszName, PRTERRINFO pErrInfo); 173 173 DECLHIDDEN(int) supHardNtLdrCacheEntryGetBits(PSUPHNTLDRCACHEENTRY pEntry, uint8_t **ppbBits, RTLDRADDR uBaseAddress, -
trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyProcess-win.cpp
r60480 r60700 272 272 va_start(va, pszMsg); 273 273 RTErrInfoSetV(pErrInfo, rc, pszMsg, va); 274 va_end(va); 275 276 return rc; 277 } 278 279 280 /** 281 * Adds error information. 282 * 283 * @returns @a rc. 284 * @param pErrInfo Pointer to the extended error info structure 285 * which may contain some details already. Can be 286 * NULL. 287 * @param rc The status to return. 288 * @param pszMsg The format string for the message. 289 * @param ... The arguments for the format string. 290 */ 291 static int supHardNtVpAddInfo1(PRTERRINFO pErrInfo, int rc, const char *pszMsg, ...) 292 { 293 va_list va; 294 #ifdef IN_RING3 295 va_start(va, pszMsg); 296 if (pErrInfo && pErrInfo->pszMsg) 297 supR3HardenedError(rc, false /*fFatal*/, "%N - %s\n", pszMsg, &va, pErrInfo->pszMsg); 298 else 299 supR3HardenedError(rc, false /*fFatal*/, "%N\n", pszMsg, &va); 300 va_end(va); 301 #endif 302 303 va_start(va, pszMsg); 304 RTErrInfoAddV(pErrInfo, rc, pszMsg, va); 274 305 va_end(va); 275 306 … … 2030 2061 rc = RTLdrOpenWithReader(&pNtViRdr->Core, RTLDR_O_FOR_VALIDATION, enmArch, &hLdrMod, pErrInfo); 2031 2062 if (RT_FAILURE(rc)) 2032 return supHardNtVp SetInfo1(pErrInfo, rc, "RTLdrOpenWithReader failed: %Rrc (Image='%ls').",2063 return supHardNtVpAddInfo1(pErrInfo, rc, "RTLdrOpenWithReader failed: %Rrc (Image='%ls').", 2033 2064 rc, pUniStrPath->Buffer); 2034 2065 … … 2067 2098 * g_apszSupNtVpAllowedDlls array. 2068 2099 * @param ppEntry Where to return the entry we've opened/found. 2069 */ 2070 DECLHIDDEN(int) supHardNtLdrCacheOpen(const char *pszName, PSUPHNTLDRCACHEENTRY *ppEntry) 2100 * @param pErrInfo Optional buffer where to return additional error 2101 * information. 2102 */ 2103 DECLHIDDEN(int) supHardNtLdrCacheOpen(const char *pszName, PSUPHNTLDRCACHEENTRY *ppEntry, PRTERRINFO pErrInfo) 2071 2104 { 2072 2105 /* … … 2106 2139 2107 2140 int rc = supHardNtLdrCacheNewEntry(&g_aSupNtVpLdrCacheEntries[g_cSupNtVpLdrCacheEntries], pszName, &UniStr, 2108 true /*fDll*/, false /*f32bitResourceDll*/, NULL /*pErrInfo*/);2141 true /*fDll*/, false /*f32bitResourceDll*/, pErrInfo); 2109 2142 if (RT_SUCCESS(rc)) 2110 2143 { -
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r60521 r60700 3564 3564 */ 3565 3565 PSUPHNTLDRCACHEENTRY pLdrEntry; 3566 int rc = supHardNtLdrCacheOpen("ntdll.dll", &pLdrEntry );3566 int rc = supHardNtLdrCacheOpen("ntdll.dll", &pLdrEntry, NULL /*pErrInfo*/); 3567 3567 if (RT_FAILURE(rc)) 3568 3568 supR3HardenedWinKillChild(pThis, "supR3HardenedWinSetupChildInit", rc, … … 5734 5734 * Set up the direct system calls so we can more easily hook NtCreateSection. 5735 5735 */ 5736 supR3HardenedWinInitSyscalls(true /*fReportErrors*/); 5736 RTERRINFOSTATIC ErrInfo; 5737 supR3HardenedWinInitSyscalls(true /*fReportErrors*/, RTErrInfoInitStatic(&ErrInfo)); 5737 5738 5738 5739 /* … … 5793 5794 SUP_DPRINTF(("supR3HardenedVmProcessInit: Restoring LdrInitializeThunk...\n")); 5794 5795 PSUPHNTLDRCACHEENTRY pLdrEntry; 5795 int rc = supHardNtLdrCacheOpen("ntdll.dll", &pLdrEntry );5796 int rc = supHardNtLdrCacheOpen("ntdll.dll", &pLdrEntry, RTErrInfoInitStatic(&ErrInfo)); 5796 5797 if (RT_FAILURE(rc)) 5797 supR3HardenedFatal("supR3HardenedVmProcessInit: supHardNtLdrCacheOpen failed on NTDLL: %Rrc\n", rc); 5798 supR3HardenedFatal("supR3HardenedVmProcessInit: supHardNtLdrCacheOpen failed on NTDLL: %Rrc %s\n", 5799 rc, ErrInfo.Core.pszMsg); 5798 5800 5799 5801 uint8_t *pbBits; 5800 rc = supHardNtLdrCacheEntryGetBits(pLdrEntry, &pbBits, uNtDllAddr, NULL, NULL, NULL /*pErrInfo*/);5802 rc = supHardNtLdrCacheEntryGetBits(pLdrEntry, &pbBits, uNtDllAddr, NULL, NULL, RTErrInfoInitStatic(&ErrInfo)); 5801 5803 if (RT_FAILURE(rc)) 5802 supR3HardenedFatal("supR3HardenedVmProcessInit: supHardNtLdrCacheEntryGetBits failed on NTDLL: %Rrc\n", rc); 5804 supR3HardenedFatal("supR3HardenedVmProcessInit: supHardNtLdrCacheEntryGetBits failed on NTDLL: %Rrc %s\n", 5805 rc, ErrInfo.Core.pszMsg); 5803 5806 5804 5807 RTLDRADDR uValue; -
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMainImports-win.cpp
r58363 r60700 588 588 memcpy((void *)&abCopy[0], pbFunction, sizeof(abCopy)); 589 589 SUPHNTIMP_ERROR(fReportErrors, 17, "supR3HardenedWinInitImports", kSupInitOp_Misc, rc, 590 "%ls: supHardNtLdrCacheOpen failed: '%s': %.16Rhxs",590 "%ls: failed to parse syscall: '%s': %.16Rhxs", 591 591 pDll->pwszName, pImport->pszName, &abCopy[0]); 592 592 } … … 601 601 * @param fReportErrors Whether we've got the machinery for reporting 602 602 * errors going already. 603 */ 604 DECLHIDDEN(void) supR3HardenedWinInitSyscalls(bool fReportErrors) 603 * @param pErrInfo Buffer for gathering additional error info. This 604 * is mainly to avoid consuming lots of stacks with 605 * RTERRINFOSTATIC structures. 606 */ 607 DECLHIDDEN(void) supR3HardenedWinInitSyscalls(bool fReportErrors, PRTERRINFO pErrInfo) 605 608 { 606 609 for (uint32_t iDll = 0; iDll < RT_ELEMENTS(g_aSupNtImpDlls); iDll++) … … 608 611 { 609 612 PSUPHNTLDRCACHEENTRY pLdrEntry; 610 int rc = supHardNtLdrCacheOpen(g_aSupNtImpDlls[iDll].pszName, &pLdrEntry );613 int rc = supHardNtLdrCacheOpen(g_aSupNtImpDlls[iDll].pszName, &pLdrEntry, pErrInfo); 611 614 if (RT_SUCCESS(rc)) 612 615 { 613 616 uint8_t *pbBits; 614 rc = supHardNtLdrCacheEntryGetBits(pLdrEntry, &pbBits, (uintptr_t)g_aSupNtImpDlls[iDll].pbImageBase, NULL, NULL,615 NULL /*pErrInfo*/);617 rc = supHardNtLdrCacheEntryGetBits(pLdrEntry, &pbBits, (uintptr_t)g_aSupNtImpDlls[iDll].pbImageBase, 618 NULL, NULL, pErrInfo); 616 619 if (RT_SUCCESS(rc)) 617 620 { … … 622 625 else 623 626 SUPHNTIMP_ERROR(fReportErrors, 20, "supR3HardenedWinInitImports", kSupInitOp_Misc, rc, 624 "%ls: supHardNtLdrCacheEntryGetBits failed: %Rrc '%s'.", g_aSupNtImpDlls[iDll].pwszName, rc); 627 "%ls: supHardNtLdrCacheEntryGetBits failed: %Rrc %s", 628 g_aSupNtImpDlls[iDll].pwszName, rc, pErrInfo ? pErrInfo->pszMsg : ""); 625 629 } 626 630 else 627 631 SUPHNTIMP_ERROR(fReportErrors, 21, "supR3HardenedWinInitImports", kSupInitOp_Misc, rc, 628 "%ls: supHardNtLdrCacheOpen failed: %Rrc '%s'.", g_aSupNtImpDlls[iDll].pwszName, rc); 632 "%ls: supHardNtLdrCacheOpen failed: %Rrc %s", 633 g_aSupNtImpDlls[iDll].pwszName, rc, pErrInfo ? pErrInfo->pszMsg : ""); 629 634 } 630 635 } … … 663 668 664 669 for (uint32_t i = 0; i < RT_ELEMENTS(aImports); i++) 665 666 667 668 669 670 670 { 671 const char *pszForwarder = supR3HardenedResolveImport(&g_aSupNtImpDlls[0], &aImports[i], false); 672 if (pszForwarder) 673 SUPHNTIMP_ERROR(false, 31, "supR3HardenedWinGetVeryEarlyImports", kSupInitOp_Misc, VERR_MODULE_NOT_FOUND, 674 "ntdll: Failed to resolve forwarder '%s'.", pszForwarder); 675 } 671 676 672 677 /* … … 723 728 DECLHIDDEN(void) supR3HardenedWinInitImports(void) 724 729 { 730 RTERRINFOSTATIC ErrInfo; 731 725 732 /* 726 733 * Find the DLLs we will be needing first (forwarders). … … 760 767 * Do system calls directly. 761 768 */ 762 supR3HardenedWinInitSyscalls(false );769 supR3HardenedWinInitSyscalls(false, RTErrInfoInitStatic(&ErrInfo)); 763 770 764 771 /* … … 770 777 { 771 778 PSUPHNTLDRCACHEENTRY pLdrEntry; 772 int rc = supHardNtLdrCacheOpen(g_aSupNtImpDlls[iDll].pszName, &pLdrEntry );779 int rc = supHardNtLdrCacheOpen(g_aSupNtImpDlls[iDll].pszName, &pLdrEntry, RTErrInfoInitStatic(&ErrInfo)); 773 780 if (RT_SUCCESS(rc)) 774 781 { 775 782 uint8_t *pbBits; 776 783 rc = supHardNtLdrCacheEntryGetBits(pLdrEntry, &pbBits, (uintptr_t)g_aSupNtImpDlls[iDll].pbImageBase, NULL, NULL, 777 NULL /*pErrInfo*/);784 RTErrInfoInitStatic(&ErrInfo)); 778 785 if (RT_SUCCESS(rc)) 779 786 for (uint32_t i = 0; i < g_aSupNtImpDlls[iDll].cImports; i++) … … 807 814 DECLHIDDEN(PFNRT) supR3HardenedWinGetRealDllSymbol(const char *pszDll, const char *pszProcedure) 808 815 { 816 RTERRINFOSTATIC ErrInfo; 817 809 818 /* 810 819 * Look the DLL up in the import DLL table. … … 815 824 816 825 PSUPHNTLDRCACHEENTRY pLdrEntry; 817 int rc = supHardNtLdrCacheOpen(g_aSupNtImpDlls[iDll].pszName, &pLdrEntry );826 int rc = supHardNtLdrCacheOpen(g_aSupNtImpDlls[iDll].pszName, &pLdrEntry, RTErrInfoInitStatic(&ErrInfo)); 818 827 if (RT_SUCCESS(rc)) 819 828 { 820 829 uint8_t *pbBits; 821 830 rc = supHardNtLdrCacheEntryGetBits(pLdrEntry, &pbBits, (uintptr_t)g_aSupNtImpDlls[iDll].pbImageBase, NULL, NULL, 822 NULL /*pErrInfo*/);831 RTErrInfoInitStatic(&ErrInfo)); 823 832 if (RT_SUCCESS(rc)) 824 833 { … … 831 840 } 832 841 else 833 SUP_DPRINTF(("supR3HardenedWinGetRealDllSymbol: supHardNtLdrCacheEntryAllocBits failed on %s: %Rrc \n",834 pszDll, rc ));842 SUP_DPRINTF(("supR3HardenedWinGetRealDllSymbol: supHardNtLdrCacheEntryAllocBits failed on %s: %Rrc %s\n", 843 pszDll, rc, ErrInfo.Core.pszMsg)); 835 844 } 836 845 else 837 SUP_DPRINTF(("supR3HardenedWinGetRealDllSymbol: supHardNtLdrCacheOpen failed on %s: %Rrc \n",838 pszDll, rc ));846 SUP_DPRINTF(("supR3HardenedWinGetRealDllSymbol: supHardNtLdrCacheOpen failed on %s: %Rrc %s\n", 847 pszDll, rc, ErrInfo.Core.pszMsg)); 839 848 840 849 /* Complications, just call GetProcAddress. */
Note:
See TracChangeset
for help on using the changeset viewer.