VirtualBox

Ignore:
Timestamp:
Apr 25, 2016 10:20:55 PM (9 years ago)
Author:
vboxsync
Message:

SUPHardNt: Propagate loader error info all the way (load config errors and such).

Location:
trunk/src/VBox/HostDrivers/Support
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h

    r59810 r60700  
    461461# endif
    462462DECLHIDDEN(void)    supR3HardenedWinInitImportsEarly(uintptr_t uNtDllAddr);
    463 DECLHIDDEN(void)    supR3HardenedWinInitSyscalls(bool fReportErrors);
     463DECLHIDDEN(void)    supR3HardenedWinInitSyscalls(bool fReportErrors, PRTERRINFO pErrInfo);
    464464DECLHIDDEN(PFNRT)   supR3HardenedWinGetRealDllSymbol(const char *pszDll, const char *pszProcedure);
    465465DECLHIDDEN(void)    supR3HardenedWinEnableThreadCreation(void);
  • trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerify-win.h

    r60480 r60700  
    169169/** Pointer to a loader cache entry. */
    170170typedef SUPHNTLDRCACHEENTRY *PSUPHNTLDRCACHEENTRY;
    171 DECLHIDDEN(int)  supHardNtLdrCacheOpen(const char *pszName, PSUPHNTLDRCACHEENTRY *ppEntry);
     171DECLHIDDEN(int)  supHardNtLdrCacheOpen(const char *pszName, PSUPHNTLDRCACHEENTRY *ppEntry, PRTERRINFO pErrInfo);
    172172DECLHIDDEN(int)  supHardNtLdrCacheEntryVerify(PSUPHNTLDRCACHEENTRY pEntry, PCRTUTF16 pwszName, PRTERRINFO pErrInfo);
    173173DECLHIDDEN(int)  supHardNtLdrCacheEntryGetBits(PSUPHNTLDRCACHEENTRY pEntry, uint8_t **ppbBits, RTLDRADDR uBaseAddress,
  • trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyProcess-win.cpp

    r60480 r60700  
    272272    va_start(va, pszMsg);
    273273    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 */
     291static 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);
    274305    va_end(va);
    275306
     
    20302061    rc = RTLdrOpenWithReader(&pNtViRdr->Core, RTLDR_O_FOR_VALIDATION, enmArch, &hLdrMod, pErrInfo);
    20312062    if (RT_FAILURE(rc))
    2032         return supHardNtVpSetInfo1(pErrInfo, rc, "RTLdrOpenWithReader failed: %Rrc (Image='%ls').",
     2063        return supHardNtVpAddInfo1(pErrInfo, rc, "RTLdrOpenWithReader failed: %Rrc (Image='%ls').",
    20332064                                   rc, pUniStrPath->Buffer);
    20342065
     
    20672098 *                              g_apszSupNtVpAllowedDlls array.
    20682099 * @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 */
     2103DECLHIDDEN(int) supHardNtLdrCacheOpen(const char *pszName, PSUPHNTLDRCACHEENTRY *ppEntry, PRTERRINFO pErrInfo)
    20712104{
    20722105    /*
     
    21062139
    21072140    int rc = supHardNtLdrCacheNewEntry(&g_aSupNtVpLdrCacheEntries[g_cSupNtVpLdrCacheEntries], pszName, &UniStr,
    2108                                        true /*fDll*/, false /*f32bitResourceDll*/, NULL /*pErrInfo*/);
     2141                                       true /*fDll*/, false /*f32bitResourceDll*/, pErrInfo);
    21092142    if (RT_SUCCESS(rc))
    21102143    {
  • trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp

    r60521 r60700  
    35643564     */
    35653565    PSUPHNTLDRCACHEENTRY pLdrEntry;
    3566     int rc = supHardNtLdrCacheOpen("ntdll.dll", &pLdrEntry);
     3566    int rc = supHardNtLdrCacheOpen("ntdll.dll", &pLdrEntry, NULL /*pErrInfo*/);
    35673567    if (RT_FAILURE(rc))
    35683568        supR3HardenedWinKillChild(pThis, "supR3HardenedWinSetupChildInit", rc,
     
    57345734     * Set up the direct system calls so we can more easily hook NtCreateSection.
    57355735     */
    5736     supR3HardenedWinInitSyscalls(true /*fReportErrors*/);
     5736    RTERRINFOSTATIC ErrInfo;
     5737    supR3HardenedWinInitSyscalls(true /*fReportErrors*/, RTErrInfoInitStatic(&ErrInfo));
    57375738
    57385739    /*
     
    57935794    SUP_DPRINTF(("supR3HardenedVmProcessInit: Restoring LdrInitializeThunk...\n"));
    57945795    PSUPHNTLDRCACHEENTRY pLdrEntry;
    5795     int rc = supHardNtLdrCacheOpen("ntdll.dll", &pLdrEntry);
     5796    int rc = supHardNtLdrCacheOpen("ntdll.dll", &pLdrEntry, RTErrInfoInitStatic(&ErrInfo));
    57965797    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);
    57985800
    57995801    uint8_t *pbBits;
    5800     rc = supHardNtLdrCacheEntryGetBits(pLdrEntry, &pbBits, uNtDllAddr, NULL, NULL, NULL /*pErrInfo*/);
     5802    rc = supHardNtLdrCacheEntryGetBits(pLdrEntry, &pbBits, uNtDllAddr, NULL, NULL, RTErrInfoInitStatic(&ErrInfo));
    58015803    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);
    58035806
    58045807    RTLDRADDR uValue;
  • trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMainImports-win.cpp

    r58363 r60700  
    588588    memcpy((void *)&abCopy[0], pbFunction, sizeof(abCopy));
    589589    SUPHNTIMP_ERROR(fReportErrors, 17, "supR3HardenedWinInitImports", kSupInitOp_Misc, rc,
    590                     "%ls: supHardNtLdrCacheOpen failed: '%s': %.16Rhxs",
     590                    "%ls: failed to parse syscall: '%s': %.16Rhxs",
    591591                    pDll->pwszName, pImport->pszName, &abCopy[0]);
    592592}
     
    601601 * @param   fReportErrors       Whether we've got the machinery for reporting
    602602 *                              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 */
     607DECLHIDDEN(void) supR3HardenedWinInitSyscalls(bool fReportErrors, PRTERRINFO pErrInfo)
    605608{
    606609    for (uint32_t iDll = 0; iDll < RT_ELEMENTS(g_aSupNtImpDlls); iDll++)
     
    608611        {
    609612            PSUPHNTLDRCACHEENTRY pLdrEntry;
    610             int rc = supHardNtLdrCacheOpen(g_aSupNtImpDlls[iDll].pszName, &pLdrEntry);
     613            int rc = supHardNtLdrCacheOpen(g_aSupNtImpDlls[iDll].pszName, &pLdrEntry, pErrInfo);
    611614            if (RT_SUCCESS(rc))
    612615            {
    613616                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);
    616619                if (RT_SUCCESS(rc))
    617620                {
     
    622625                else
    623626                    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 : "");
    625629            }
    626630            else
    627631                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 : "");
    629634        }
    630635}
     
    663668
    664669    for (uint32_t i = 0; i < RT_ELEMENTS(aImports); i++)
    665         {
    666             const char *pszForwarder = supR3HardenedResolveImport(&g_aSupNtImpDlls[0], &aImports[i], false);
    667             if (pszForwarder)
    668                 SUPHNTIMP_ERROR(false, 31, "supR3HardenedWinGetVeryEarlyImports", kSupInitOp_Misc, VERR_MODULE_NOT_FOUND,
    669                                 "ntdll: Failed to resolve forwarder '%s'.", pszForwarder);
    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    }
    671676
    672677    /*
     
    723728DECLHIDDEN(void) supR3HardenedWinInitImports(void)
    724729{
     730    RTERRINFOSTATIC ErrInfo;
     731
    725732    /*
    726733     * Find the DLLs we will be needing first (forwarders).
     
    760767     * Do system calls directly.
    761768     */
    762     supR3HardenedWinInitSyscalls(false);
     769    supR3HardenedWinInitSyscalls(false, RTErrInfoInitStatic(&ErrInfo));
    763770
    764771    /*
     
    770777        {
    771778            PSUPHNTLDRCACHEENTRY pLdrEntry;
    772             int rc = supHardNtLdrCacheOpen(g_aSupNtImpDlls[iDll].pszName, &pLdrEntry);
     779            int rc = supHardNtLdrCacheOpen(g_aSupNtImpDlls[iDll].pszName, &pLdrEntry, RTErrInfoInitStatic(&ErrInfo));
    773780            if (RT_SUCCESS(rc))
    774781            {
    775782                uint8_t *pbBits;
    776783                rc = supHardNtLdrCacheEntryGetBits(pLdrEntry, &pbBits, (uintptr_t)g_aSupNtImpDlls[iDll].pbImageBase, NULL, NULL,
    777                                                    NULL /*pErrInfo*/);
     784                                                   RTErrInfoInitStatic(&ErrInfo));
    778785                if (RT_SUCCESS(rc))
    779786                    for (uint32_t i = 0; i < g_aSupNtImpDlls[iDll].cImports; i++)
     
    807814DECLHIDDEN(PFNRT) supR3HardenedWinGetRealDllSymbol(const char *pszDll, const char *pszProcedure)
    808815{
     816    RTERRINFOSTATIC ErrInfo;
     817
    809818    /*
    810819     * Look the DLL up in the import DLL table.
     
    815824
    816825            PSUPHNTLDRCACHEENTRY pLdrEntry;
    817             int rc = supHardNtLdrCacheOpen(g_aSupNtImpDlls[iDll].pszName, &pLdrEntry);
     826            int rc = supHardNtLdrCacheOpen(g_aSupNtImpDlls[iDll].pszName, &pLdrEntry, RTErrInfoInitStatic(&ErrInfo));
    818827            if (RT_SUCCESS(rc))
    819828            {
    820829                uint8_t *pbBits;
    821830                rc = supHardNtLdrCacheEntryGetBits(pLdrEntry, &pbBits, (uintptr_t)g_aSupNtImpDlls[iDll].pbImageBase, NULL, NULL,
    822                                                    NULL /*pErrInfo*/);
     831                                                   RTErrInfoInitStatic(&ErrInfo));
    823832                if (RT_SUCCESS(rc))
    824833                {
     
    831840                }
    832841                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));
    835844            }
    836845            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));
    839848
    840849            /* Complications, just call GetProcAddress. */
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