VirtualBox

Changeset 60297 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Apr 3, 2016 5:10:48 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106343
Message:

ldrPE.cpp/pecoff.h: Added version 5 of the load config structures, new error code VERR_LDRPE_GUARD_CF_STUFF. Added a pErrInfo parameter to rtldrPEValidateDirectoriesAndRememberStuff so it can report back why it fails.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/ldr/ldrPE.cpp

    r59747 r60297  
    29592959     * volatile everywhere! Trying to prevent the compiler being a smarta$$ and reorder stuff.
    29602960     */
    2961     IMAGE_LOAD_CONFIG_DIRECTORY32_V4 volatile *pLoadCfg32 = (IMAGE_LOAD_CONFIG_DIRECTORY32_V4 volatile *)pLoadCfg;
    2962     IMAGE_LOAD_CONFIG_DIRECTORY64_V4 volatile *pLoadCfg64 = pLoadCfg;
    2963 
    2964     pLoadCfg64->CodeIntegrity.Reserved      = pLoadCfg32->CodeIntegrity.Reserved;
    2965     pLoadCfg64->CodeIntegrity.CatalogOffset = pLoadCfg32->CodeIntegrity.CatalogOffset;
    2966     pLoadCfg64->CodeIntegrity.Catalog       = pLoadCfg32->CodeIntegrity.Catalog;
    2967     pLoadCfg64->CodeIntegrity.Flags         = pLoadCfg32->CodeIntegrity.Flags;
    2968     pLoadCfg64->GuardFlags                  = pLoadCfg32->GuardFlags;
    2969     pLoadCfg64->GuardCFFunctionCount        = pLoadCfg32->GuardCFFunctionCount;
    2970     pLoadCfg64->GuardCFFunctionTable        = pLoadCfg32->GuardCFFunctionTable;
    2971     pLoadCfg64->Reserved2                   = pLoadCfg32->Reserved2;
    2972     pLoadCfg64->GuardCFCCheckFunctionPointer= pLoadCfg32->GuardCFCCheckFunctionPointer;
    2973     pLoadCfg64->SEHandlerCount              = pLoadCfg32->SEHandlerCount;
    2974     pLoadCfg64->SEHandlerTable              = pLoadCfg32->SEHandlerTable;
    2975     pLoadCfg64->SecurityCookie              = pLoadCfg32->SecurityCookie;
    2976     pLoadCfg64->EditList                    = pLoadCfg32->EditList;
    2977     pLoadCfg64->Reserved1                   = pLoadCfg32->Reserved1;
    2978     pLoadCfg64->CSDVersion                  = pLoadCfg32->CSDVersion;
    2979     pLoadCfg64->ProcessHeapFlags            = pLoadCfg32->ProcessHeapFlags; /* switched place with ProcessAffinityMask, but we're more than 16 byte off by now so it doesn't matter. */
    2980     pLoadCfg64->ProcessAffinityMask         = pLoadCfg32->ProcessAffinityMask;
    2981     pLoadCfg64->VirtualMemoryThreshold      = pLoadCfg32->VirtualMemoryThreshold;
    2982     pLoadCfg64->MaximumAllocationSize       = pLoadCfg32->MaximumAllocationSize;
    2983     pLoadCfg64->LockPrefixTable             = pLoadCfg32->LockPrefixTable;
    2984     pLoadCfg64->DeCommitTotalFreeThreshold  = pLoadCfg32->DeCommitTotalFreeThreshold;
    2985     uint32_t u32DeCommitFreeBlockThreshold  = pLoadCfg32->DeCommitFreeBlockThreshold;
    2986     pLoadCfg64->DeCommitFreeBlockThreshold  = u32DeCommitFreeBlockThreshold;
     2961    IMAGE_LOAD_CONFIG_DIRECTORY32_V5 volatile *pLoadCfg32 = (IMAGE_LOAD_CONFIG_DIRECTORY32_V5 volatile *)pLoadCfg;
     2962    IMAGE_LOAD_CONFIG_DIRECTORY64_V5 volatile *pLoadCfg64 = pLoadCfg;
     2963
     2964    pLoadCfg64->GuardAddressTakenIatEntryTable  = pLoadCfg32->GuardAddressTakenIatEntryTable;
     2965    pLoadCfg64->GuardAddressTakenIatEntryCount  = pLoadCfg32->GuardAddressTakenIatEntryCount;
     2966    pLoadCfg64->GuardLongJumpTargetTable        = pLoadCfg32->GuardLongJumpTargetTable;
     2967    pLoadCfg64->GuardLongJumpTargetCount        = pLoadCfg32->GuardLongJumpTargetCount;
     2968    pLoadCfg64->CodeIntegrity.Reserved          = pLoadCfg32->CodeIntegrity.Reserved;
     2969    pLoadCfg64->CodeIntegrity.CatalogOffset     = pLoadCfg32->CodeIntegrity.CatalogOffset;
     2970    pLoadCfg64->CodeIntegrity.Catalog           = pLoadCfg32->CodeIntegrity.Catalog;
     2971    pLoadCfg64->CodeIntegrity.Flags             = pLoadCfg32->CodeIntegrity.Flags;
     2972    pLoadCfg64->GuardFlags                      = pLoadCfg32->GuardFlags;
     2973    pLoadCfg64->GuardCFFunctionCount            = pLoadCfg32->GuardCFFunctionCount;
     2974    pLoadCfg64->GuardCFFunctionTable            = pLoadCfg32->GuardCFFunctionTable;
     2975    pLoadCfg64->Reserved2                       = pLoadCfg32->Reserved2;
     2976    pLoadCfg64->GuardCFCCheckFunctionPointer    = pLoadCfg32->GuardCFCCheckFunctionPointer;
     2977    pLoadCfg64->SEHandlerCount                  = pLoadCfg32->SEHandlerCount;
     2978    pLoadCfg64->SEHandlerTable                  = pLoadCfg32->SEHandlerTable;
     2979    pLoadCfg64->SecurityCookie                  = pLoadCfg32->SecurityCookie;
     2980    pLoadCfg64->EditList                        = pLoadCfg32->EditList;
     2981    pLoadCfg64->Reserved1                       = pLoadCfg32->Reserved1;
     2982    pLoadCfg64->CSDVersion                      = pLoadCfg32->CSDVersion;
     2983    pLoadCfg64->ProcessHeapFlags                = pLoadCfg32->ProcessHeapFlags; /* switched place with ProcessAffinityMask, but we're more than 16 byte off by now so it doesn't matter. */
     2984    pLoadCfg64->ProcessAffinityMask             = pLoadCfg32->ProcessAffinityMask;
     2985    pLoadCfg64->VirtualMemoryThreshold          = pLoadCfg32->VirtualMemoryThreshold;
     2986    pLoadCfg64->MaximumAllocationSize           = pLoadCfg32->MaximumAllocationSize;
     2987    pLoadCfg64->LockPrefixTable                 = pLoadCfg32->LockPrefixTable;
     2988    pLoadCfg64->DeCommitTotalFreeThreshold      = pLoadCfg32->DeCommitTotalFreeThreshold;
     2989    uint32_t u32DeCommitFreeBlockThreshold      = pLoadCfg32->DeCommitFreeBlockThreshold;
     2990    pLoadCfg64->DeCommitFreeBlockThreshold      = u32DeCommitFreeBlockThreshold;
    29872991    /* the rest is equal. */
    29882992    Assert(     RT_OFFSETOF(IMAGE_LOAD_CONFIG_DIRECTORY32, DeCommitFreeBlockThreshold)
     
    34873491 * @param   fFlags      Loader flags, RTLDR_O_XXX.
    34883492 */
    3489 static int rtldrPEValidateDirectoriesAndRememberStuff(PRTLDRMODPE pModPe, const IMAGE_OPTIONAL_HEADER64 *pOptHdr, uint32_t fFlags)
     3493static int rtldrPEValidateDirectoriesAndRememberStuff(PRTLDRMODPE pModPe, const IMAGE_OPTIONAL_HEADER64 *pOptHdr, uint32_t fFlags,
     3494                                                      PRTERRINFO pErrInfo)
    34903495{
    34913496    const char *pszLogName = pModPe->Core.pReader->pfnLogName(pModPe->Core.pReader); NOREF(pszLogName);
     
    35033508    if (Dir.Size)
    35043509    {
     3510        const size_t cbExpectV5 = !pModPe->f64Bit
     3511                                ? sizeof(IMAGE_LOAD_CONFIG_DIRECTORY32_V5)
     3512                                : sizeof(IMAGE_LOAD_CONFIG_DIRECTORY64_V5);
    35053513        const size_t cbExpectV4 = !pModPe->f64Bit
    35063514                                ? sizeof(IMAGE_LOAD_CONFIG_DIRECTORY32_V4)
     
    35163524                                : sizeof(IMAGE_LOAD_CONFIG_DIRECTORY64_V2) /*No V1*/;
    35173525
    3518         if (   Dir.Size != cbExpectV4
     3526        if (   Dir.Size != cbExpectV5
     3527            && Dir.Size != cbExpectV4
    35193528            && Dir.Size != cbExpectV3
    35203529            && Dir.Size != cbExpectV2
    35213530            && Dir.Size != cbExpectV1)
    35223531        {
    3523             Log(("rtldrPEOpen: %s: load cfg dir: unexpected dir size of %d bytes, expected %d, %d, %d, or %d.\n",
    3524                  pszLogName, Dir.Size, cbExpectV4, cbExpectV3, cbExpectV2, cbExpectV1));
    3525             return VERR_LDRPE_LOAD_CONFIG_SIZE;
     3532            Log(("rtldrPEOpen: %s: load cfg dir: unexpected dir size of %u bytes, expected %zu, %zu, %zu, %zu, or %zu.\n",
     3533                 pszLogName, Dir.Size, cbExpectV5, cbExpectV4, cbExpectV3, cbExpectV2, cbExpectV1));
     3534            return RTErrInfoSetF(pErrInfo, VERR_LDRPE_LOAD_CONFIG_SIZE,
     3535                                 "Unexpected load config dir size of %u bytes; supported sized: %zu, %zu, %zu, %zu, or %zu",
     3536                                 Dir.Size, cbExpectV5, cbExpectV4, cbExpectV3, cbExpectV2, cbExpectV1);
    35263537        }
    35273538
     
    35793590                Log(("rtldrPEOpen: %s: load cfg dir: unexpected header size of %d bytes, expected %d.\n",
    35803591                     pszLogName, u.Cfg64.Size, Dir.Size));
    3581                 return VERR_LDRPE_LOAD_CONFIG_SIZE;
     3592                return RTErrInfoSetF(pErrInfo, VERR_LDRPE_LOAD_CONFIG_SIZE,
     3593                                     "Load config header vs directory size mismatch: %#x vs %#x", u.Cfg64.Size, Dir.Size);
    35823594            }
    35833595        }
     
    35863598            Log(("rtldrPEOpen: %s: load cfg dir: lock prefix table at %RX64. We don't support lock prefix tables!\n",
    35873599                 pszLogName, u.Cfg64.LockPrefixTable));
    3588             return VERR_LDRPE_LOCK_PREFIX_TABLE;
     3600            return RTErrInfoSetF(pErrInfo, VERR_LDRPE_LOCK_PREFIX_TABLE,
     3601                                 "Lock prefix table not supported: %RX64", u.Cfg64.LockPrefixTable);
    35893602        }
    35903603#if 0/* this seems to be safe to ignore. */
     
    36013614            Log(("rtldrPEOpen: %s: load cfg dir: EditList=%RX64 is unsupported!\n",
    36023615                 pszLogName, u.Cfg64.EditList));
    3603             return VERR_BAD_EXE_FORMAT;
     3616            return RTErrInfoSetF(pErrInfo, VERR_BAD_EXE_FORMAT, "Load config EditList=%RX64 is not supported", u.Cfg64.EditList);
    36043617        }
    36053618        /** @todo GuardCFC? Possibly related to:
     
    36113624                 || u.Cfg64.GuardCFFunctionTable
    36123625                 || u.Cfg64.GuardCFFunctionCount
    3613                  || u.Cfg64.GuardFlags)
    3614             && !(fFlags & (RTLDR_O_FOR_DEBUG | RTLDR_O_FOR_VALIDATION)))
    3615         {
    3616             Log(("rtldrPEOpen: %s: load cfg dir: Guard stuff: %RX64,%RX64,%RX64,%RX64,%RX32!\n",
     3626                 || u.Cfg64.GuardFlags
     3627                 || u.Cfg64.GuardAddressTakenIatEntryTable
     3628                 || u.Cfg64.GuardAddressTakenIatEntryCount
     3629                 || u.Cfg64.GuardLongJumpTargetTable
     3630                 || u.Cfg64.GuardLongJumpTargetCount)
     3631            && !(fFlags & (RTLDR_O_FOR_DEBUG | RTLDR_O_FOR_VALIDATION)) )
     3632        {
     3633            Log(("rtldrPEOpen: %s: load cfg dir: Guard stuff: %RX64,%RX64,%RX64,%RX64,%RX32,%RX64,%RX64,%RX64,%RX64!\n",
    36173634                 pszLogName, u.Cfg64.GuardCFCCheckFunctionPointer, u.Cfg64.Reserved2,
    3618                  u.Cfg64.GuardCFFunctionTable, u.Cfg64.GuardCFFunctionCount, u.Cfg64.GuardFlags));
    3619             return VERR_BAD_EXE_FORMAT;
     3635                 u.Cfg64.GuardCFFunctionTable, u.Cfg64.GuardCFFunctionCount, u.Cfg64.GuardFlags,
     3636                 u.Cfg64.GuardAddressTakenIatEntryTable, u.Cfg64.GuardAddressTakenIatEntryCount,
     3637                 u.Cfg64.GuardLongJumpTargetTable, u.Cfg64.GuardLongJumpTargetCount ));
     3638            return RTErrInfoSetF(pErrInfo, VERR_LDRPE_GUARD_CF_STUFF,
     3639                                 "Guard bits in load config: %RX64,%RX64,%RX64,%RX64,%RX32,%RX64,%RX64,%RX64,%RX64!",
     3640                                 u.Cfg64.GuardCFCCheckFunctionPointer, u.Cfg64.Reserved2,
     3641                                 u.Cfg64.GuardCFFunctionTable, u.Cfg64.GuardCFFunctionCount, u.Cfg64.GuardFlags,
     3642                                 u.Cfg64.GuardAddressTakenIatEntryTable, u.Cfg64.GuardAddressTakenIatEntryCount,
     3643                                 u.Cfg64.GuardLongJumpTargetTable, u.Cfg64.GuardLongJumpTargetCount);
    36203644        }
    36213645    }
     
    36443668                {
    36453669                    Log(("rtldrPEOpen: %s: cert at %#x/%#x: dwLength=%#x\n", pszLogName, off, Dir.Size, pCur->dwLength));
    3646                     rc = VERR_LDRPE_CERT_MALFORMED;
     3670                    rc = RTErrInfoSetF(pErrInfo, VERR_LDRPE_CERT_MALFORMED,
     3671                                       "Cert at %#x LB %#x: Bad header length value: %#x", off, Dir.Size, pCur->dwLength);
    36473672                    break;
    36483673                }
     
    36513676                {
    36523677                    Log(("rtldrPEOpen: %s: cert at %#x/%#x: wRevision=%#x\n", pszLogName, off, Dir.Size, pCur->wRevision));
    3653                     rc = pCur->wRevision >= WIN_CERT_REVISION_1_0 ? VERR_LDRPE_CERT_UNSUPPORTED : VERR_LDRPE_CERT_MALFORMED;
     3678                    if (pCur->wRevision >= WIN_CERT_REVISION_1_0)
     3679                        rc = RTErrInfoSetF(pErrInfo, VERR_LDRPE_CERT_UNSUPPORTED,
     3680                                           "Cert at %#x LB %#x: Unsupported revision: %#x", off, Dir.Size, pCur->wRevision);
     3681                    else
     3682                        rc = RTErrInfoSetF(pErrInfo, VERR_LDRPE_CERT_MALFORMED,
     3683                                           "Cert at %#x LB %#x: Malformed revision: %#x", off, Dir.Size, pCur->wRevision);
    36543684                    break;
    36553685                }
     
    36623692                   )
    36633693                {
    3664                     Log(("rtldrPEOpen: %s: cert at %#x/%#x: wRevision=%#x\n", pszLogName, off, Dir.Size, pCur->wRevision));
    3665                     rc = pCur->wCertificateType ? VERR_LDRPE_CERT_UNSUPPORTED : VERR_LDRPE_CERT_MALFORMED;
     3694                    Log(("rtldrPEOpen: %s: cert at %#x/%#x: wCertificateType=%#x\n", pszLogName, off, Dir.Size, pCur->wCertificateType));
     3695                    if (pCur->wCertificateType)
     3696                        rc = RTErrInfoSetF(pErrInfo, VERR_LDRPE_CERT_UNSUPPORTED,
     3697                                           "Cert at %#x LB %#x: Unsupported certificate type: %#x",
     3698                                           off, Dir.Size, pCur->wCertificateType);
     3699                    else
     3700                        rc = RTErrInfoSetF(pErrInfo, VERR_LDRPE_CERT_MALFORMED,
     3701                                           "Cert at %#x LB %#x: Malformed certificate type: %#x",
     3702                                           off, Dir.Size, pCur->wCertificateType);
    36663703                    break;
    36673704                }
     
    38153852                 * information.
    38163853                 */
    3817                 rc = rtldrPEValidateDirectoriesAndRememberStuff(pModPe, &OptHdr, fFlags);
     3854                rc = rtldrPEValidateDirectoriesAndRememberStuff(pModPe, &OptHdr, fFlags, pErrInfo);
    38183855                if (RT_SUCCESS(rc))
    38193856                {
Note: See TracChangeset for help on using the changeset viewer.

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