VirtualBox

Ignore:
Timestamp:
Oct 5, 2014 4:48:25 PM (10 years ago)
Author:
vboxsync
Message:

SUP: Implemented early VM process vboxdrv initialization.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyProcess-win.cpp

    r52940 r52947  
    810810     */
    811811    uint8_t *pbBits;
    812     rc = supHardNtLdrCacheEntryAllocBits(pImage->pCacheEntry, &pbBits, pThis->pErrInfo);
     812    if (pThis->enmKind == SUPHARDNTVPKIND_CHILD_PURIFICATION)
     813        rc = supHardNtLdrCacheEntryGetBits(pImage->pCacheEntry, &pbBits, pImage->uImageBase, NULL /*pfnGetImport*/, pThis,
     814                                           pThis->pErrInfo);
     815    else
     816        rc = supHardNtLdrCacheEntryGetBits(pImage->pCacheEntry, &pbBits, pImage->uImageBase, supHardNtVpGetImport, pThis,
     817                                           pThis->pErrInfo);
    813818    if (RT_FAILURE(rc))
    814819        return rc;
    815     if (pThis->enmKind == SUPHARDNTVPKIND_CHILD_PURIFICATION)
    816         rc = RTLdrGetBits(pImage->pCacheEntry->hLdrMod, pbBits, pImage->uImageBase, NULL /*pfnGetImport*/, pThis);
    817     else
    818         rc = RTLdrGetBits(pImage->pCacheEntry->hLdrMod, pbBits, pImage->uImageBase, supHardNtVpGetImport, pThis);
    819     if (RT_FAILURE(rc))
    820         return supHardNtVpSetInfo2(pThis, rc, "%s: RTLdrGetBits failed: %Rrc", pImage->pszName, rc);
    821820
    822821    /* XP SP3 does not set ImageBase to load address. It fixes up the image on load time though. */
     
    862861                return supHardNtVpSetInfo2(pThis, rc, "%s: Failed to find 'LdrInitializeThunk': %Rrc", pImage->pszName, rc);
    863862            aSkipAreas[cSkipAreas].uRva = (uint32_t)uValue;
    864             aSkipAreas[cSkipAreas++].cb = 10;
     863            aSkipAreas[cSkipAreas++].cb = 14;
    865864        }
    866865
     
    15861585
    15871586/**
    1588  * Allocates a image bits buffer for use with RTLdrGetBits.
     1587 * Allocates a image bits buffer and calls RTLdrGetBits on them.
    15891588 *
    15901589 * An assumption here is that there won't ever be concurrent use of the cache.
     
    15951594 * @param   pEntry              The loader cache entry.
    15961595 * @param   ppbBits             Where to return the pointer to the allocation.
    1597  * @param   pErRInfo            Where to return extened error information.
    1598  */
    1599 DECLHIDDEN(int) supHardNtLdrCacheEntryAllocBits(PSUPHNTLDRCACHEENTRY pEntry, uint8_t **ppbBits, PRTERRINFO pErrInfo)
    1600 {
     1596 * @param   uBaseAddress        The image base address, see RTLdrGetBits.
     1597 * @param   pfnGetImport        Import getter, see RTLdrGetBits.
     1598 * @param   pvUser              The user argument for @a pfnGetImport.
     1599 * @param   pErrInfo            Where to return extened error information.
     1600 */
     1601DECLHIDDEN(int) supHardNtLdrCacheEntryGetBits(PSUPHNTLDRCACHEENTRY pEntry, uint8_t **ppbBits,
     1602                                              RTLDRADDR uBaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser,
     1603                                              PRTERRINFO pErrInfo)
     1604{
     1605    int rc;
     1606
     1607    /*
     1608     * First time around we have to allocate memory before we can get the image bits.
     1609     */
    16011610    if (!pEntry->pbBits)
    16021611    {
     
    16101619            return supHardNtVpSetInfo1(pErrInfo, VERR_SUP_VP_NO_MEMORY, "Failed to allocate %zu bytes for image %s.",
    16111620                                       cbBits, pEntry->pszName);
    1612     }
    1613 
    1614     /** @todo Try cache RTLdrGetBits calls too. */
     1621
     1622        pEntry->fValidBits = false; /* paranoia */
     1623
     1624        rc = RTLdrGetBits(pEntry->hLdrMod, pEntry->pbBits, uBaseAddress, pfnGetImport, pvUser);
     1625        if (RT_FAILURE(rc))
     1626            return supHardNtVpSetInfo1(pErrInfo, VERR_SUP_VP_NO_MEMORY, "RTLdrGetBits failed on image %s: %Rrc",
     1627                                       pEntry->pszName, rc);
     1628        pEntry->uImageBase = uBaseAddress;
     1629        pEntry->fValidBits = pfnGetImport == NULL;
     1630
     1631    }
     1632    /*
     1633     * Cache hit? No?
     1634     *
     1635     * Note! We cannot currently cache image bits for images with imports as we
     1636     *       don't control the way they're resolved.  Fortunately, NTDLL and
     1637     *       the VM process images all have no imports.
     1638     */
     1639    else if (   !pEntry->fValidBits
     1640             || pEntry->uImageBase != uBaseAddress
     1641             || pfnGetImport)
     1642    {
     1643        pEntry->fValidBits = false;
     1644
     1645        rc = RTLdrGetBits(pEntry->hLdrMod, pEntry->pbBits, uBaseAddress, pfnGetImport, pvUser);
     1646        if (RT_FAILURE(rc))
     1647            return supHardNtVpSetInfo1(pErrInfo, VERR_SUP_VP_NO_MEMORY, "RTLdrGetBits failed on image %s: %Rrc",
     1648                                       pEntry->pszName, rc);
     1649        pEntry->uImageBase = uBaseAddress;
     1650        pEntry->fValidBits = pfnGetImport == NULL;
     1651    }
    16151652
    16161653    *ppbBits = pEntry->pbBits;
     
    16511688    }
    16521689
    1653     pEntry->pszName   = NULL;
    1654     pEntry->fVerified = false;
     1690    pEntry->pszName    = NULL;
     1691    pEntry->fVerified  = false;
     1692    pEntry->fValidBits = false;
     1693    pEntry->uImageBase = 0;
    16551694}
    16561695
     
    17601799     * Fill in the cache entry.
    17611800     */
    1762     pEntry->pszName   = pszName;
    1763     pEntry->hLdrMod   = hLdrMod;
    1764     pEntry->pNtViRdr  = pNtViRdr;
    1765     pEntry->hFile     = hFile;
    1766     pEntry->pbBits    = NULL;
    1767     pEntry->fVerified = false;
     1801    pEntry->pszName    = pszName;
     1802    pEntry->hLdrMod    = hLdrMod;
     1803    pEntry->pNtViRdr   = pNtViRdr;
     1804    pEntry->hFile      = hFile;
     1805    pEntry->pbBits     = NULL;
     1806    pEntry->fVerified  = false;
     1807    pEntry->fValidBits = false;
     1808    pEntry->uImageBase = ~(uintptr_t)0;
    17681809
    17691810#ifdef IN_SUP_HARDENED_R3
     
    20422083        return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_NO_NTDLL_MAPPING,
    20432084                                   "The process has no NTDLL.DLL.");
    2044     if (iKernel32 == UINT32_MAX && pThis->enmKind != SUPHARDNTVPKIND_CHILD_PURIFICATION)
     2085    if (iKernel32 == UINT32_MAX && pThis->enmKind == SUPHARDNTVPKIND_SELF_PURIFICATION)
    20452086        return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_NO_KERNEL32_MAPPING,
    20462087                                   "The process has no KERNEL32.DLL.");
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette