VirtualBox

Changeset 52030 in vbox for trunk/src/VBox/HostDrivers


Ignore:
Timestamp:
Jul 15, 2014 7:28:25 AM (10 years ago)
Author:
vboxsync
Message:

Forward ported r95010 from 4.3

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/Makefile.kmk

    r51999 r52030  
    137137# The Ring-3 Support Library (this is linked into the IPRT dll, VBoxRT).
    138138#
    139 SUPR3_TEMPLATE      = VBOXR3NP
     139SUPR3_TEMPLATE      = VBOXR3
    140140SUPR3_DEFS          = \
    141141        IN_SUP_R3 IN_RT_R3 \
    142142        $(if $(VBOX_WITH_SUPSVC),VBOX_WITH_SUPSVC) \
    143143        $(if $(VBOX_WITH_MAIN),VBOX_WITH_MAIN,) \
    144         $(if $(VBOX_WITH_RAW_MODE),VBOX_WITH_RAW_MODE,)
     144        $(if $(VBOX_WITH_RAW_MODE),VBOX_WITH_RAW_MODE,) \
     145        VBOX_PERMIT_MORE
    145146SUPR3_INCS         := $(PATH_SUB_CURRENT)
    146147SUPR3_SOURCES       = \
     
    183184        $(if $(VBOX_WITH_RAW_MODE),VBOX_WITH_RAW_MODE,) \
    184185        $(if $(VBOX_WITHOUT_DEBUGGER_CHECKS),VBOX_WITHOUT_DEBUGGER_CHECKS,) \
    185         $(if $(VBOX_PERMIT_VISUAL_STUDIO_PROFILING),VBOX_PERMIT_VISUAL_STUDIO_PROFILING,)
     186        $(if $(VBOX_PERMIT_VISUAL_STUDIO_PROFILING),VBOX_PERMIT_VISUAL_STUDIO_PROFILING,) \
     187        VBOX_PERMIT_MORE
    186188ifdef VBOX_WITH_VISTA_NO_SP
    187189 SUPR3HardenedStatic_DEFS.win += VBOX_WITH_VISTA_NO_SP
     
    535537  VBoxDrv_DEFS           += VBOX_PERMIT_VISUAL_STUDIO_PROFILING
    536538 endif
     539 VBoxDrv_DEFS            += VBOX_PERMIT_MORE
    537540 #VBoxDrv_DEFS.debug      += DEBUG_DARWIN_GIP
    538541 VBoxDrv_DEFS.darwin     := VBOX_WITH_HOST_VMX
  • trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerify-win.h

    r51770 r52030  
    3939DECLHIDDEN(int)      supHardenedWinVerifyProcess(HANDLE hProcess, HANDLE hThread, PRTERRINFO pErrInfo);
    4040
     41DECLHIDDEN(bool)     supHardViIsAppPatchDir(PCRTUTF16 pwszPath, uint32_t cwcName);
    4142DECLHIDDEN(int)      supHardenedWinVerifyImageByHandle(HANDLE hFile, PCRTUTF16 pwszName, uint32_t fFlags, bool *pfCacheable, PRTERRINFO pErrInfo);
    4243DECLHIDDEN(int)      supHardenedWinVerifyImageByHandleNoName(HANDLE hFile, uint32_t fFlags, PRTERRINFO pErrInfo);
     
    5253/** Whether to allow image verification by catalog file. */
    5354#  define SUPHNTVI_F_ALLOW_CAT_FILE_VERIFICATION    RT_BIT(3)
     55/** Resource image, could be any bitness. */
     56#  define SUPHNTVI_F_RESOURCE_IMAGE                 RT_BIT(30)
    5457/** Raw-mode context image, always 32-bit. */
    5558#  define SUPHNTVI_F_RC_IMAGE                       RT_BIT(31)
  • trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp

    r51977 r52030  
    511511
    512512
     513#ifdef VBOX_PERMIT_MORE
     514/**
     515 * Checks if the path goes into %windir%\apppatch\.
     516 *
     517 * @returns true if apppatch, false if not.
     518 * @param   pwszPath        The path to examine.
     519 */
     520DECLHIDDEN(bool) supHardViIsAppPatchDir(PCRTUTF16 pwszPath, uint32_t cwcName)
     521{
     522    uint32_t cwcWinDir = (g_System32NtPath.UniStr.Length - sizeof(L"System32")) / sizeof(WCHAR);
     523
     524    if (cwcName <= cwcWinDir + sizeof("AppPatch"))
     525        return false;
     526
     527    if (memcmp(pwszPath, g_System32NtPath.UniStr.Buffer, cwcWinDir * sizeof(WCHAR)))
     528        return false;
     529
     530    if (!supHardViUtf16PathStartsWith(&pwszPath[cwcWinDir], "\\AppPatch\\"))
     531        return false;
     532
     533    return g_uNtVerCombined >= SUP_NT_VER_VISTA;
     534}
     535#else
     536# error should not get here..
     537#endif
     538
     539
     540
    513541/**
    514542 * Checks if the unsigned DLL is fine or not.
     
    571599        if (supHardViUtf16PathIsEqual(pwsz, "apphelp.dll"))
    572600            return uNtVer < SUP_MAKE_NT_VER_SIMPLE(6, 4) ? VINF_LDRVI_NOT_SIGNED : rc;
    573         if (supHardViUtf16PathIsEqual(pwsz, "sfc.dll"))
    574             return uNtVer < SUP_MAKE_NT_VER_SIMPLE(6, 4) ? VINF_LDRVI_NOT_SIGNED : rc;
     601#ifdef VBOX_PERMIT_MORE
     602        if (uNtVer >= SUP_NT_VER_W70) /* hard limit: user32.dll is unwanted prior to w7. */
     603        {
     604            if (supHardViUtf16PathIsEqual(pwsz, "sfc.dll"))
     605                return uNtVer < SUP_MAKE_NT_VER_SIMPLE(6, 4) ? VINF_LDRVI_NOT_SIGNED : rc;
     606            if (supHardViUtf16PathIsEqual(pwsz, "sfc_os.dll"))
     607                return uNtVer < SUP_MAKE_NT_VER_SIMPLE(6, 4) ? VINF_LDRVI_NOT_SIGNED : rc;
     608            if (supHardViUtf16PathIsEqual(pwsz, "user32.dll"))
     609                return uNtVer < SUP_NT_VER_W81 ? VINF_LDRVI_NOT_SIGNED : rc;
     610        }
     611#endif
    575612
    576613#ifndef IN_RING0
     
    653690        return rc;
    654691    }
     692#endif
     693
     694#ifdef VBOX_PERMIT_MORE
     695    /*
     696     * AppPatch whitelist.
     697     */
     698    if (supHardViIsAppPatchDir(pwszName, cwcName))
     699    {
     700        cwcOther = g_System32NtPath.UniStr.Length / sizeof(WCHAR); /* ASSUMES System32 is called System32. */
     701        pwsz = pwszName + cwcOther + 1;
     702
     703        if (supHardViUtf16PathIsEqual(pwsz, "acres.dll"))
     704            return VINF_LDRVI_NOT_SIGNED;
     705
     706# ifdef RT_ARCH_AMD64
     707        if (supHardViUtf16PathIsEqual(pwsz, "AppPatch64\\AcGenral.dll"))
     708            return VINF_LDRVI_NOT_SIGNED;
     709# elif defined(RT_ARCH_X86)
     710        if (supHardViUtf16PathIsEqual(pwsz, "AcGenral.dll"))
     711            return VINF_LDRVI_NOT_SIGNED;
     712# endif
     713
     714        return rc;
     715    }
     716#else
     717# error should not be here...
    655718#endif
    656719
     
    855918         */
    856919        RTLDRMOD hLdrMod;
    857         rc = RTLdrOpenWithReader(&pNtViRdr->Core, RTLDR_O_FOR_VALIDATION,
    858                                  fFlags & SUPHNTVI_F_RC_IMAGE ? RTLDRARCH_X86_32 : RTLDRARCH_HOST,
    859                                  &hLdrMod, pErrInfo);
     920        RTLDRARCH enmArch = fFlags & SUPHNTVI_F_RC_IMAGE ? RTLDRARCH_X86_32 : RTLDRARCH_HOST;
     921        if (fFlags & SUPHNTVI_F_RESOURCE_IMAGE)
     922            enmArch = RTLDRARCH_WHATEVER;
     923        rc = RTLdrOpenWithReader(&pNtViRdr->Core, RTLDR_O_FOR_VALIDATION, enmArch, &hLdrMod, pErrInfo);
    860924        if (RT_SUCCESS(rc))
    861925        {
  • trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyProcess-win.cpp

    r51999 r52030  
    106106     * content.  The hack means that we only check if the 1st section is mapped. */
    107107    bool            fApiSetSchemaOnlySection1;
     108    /** This may be a 32-bit resource DLL. */
     109    bool            f32bitResourceDll;
    108110} SUPHNTVPIMAGE;
    109111/** Pointer to image info from the virtual address space scan. */
     
    123125     * more so we can get the image name of the first unwanted DLL. */
    124126    SUPHNTVPIMAGE           aImages[1 + 6 + 1
     127#ifdef VBOX_PERMIT_MORE
     128                                    + 5
     129#endif
    125130#ifdef VBOX_PERMIT_VISUAL_STUDIO_PROFILING
    126131                                    + 16
     
    154159    "apphelp.dll",
    155160    "apisetschema.dll",
     161#ifdef VBOX_PERMIT_MORE
     162# define VBOX_PERMIT_MORE_FIRST_IDX 5
    156163    "sfc.dll",
     164    "sfc_os.dll",
     165    "user32.dll",
     166    "acres.dll",
     167    "acgenral.dll",
     168#endif
    157169#ifdef VBOX_PERMIT_VISUAL_STUDIO_PROFILING
    158170    "psapi.dll",
     
    409421                                       "%s: Unexpected e_lfanew value: %#x", pImage->pszName, offNtHdrs);
    410422    }
    411     PIMAGE_NT_HEADERS pNtHdrs = (PIMAGE_NT_HEADERS)&pThis->abFile[offNtHdrs];
     423    PIMAGE_NT_HEADERS   pNtHdrs   = (PIMAGE_NT_HEADERS)&pThis->abFile[offNtHdrs];
     424    PIMAGE_NT_HEADERS32 pNtHdrs32 = (PIMAGE_NT_HEADERS32)pNtHdrs;
    412425    if (pNtHdrs->Signature != IMAGE_NT_SIGNATURE)
    413426        return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_IMAGE_SIGNATURE,
     
    418431     */
    419432#ifdef RT_ARCH_AMD64
    420     if (pNtHdrs->FileHeader.Machine != IMAGE_FILE_MACHINE_AMD64)
     433    if (pNtHdrs->FileHeader.Machine != IMAGE_FILE_MACHINE_AMD64 && !pImage->f32bitResourceDll)
    421434#else
    422435    if (pNtHdrs->FileHeader.Machine != IMAGE_FILE_MACHINE_I386)
     
    424437        return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_UNEXPECTED_IMAGE_MACHINE,
    425438                                   "%s: Unexpected machine: %#x", pImage->pszName, pNtHdrs->FileHeader.Machine);
    426 
    427     if (pNtHdrs->FileHeader.SizeOfOptionalHeader != sizeof(pNtHdrs->OptionalHeader))
     439    bool const fIs32Bit = pNtHdrs->FileHeader.Machine == IMAGE_FILE_MACHINE_I386;
     440
     441    if (pNtHdrs->FileHeader.SizeOfOptionalHeader != (fIs32Bit ? sizeof(IMAGE_OPTIONAL_HEADER32) : sizeof(IMAGE_OPTIONAL_HEADER64)))
    428442        return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_OPTIONAL_HEADER,
    429443                                   "%s: Unexpected optional header size: %#x",
    430444                                   pImage->pszName, pNtHdrs->FileHeader.SizeOfOptionalHeader);
    431445
    432     if (pNtHdrs->OptionalHeader.Magic != RT_CONCAT3(IMAGE_NT_OPTIONAL_HDR,ARCH_BITS,_MAGIC))
     446    if (pNtHdrs->OptionalHeader.Magic != (fIs32Bit ? IMAGE_NT_OPTIONAL_HDR32_MAGIC : IMAGE_NT_OPTIONAL_HDR64_MAGIC))
    433447        return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_OPTIONAL_HEADER,
    434448                                   "%s: Unexpected optional header magic: %#x", pImage->pszName, pNtHdrs->OptionalHeader.Magic);
    435     if (pNtHdrs->OptionalHeader.NumberOfRvaAndSizes != IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
     449
     450    uint32_t cDirs = (fIs32Bit ? pNtHdrs32->OptionalHeader.NumberOfRvaAndSizes : pNtHdrs->OptionalHeader.NumberOfRvaAndSizes);
     451    if (cDirs != IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
    436452        return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_OPTIONAL_HEADER,
    437                                    "%s: Unexpected data dirs: %#x", pImage->pszName, pNtHdrs->OptionalHeader.NumberOfRvaAndSizes);
     453                                   "%s: Unexpected data dirs: %#x", pImage->pszName, cDirs);
    438454
    439455    /*
     
    444460        return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_TOO_MANY_SECTIONS,
    445461                                   "%s: Too many section headers: %#x", pImage->pszName, cSections);
    446     suplibHardenedMemCopy(pThis->aSecHdrs, pNtHdrs + 1, cSections * sizeof(IMAGE_SECTION_HEADER));
    447 
    448     uintptr_t const uImageBase = pNtHdrs->OptionalHeader.ImageBase;
     462    suplibHardenedMemCopy(pThis->aSecHdrs, (fIs32Bit ? (void *)(pNtHdrs32 + 1) : (void *)(pNtHdrs + 1)),
     463                          cSections * sizeof(IMAGE_SECTION_HEADER));
     464
     465    uintptr_t const uImageBase = fIs32Bit ? pNtHdrs32->OptionalHeader.ImageBase : pNtHdrs->OptionalHeader.ImageBase;
    449466    if (uImageBase & PAGE_OFFSET_MASK)
    450467        return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_IMAGE_BASE,
    451468                                   "%s: Invalid image base: %p", pImage->pszName, uImageBase);
    452469
    453     uint32_t  const cbImage    = pNtHdrs->OptionalHeader.SizeOfImage;
     470    uint32_t  const cbImage    = fIs32Bit ? pNtHdrs32->OptionalHeader.SizeOfImage : pNtHdrs->OptionalHeader.SizeOfImage;
    454471    if (RT_ALIGN_32(pImage->cbImage, PAGE_SIZE) != RT_ALIGN_32(cbImage, PAGE_SIZE) && !pImage->fApiSetSchemaOnlySection1)
    455472        return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_IMAGE_SIZE,
     
    457474                                   pImage->pszName, cbImage, pImage->cbImage);
    458475
    459     uint32_t const cbSectAlign = pNtHdrs->OptionalHeader.SectionAlignment;
     476    uint32_t const cbSectAlign = fIs32Bit ? pNtHdrs32->OptionalHeader.SectionAlignment : pNtHdrs->OptionalHeader.SectionAlignment;
    460477    if (   !RT_IS_POWER_OF_TWO(cbSectAlign)
    461478        || cbSectAlign < PAGE_SIZE
     
    464481                                   "%s: Unexpected SectionAlignment value: %#x", pImage->pszName, cbSectAlign);
    465482
    466     uint32_t const cbFileAlign = pNtHdrs->OptionalHeader.FileAlignment;
     483    uint32_t const cbFileAlign = fIs32Bit ? pNtHdrs32->OptionalHeader.FileAlignment : pNtHdrs->OptionalHeader.FileAlignment;
    467484    if (!RT_IS_POWER_OF_TWO(cbFileAlign) || cbFileAlign < 512 || cbFileAlign > PAGE_SIZE || cbFileAlign > cbSectAlign)
    468485        return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_FILE_ALIGNMENT_VALUE,
     
    470487                                   pImage->pszName, cbFileAlign, cbSectAlign);
    471488
    472     uint32_t  const cbHeaders  = pNtHdrs->OptionalHeader.SizeOfHeaders;
    473     uint32_t  const cbMinHdrs  = offNtHdrs + sizeof(*pNtHdrs) + sizeof(IMAGE_SECTION_HEADER) * cSections;
     489    uint32_t  const cbHeaders  = fIs32Bit ? pNtHdrs32->OptionalHeader.SizeOfHeaders : pNtHdrs->OptionalHeader.SizeOfHeaders;
     490    uint32_t  const cbMinHdrs  = offNtHdrs + (fIs32Bit ? sizeof(*pNtHdrs32) : sizeof(*pNtHdrs) )
     491                               + sizeof(IMAGE_SECTION_HEADER) * cSections;
    474492    if (cbHeaders < cbMinHdrs)
    475493        return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_BAD_SIZE_OF_HEADERS,
     
    494512                                       "%s: Error reading image header from memory: %#x", pImage->pszName, rcNt);
    495513        if (uImageBase != pImage->uImageBase)
    496             pNtHdrs->OptionalHeader.ImageBase = pImage->uImageBase;
     514        {
     515            if (fIs32Bit)
     516                pNtHdrs32->OptionalHeader.ImageBase = (uint32_t)pImage->uImageBase;
     517            else
     518                pNtHdrs->OptionalHeader.ImageBase = pImage->uImageBase;
     519        }
    497520
    498521        rc = supHardNtVpFileMemCompare(pThis, pThis->abFile, pThis->abMemory, cbHeaders, pImage, 0 /*uRva*/);
     
    508531     */
    509532    pImage->fImageCharecteristics = pNtHdrs->FileHeader.Characteristics;
    510     pImage->fDllCharecteristics   = pNtHdrs->OptionalHeader.DllCharacteristics;
     533    pImage->fDllCharecteristics   = fIs32Bit ? pNtHdrs32->OptionalHeader.DllCharacteristics : pNtHdrs->OptionalHeader.DllCharacteristics;
    511534
    512535    /*
     
    641664     * disk content.
    642665     */
    643     int rc = supHardenedWinVerifyImageByHandle(hFile, pImage->Name.UniStr.Buffer,
    644                                                pImage->fDll ? 0 : SUPHNTVI_F_REQUIRE_BUILD_CERT,
    645                                                NULL /*pfCacheable*/, pThis->pErrInfo);
     666    uint32_t fFlags = pImage->fDll ? 0 : SUPHNTVI_F_REQUIRE_BUILD_CERT;
     667    if (pImage->f32bitResourceDll)
     668        fFlags |= SUPHNTVI_F_RESOURCE_IMAGE;
     669    int rc = supHardenedWinVerifyImageByHandle(hFile, pImage->Name.UniStr.Buffer, fFlags, NULL /*pfCacheable*/, pThis->pErrInfo);
    646670    if (RT_SUCCESS(rc))
    647671        rc = supHardNtVpVerifyImageCompareMemory(pThis, pImage, hProcess, hFile, pThis->pErrInfo);
     
    831855#ifndef VBOX_PERMIT_VISUAL_STUDIO_PROFILING
    832856            /* The directory name must match the one we've got for System32. */
    833             if (   cwcDirName * sizeof(WCHAR) != g_System32NtPath.UniStr.Length
    834                 || suplibHardenedMemComp(pImage->Name.UniStr.Buffer,
    835                                          g_System32NtPath.UniStr.Buffer,
    836                                          cwcDirName * sizeof(WCHAR)))
     857            if (   (   cwcDirName * sizeof(WCHAR) != g_System32NtPath.UniStr.Length
     858                    || suplibHardenedMemComp(pImage->Name.UniStr.Buffer,
     859                                            g_System32NtPath.UniStr.Buffer,
     860                                            cwcDirName * sizeof(WCHAR)) )
     861# ifdef VBOX_PERMIT_MORE
     862                && (   pImage->pszName[0] != 'a'
     863                    || pImage->pszName[1] != 'c'
     864                    || !supHardViIsAppPatchDir(pImage->Name.UniStr.Buffer, pImage->Name.UniStr.Length / sizeof(WCHAR)) )
     865# endif
     866                )
    837867                return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_NON_SYSTEM32_DLL,
    838868                                           "Expected %ls to be loaded from %ls.",
    839869                                           pImage->Name.UniStr.Buffer, g_System32NtPath.UniStr.Buffer);
    840 #endif
     870# ifdef VBOX_PERMIT_MORE
     871            if (g_uNtVerCombined < SUP_NT_VER_W70 && i >= VBOX_PERMIT_MORE_FIRST_IDX)
     872                pImage->pszName = NULL; /* hard limit: user32.dll is unwanted prior to w7. */
     873# endif
     874
     875#endif /* VBOX_PERMIT_VISUAL_STUDIO_PROFILING */
    841876            break;
    842877        }
     
    12321267        else if (suplibHardenedStrCmp(pThis->aImages[i].pszName, "apisetschema.dll") == 0)
    12331268            iApiSetSchema = i;
     1269#ifdef VBOX_PERMIT_MORE
     1270        else if (suplibHardenedStrCmp(pThis->aImages[i].pszName, "acres.dll") == 0)
     1271            pThis->aImages[i].f32bitResourceDll = true;
     1272#endif
    12341273    if (iNtDll == UINT32_MAX)
    12351274        return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_NO_NTDLL_MAPPING,
  • trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp

    r51999 r52030  
    624624                               g_offSupLibHardenedExeNtName * sizeof(WCHAR)) == 0)
    625625                fFlags |= SUPHNTVI_F_REQUIRE_KERNEL_CODE_SIGNING | SUPHNTVI_F_REQUIRE_SIGNATURE_ENFORCEMENT;
     626#ifdef VBOX_PERMIT_MORE
     627            else if (supHardViIsAppPatchDir(uBuf.UniStr.Buffer, uBuf.UniStr.Length / sizeof(WCHAR)))
     628                fFlags |= SUPHNTVI_F_ALLOW_CAT_FILE_VERIFICATION;
     629#endif
    626630#ifdef VBOX_PERMIT_VISUAL_STUDIO_PROFILING
    627631            /* Hack to allow profiling our code with Visual Studio. */
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