Changeset 52213 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Jul 28, 2014 5:52:58 PM (10 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPLibLdr.cpp
r51770 r52213 429 429 if (fIsVMMR0) 430 430 { 431 rc = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.abImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, "VMMR0EntryInt", &VMMR0EntryInt);431 rc = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.abImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, UINT32_MAX, "VMMR0EntryInt", &VMMR0EntryInt); 432 432 if (RT_SUCCESS(rc)) 433 rc = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.abImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, "VMMR0EntryFast", &VMMR0EntryFast);433 rc = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.abImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, UINT32_MAX, "VMMR0EntryFast", &VMMR0EntryFast); 434 434 if (RT_SUCCESS(rc)) 435 rc = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.abImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, "VMMR0EntryEx", &VMMR0EntryEx);435 rc = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.abImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, UINT32_MAX, "VMMR0EntryEx", &VMMR0EntryEx); 436 436 } 437 437 else if (pszSrvReqHandler) 438 rc = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.abImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, pszSrvReqHandler, &SrvReqHandler);438 rc = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.abImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, UINT32_MAX, pszSrvReqHandler, &SrvReqHandler); 439 439 if (RT_SUCCESS(rc)) 440 440 { 441 int rc2 = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.abImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, "ModuleInit", &ModuleInit);441 int rc2 = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.abImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, UINT32_MAX, "ModuleInit", &ModuleInit); 442 442 if (RT_FAILURE(rc2)) 443 443 ModuleInit = 0; 444 444 445 rc2 = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.abImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, "ModuleTerm", &ModuleTerm);445 rc2 = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.abImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, UINT32_MAX, "ModuleTerm", &ModuleTerm); 446 446 if (RT_FAILURE(rc2)) 447 447 ModuleTerm = 0; -
trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp
r52207 r52213 1665 1665 */ 1666 1666 # ifdef DEBUG_bird 1667 __debugbreak(); 1667 if (hrc != CERT_E_CHAINING /* Un-updated vistas, XPs, ++ */) 1668 __debugbreak(); 1668 1669 # endif 1669 1670 const char *pszErrConst = NULL; … … 1685 1686 case TRUST_E_FAIL: pszErrConst = "TRUST_E_FAIL"; break; 1686 1687 case TRUST_E_EXPLICIT_DISTRUST: pszErrConst = "TRUST_E_EXPLICIT_DISTRUST"; break; 1688 case CERT_E_CHAINING: pszErrConst = "CERT_E_CHAINING"; break; 1687 1689 } 1688 1690 if (pszErrConst) -
trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyProcess-win.cpp
r52207 r52213 38 38 #include <VBox/sup.h> 39 39 #include <VBox/err.h> 40 #include <iprt/alloca.h> 40 41 #include <iprt/ctype.h> 42 #include <iprt/param.h> 43 #include <iprt/string.h> 41 44 #include <iprt/zero.h> 42 #include <iprt/param.h>43 45 44 46 #ifdef IN_RING0 … … 134 136 /** Number of images in aImages. */ 135 137 uint32_t cImages; 138 /** The index of the last image we looked up. */ 139 uint32_t iImageHint; 136 140 /** The process handle. */ 137 141 HANDLE hProcess; … … 512 516 513 517 518 static DECLINLINE(bool) supHardNtVpIsModuleNameMatch(PSUPHNTVPIMAGE pImage, const char *pszModule) 519 { 520 if (pImage->fDll) 521 { 522 const char *pszImageNm = pImage->pszName; 523 for (;;) 524 { 525 char chLeft = *pszImageNm++; 526 char chRight = *pszModule++; 527 if (chLeft != chRight) 528 { 529 Assert(chLeft == RT_C_TO_LOWER(chLeft)); 530 if (chLeft != RT_C_TO_LOWER(chRight)) 531 { 532 if ( chRight == '\0' 533 && chLeft == '.' 534 && pszImageNm[0] == 'd' 535 && pszImageNm[1] == 'l' 536 && pszImageNm[2] == 'l' 537 && pszImageNm[3] == '\0') 538 return true; 539 break; 540 } 541 } 542 543 if (chLeft == '\0') 544 return true; 545 } 546 } 547 548 return false; 549 } 550 551 552 /** 553 * Worker for supHardNtVpGetImport that looks up a module in the module table. 554 * 555 * @returns Pointer to the module if found, NULL if not found. 556 * @param pThis The process validator instance. 557 * @param pszModule The name of the module we're looking for. 558 */ 559 static PSUPHNTVPIMAGE supHardNtVpFindModule(PSUPHNTVPSTATE pThis, const char *pszModule) 560 { 561 /* 562 * Check out the hint first. 563 */ 564 if ( pThis->iImageHint < pThis->cImages 565 && supHardNtVpIsModuleNameMatch(&pThis->aImages[pThis->iImageHint], pszModule)) 566 return &pThis->aImages[pThis->iImageHint]; 567 568 /* 569 * Linear array search next. 570 */ 571 uint32_t i = pThis->cImages; 572 while (i-- > 0) 573 if (supHardNtVpIsModuleNameMatch(&pThis->aImages[i], pszModule)) 574 { 575 pThis->iImageHint = i; 576 return &pThis->aImages[i]; 577 } 578 579 /* No cigar. */ 580 return NULL; 581 } 582 583 584 /** 585 * @callback_method_impl{FNRTLDRIMPORT} 586 */ 587 static DECLCALLBACK(int) supHardNtVpGetImport(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, 588 PRTLDRADDR pValue, void *pvUser) 589 { 590 /*SUP_DPRINTF(("supHardNtVpGetImport: %s / %#x / %s.\n", pszModule, uSymbol, pszSymbol));*/ 591 PSUPHNTVPSTATE pThis = (PSUPHNTVPSTATE)pvUser; 592 593 int rc = VERR_MODULE_NOT_FOUND; 594 PSUPHNTVPIMAGE pImage = supHardNtVpFindModule(pThis, pszModule); 595 if (pImage) 596 { 597 rc = RTLdrGetSymbolEx(pImage->hLdrMod, NULL, pImage->uImageBase, uSymbol, pszSymbol, pValue); 598 if (RT_SUCCESS(rc)) 599 return rc; 600 } 601 /* 602 * API set hacks. 603 */ 604 else if (!RTStrNICmp(pszModule, RT_STR_TUPLE("api-ms-win-"))) 605 { 606 static const char * const s_apszDlls[] = { "ntdll.dll", "kernelbase.dll", "kernel32.dll" }; 607 for (uint32_t i = 0; i < RT_ELEMENTS(s_apszDlls); i++) 608 { 609 pImage = supHardNtVpFindModule(pThis, s_apszDlls[i]); 610 if (pImage) 611 { 612 rc = RTLdrGetSymbolEx(pImage->hLdrMod, NULL, pImage->uImageBase, uSymbol, pszSymbol, pValue); 613 if (RT_SUCCESS(rc)) 614 return rc; 615 if (rc != VERR_SYMBOL_NOT_FOUND) 616 break; 617 } 618 } 619 } 620 621 /* 622 * Deal with forwarders. 623 * ASSUMES no forwarders thru any api-ms-win-core-*.dll. 624 * ASSUMES forwarders are resolved after one redirection. 625 */ 626 if (rc == VERR_LDR_FORWARDER) 627 { 628 size_t cbInfo = RT_MIN((uint32_t)*pValue, sizeof(RTLDRIMPORTINFO) + 32); 629 PRTLDRIMPORTINFO pInfo = (PRTLDRIMPORTINFO)alloca(cbInfo); 630 rc = RTLdrQueryForwarderInfo(pImage->hLdrMod, NULL, uSymbol, pszSymbol, pInfo, cbInfo); 631 if (RT_SUCCESS(rc)) 632 { 633 rc = VERR_MODULE_NOT_FOUND; 634 pImage = supHardNtVpFindModule(pThis, pInfo->szModule); 635 if (pImage) 636 { 637 rc = RTLdrGetSymbolEx(pImage->hLdrMod, NULL, pImage->uImageBase, pInfo->iOrdinal, pInfo->pszSymbol, pValue); 638 if (RT_SUCCESS(rc)) 639 return rc; 640 641 SUP_DPRINTF(("supHardNtVpGetImport: Failed to find symbol '%s' in '%s' (forwarded from %s / %s): %Rrc\n", 642 pInfo->pszSymbol, pInfo->szModule, pszModule, pszSymbol, rc)); 643 if (rc == VERR_LDR_FORWARDER) 644 rc = VERR_LDR_FORWARDER_CHAIN_TOO_LONG; 645 } 646 else 647 SUP_DPRINTF(("supHardNtVpGetImport: Failed to find forwarder module '%s' (%#x / %s; originally %s / %#x / %s): %Rrc\n", 648 pInfo->szModule, pInfo->iOrdinal, pInfo->pszSymbol, pszModule, uSymbol, pszSymbol, rc)); 649 } 650 else 651 SUP_DPRINTF(("supHardNtVpGetImport: RTLdrQueryForwarderInfo failed on symbol %#x/'%s' in '%s': %Rrc\n", 652 uSymbol, pszSymbol, pszModule, rc)); 653 } 654 else 655 SUP_DPRINTF(("supHardNtVpGetImport: Failed to find symbol %#x / '%s' in '%s': %Rrc\n", 656 uSymbol, pszSymbol, pszModule, rc)); 657 return rc; 658 } 659 660 514 661 /** 515 662 * Compares process memory with the disk content. … … 648 795 return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_NO_MEMORY, 649 796 "%s: Error allocating %#x bytes for fixed up image bits.", pImage->pszName, cbImage); 650 rc = RTLdrGetBits(pImage->hLdrMod, pImage->pbBits, pImage->uImageBase, NULL /*pfnGetImport*/, pThis); 651 /**@todo resolve import when not in SUPHARDNTVPKIND_CHILD_PURIFICATION mode. */ 797 if (pThis->enmKind == SUPHARDNTVPKIND_CHILD_PURIFICATION) 798 rc = RTLdrGetBits(pImage->hLdrMod, pImage->pbBits, pImage->uImageBase, NULL /*pfnGetImport*/, pThis); 799 else 800 rc = RTLdrGetBits(pImage->hLdrMod, pImage->pbBits, pImage->uImageBase, supHardNtVpGetImport, pThis); 652 801 if (RT_FAILURE(rc)) 653 802 return supHardNtVpSetInfo2(pThis, rc, "%s: RTLdrGetBits failed: %Rrc", pImage->pszName, rc); … … 666 815 */ 667 816 uint32_t cSkipAreas = 0; 668 SUPHNTVPSKIPAREA aSkipAreas[ 2];817 SUPHNTVPSKIPAREA aSkipAreas[3]; 669 818 if (pImage->fNtCreateSectionPatch) 670 819 { … … 673 822 { 674 823 /* Ignore our NtCreateSection hack. */ 675 rc = RTLdrGetSymbolEx(pImage->hLdrMod, pImage->pbBits, 0, "NtCreateSection", &uValue);824 rc = RTLdrGetSymbolEx(pImage->hLdrMod, pImage->pbBits, 0, UINT32_MAX, "NtCreateSection", &uValue); 676 825 if (RT_FAILURE(rc)) 677 826 return supHardNtVpSetInfo2(pThis, rc, "%s: Failed to find 'NtCreateSection': %Rrc", pImage->pszName, rc); … … 681 830 682 831 /* LdrSystemDllInitBlock is filled in by the kernel. It mainly contains addresses of 32-bit ntdll method for wow64. */ 683 rc = RTLdrGetSymbolEx(pImage->hLdrMod, pImage->pbBits, 0, "LdrSystemDllInitBlock", &uValue);832 rc = RTLdrGetSymbolEx(pImage->hLdrMod, pImage->pbBits, 0, UINT32_MAX, "LdrSystemDllInitBlock", &uValue); 684 833 if (RT_SUCCESS(rc)) 685 834 { … … 758 907 /* The section bits, only child purification verifies all bits . */ 759 908 if ( pThis->enmKind == SUPHARDNTVPKIND_CHILD_PURIFICATION 760 || (pThis->aSecHdrs[i].Characteristics & (IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_CNT_CODE)) ) 909 || (pThis->aSecHdrs[i].Characteristics & (IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_CNT_CODE)) 910 || (pThis->aSecHdrs[i].Characteristics & (IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE)) == IMAGE_SCN_MEM_READ) 761 911 { 762 912 rc = VINF_SUCCESS; … … 1007 1157 { 1008 1158 /* 1009 * Not a known DLL, executable?1159 * Not a known DLL, is it a known executable? 1010 1160 */ 1011 1161 for (uint32_t i = 0; i < RT_ELEMENTS(g_apszSupNtVpAllowedVmExes); i++)
Note:
See TracChangeset
for help on using the changeset viewer.