VirtualBox

Changeset 54013 in vbox


Ignore:
Timestamp:
Jan 28, 2015 1:44:00 PM (10 years ago)
Author:
vboxsync
Message:

Support: added SUPR3LockDownLoader()

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/sup.h

    r53824 r54013  
    11371137
    11381138/**
     1139 * Lock down the module loader interface.
     1140 *
     1141 * This will lock down the module loader interface. No new modules can be
     1142 * loaded and all loaded modules can no longer be freed.
     1143 *
     1144 * @returns VBox status code.
     1145 * @param   pErrInfo        Where to return extended error information.
     1146 *                          Optional.
     1147 */
     1148SUPR3DECL(int) SUPR3LockDownLoader(PRTERRINFO pErrInfo);
     1149
     1150/**
    11391151 * Get the address of a symbol in a ring-0 module.
    11401152 *
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.c

    r53843 r54013  
    148148static int                  supdrvIOCtl_LdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRLOAD pReq);
    149149static int                  supdrvIOCtl_LdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRFREE pReq);
     150static int                  supdrvIOCtl_LdrLockDown(PSUPDRVDEVEXT pDevExt);
    150151static int                  supdrvIOCtl_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRGETSYMBOL pReq);
    151152static int                  supdrvIDC_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQGETSYM pReq);
     
    17101711        }
    17111712
     1713        case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_LDR_LOCK_DOWN):
     1714        {
     1715            /* validate */
     1716            REQ_CHECK_SIZES(SUP_IOCTL_LDR_LOCK_DOWN);
     1717
     1718            /* execute */
     1719            pReqHdr->rc = supdrvIOCtl_LdrLockDown(pDevExt);
     1720            return 0;
     1721        }
     1722
    17121723        case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_LDR_GET_SYMBOL):
    17131724        {
     
    45574568    /* (not found - add it!) */
    45584569
     4570    /* If the loader interface is locked down, make userland fail early */
     4571    if (pDevExt->fLdrLockedDown)
     4572    {
     4573        supdrvLdrUnlock(pDevExt);
     4574        Log(("supdrvIOCtl_LdrOpen: Not adding '%s' to image list, loader interface is locked down!\n", pReq->u.In.szName));
     4575        return VERR_PERMISSION_DENIED;
     4576    }
     4577
    45594578    /*
    45604579     * Allocate memory.
     
    47224741    }
    47234742
     4743    /* If the loader interface is locked down, don't load new images */
     4744    if (pDevExt->fLdrLockedDown)
     4745    {
     4746        supdrvLdrUnlock(pDevExt);
     4747        Log(("SUP_IOCTL_LDR_LOAD: Not loading '%s' image bits, loader interface is locked down!\n", pImage->szName));
     4748        return VERR_PERMISSION_DENIED;
     4749    }
     4750
    47244751    switch (pReq->u.In.eEPType)
    47254752    {
     
    49845011
    49855012/**
     5013 * Lock down the image loader interface.
     5014 *
     5015 * @returns IPRT status code.
     5016 * @param   pDevExt     Device globals.
     5017 */
     5018static int supdrvIOCtl_LdrLockDown(PSUPDRVDEVEXT pDevExt)
     5019{
     5020    LogFlow(("supdrvIOCtl_LdrLockDown:\n"));
     5021
     5022    supdrvLdrLock(pDevExt);
     5023    if (!pDevExt->fLdrLockedDown)
     5024    {
     5025        pDevExt->fLdrLockedDown = true;
     5026        Log(("supdrvIOCtl_LdrLockDown: Image loader interface locked down\n"));
     5027    }
     5028    supdrvLdrUnlock(pDevExt);
     5029
     5030    return VINF_SUCCESS;
     5031}
     5032
     5033
     5034/**
    49865035 * Gets the address of a symbol in an open image.
    49875036 *
     
    52525301    PSUPDRVLDRIMAGE pImagePrev;
    52535302    LogFlow(("supdrvLdrFree: pImage=%p\n", pImage));
     5303
     5304    /*
     5305     * Warn if we're releasing images while the image loader interface is
     5306     * locked down -- we won't be able to reload them!
     5307     */
     5308    if (pDevExt->fLdrLockedDown)
     5309        Log(("supdrvLdrFree: Warning: unloading '%s' image, while loader interface is locked down!\n", pImage->szName));
    52545310
    52555311    /* find it - arg. should've used doubly linked list. */
  • trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h

    r53269 r54013  
    215215 *          - (none).
    216216 */
    217 #define SUPDRV_IOC_VERSION                              0x001d0000
     217#define SUPDRV_IOC_VERSION                              0x001d0001
    218218
    219219/** SUP_IOCTL_COOKIE. */
     
    480480
    481481
     482/** @name SUP_IOCTL_LDR_LOCK_DOWN
     483 * Lock down the image loader interface.
     484 * @{
     485 */
     486#define SUP_IOCTL_LDR_LOCK_DOWN                         SUP_CTL_CODE_SIZE(38, SUP_IOCTL_LDR_LOCK_DOWN_SIZE)
     487#define SUP_IOCTL_LDR_LOCK_DOWN_SIZE                    sizeof(SUPREQHDR)
     488#define SUP_IOCTL_LDR_LOCK_DOWN_SIZE_IN                 sizeof(SUPREQHDR)
     489#define SUP_IOCTL_LDR_LOCK_DOWN_SIZE_OUT                sizeof(SUPREQHDR)
     490/** @} */
     491
     492
    482493/** @name SUP_IOCTL_LDR_GET_SYMBOL
    483494 * Get address of a symbol within an image.
  • trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h

    r53800 r54013  
    610610    /** Linked list of loaded code. */
    611611    PSUPDRVLDRIMAGE volatile        pLdrImages;
     612    /** Set if the image loading interface got disabled after loading all needed images */
     613    bool                            fLdrLockedDown;
    612614
    613615    /** @name These members for detecting whether an API caller is in ModuleInit.
  • trunk/src/VBox/HostDrivers/Support/SUPLib.cpp

    r53212 r54013  
    279279        strcpy(CookieReq.u.In.szMagic, SUPCOOKIE_MAGIC);
    280280        CookieReq.u.In.u32ReqVersion = SUPDRV_IOC_VERSION;
    281         const uint32_t uMinVersion = (SUPDRV_IOC_VERSION & 0xffff0000) == 0x001c0000
    282                                    ? 0x001c0001
     281        const uint32_t uMinVersion = (SUPDRV_IOC_VERSION & 0xffff0000) == 0x001d0000
     282                                   ? 0x001d0001
    283283                                   : SUPDRV_IOC_VERSION & 0xffff0000;
    284284        CookieReq.u.In.u32MinVersion = uMinVersion;
     
    10381038
    10391039
     1040SUPR3DECL(int) SUPR3LockDownLoader(PRTERRINFO pErrInfo)
     1041{
     1042    /* fake */
     1043    if (RT_UNLIKELY(g_uSupFakeMode))
     1044        return VINF_SUCCESS;
     1045
     1046    /*
     1047     * Lock down the module loader interface.
     1048     */
     1049    SUPREQHDR ReqHdr;
     1050    ReqHdr.u32Cookie = g_u32Cookie;
     1051    ReqHdr.u32SessionCookie = g_u32SessionCookie;
     1052    ReqHdr.cbIn = SUP_IOCTL_LDR_LOCK_DOWN_SIZE_IN;
     1053    ReqHdr.cbOut = SUP_IOCTL_LDR_LOCK_DOWN_SIZE_OUT;
     1054    ReqHdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
     1055    ReqHdr.rc = VERR_INTERNAL_ERROR;
     1056    int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_LDR_LOCK_DOWN, &ReqHdr, SUP_IOCTL_LDR_LOCK_DOWN_SIZE);
     1057    if (RT_FAILURE(rc))
     1058        return RTErrInfoSetF(pErrInfo, rc,
     1059                             "SUPR3LockDownLoader: SUP_IOCTL_LDR_LOCK_DOWN ioctl returned %Rrc", rc);
     1060
     1061    return ReqHdr.rc;
     1062}
     1063
     1064
    10401065/**
    10411066 * Fallback for SUPR3PageAllocEx on systems where RTR0MemObjPhysAllocNC isn't
  • trunk/src/VBox/VMM/tools/VBoxVMMPreload.cpp

    r46175 r54013  
    5252
    5353static uint32_t     g_cVerbose = 1;
     54static bool         g_fLockDown = false;
    5455
    5556
     
    7172        { "--only",     'o', RTGETOPT_REQ_STRING  },
    7273        { "--quiet",    'q', RTGETOPT_REQ_NOTHING },
     74        { "--lock" ,    'l', RTGETOPT_REQ_NOTHING },
    7375        { "--verbose",  'v', RTGETOPT_REQ_NOTHING },
    7476    };
     
    115117                break;
    116118
     119            case 'l':
     120                g_fLockDown = true;
     121                break;
     122
    117123            case 'h':
    118124                RTPrintf(VBOX_PRODUCT " VMM ring-0 Module Preloader Version " VBOX_VERSION_STRING
     
    120126                         "All rights reserved.\n"
    121127                         "\n"
    122                          "Usage: VBoxVMMPreload [-hqvV] [-o|--only <mod>]\n"
     128                         "Usage: VBoxVMMPreload [-hlqvV] [-o|--only <mod>]\n"
    123129                         "\n");
    124130                *pfExit = true;
     
    145151static RTEXITCODE LoadModules(void)
    146152{
     153    RTERRINFOSTATIC ErrInfo;
     154
    147155    for (uint32_t i = 0; i < RT_ELEMENTS(g_aModules); i++)
    148156    {
     
    156164                return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAppPrivateArch or RTPathAppend returned %Rrc", rc);
    157165
    158             RTERRINFOSTATIC ErrInfo;
    159166            RTErrInfoInitStatic(&ErrInfo);
    160167            rc = SUPR3LoadModule(szPath, g_aModules[i].pszName, &g_aModules[i].pvImageBase, &ErrInfo.Core);
     
    167174    }
    168175
     176    if (g_fLockDown)
     177    {
     178        RTErrInfoInitStatic(&ErrInfo);
     179        int rc = SUPR3LockDownLoader(&ErrInfo.Core);
     180        if (RT_FAILURE(rc))
     181            return RTMsgErrorExit(RTEXITCODE_FAILURE, "SUPR3LockDownLoader failed: %s (rc=%Rrc)",
     182                                  ErrInfo.Core.pszMsg, rc);
     183        if (g_cVerbose >= 1)
     184            RTMsgInfo("Locked down module loader interface!\n");
     185    }
     186
    169187    RTStrmFlush(g_pStdOut);
    170188    return RTEXITCODE_SUCCESS;
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