VirtualBox

儲存庫 vbox 的更動 12423


忽略:
時間撮記:
2008-9-12 下午02:42:49 (16 年 以前)
作者:
vboxsync
訊息:

IPRT/SUP: Renamed RTLdrOpenAppSharedLib to RTLdrOpenAppPriv. Hardend versions of RTLdrOpen and RTLdrOpenAppPriv. Use the hardend versions where appropriate.

位置:
trunk
檔案:
修改 9 筆資料

圖例:

未更動
新增
刪除
  • trunk/include/VBox/sup.h

    r11889 r12423  
    566566
    567567/**
    568  * Verifies the integrity of a file, and optionally opens it.
    569  * 
    570  * The integrity check is for whether the file is suitable for loading into
    571  * the hypervisor or VM process. The integrity check may include verifying
    572  * the authenticode/elfsign/whatever signature of the file, which can take
    573  * a little while.
    574  *
    575  * @returns VBox status code. On failure it will have printed a LogRel message.
    576  *
    577  * @param   pszFilename     The file.
    578  * @param   pszWhat         For the LogRel on failure.
    579  * @param   phFile          Where to store the handle to the opened file. This is optional, pass NULL
    580  *                          if the file should not be opened.
    581  */
    582 SUPR3DECL(int) SUPR3HardenedVerifyFile(const char *pszFilename, const char *pszWhat, PRTFILE phFile);
    583 
    584 /**
    585  * Load a module into R0 HC.
    586  * 
    587  * This will verify the file integrity in a similar manner as
     568 * Load a module into R0 HC.
     569 *
     570 * This will verify the file integrity in a similar manner as
    588571 * SUPR3HardenedVerifyFile before loading it.
    589572 *
     
    637620 */
    638621SUPR3DECL(int) SUPGipGetPhys(PRTHCPHYS pHCPhys);
     622
     623/**
     624 * Verifies the integrity of a file, and optionally opens it.
     625 *
     626 * The integrity check is for whether the file is suitable for loading into
     627 * the hypervisor or VM process. The integrity check may include verifying
     628 * the authenticode/elfsign/whatever signature of the file, which can take
     629 * a little while.
     630 *
     631 * @returns VBox status code. On failure it will have printed a LogRel message.
     632 *
     633 * @param   pszFilename     The file.
     634 * @param   pszWhat         For the LogRel on failure.
     635 * @param   phFile          Where to store the handle to the opened file. This is optional, pass NULL
     636 *                          if the file should not be opened.
     637 */
     638SUPR3DECL(int) SUPR3HardenedVerifyFile(const char *pszFilename, const char *pszWhat, PRTFILE phFile);
     639
     640/**
     641 * Same as RTLdrLoad() but will verify the files it loads (hardened builds).
     642 *
     643 * Will add dll suffix if missing and try load the file.
     644 *
     645 * @returns iprt status code.
     646 * @param   pszFilename Image filename. This must have a path.
     647 * @param   phLdrMod    Where to store the handle to the loaded module.
     648 */
     649SUPR3DECL(int) SUPR3HardenedLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod);
     650
     651/**
     652 * Same as RTLdrLoadAppPriv() but it will verify the files it loads (hardened
     653 * builds).
     654 *
     655 * Will add dll suffix to the file if missing, then look for it in the
     656 * architecture dependent application directory.
     657 *
     658 * @returns iprt status code.
     659 * @param   pszFilename Image filename.
     660 * @param   phLdrMod    Where to store the handle to the loaded module.
     661 */
     662SUPR3DECL(int) SUPR3HardenedLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod);
    639663
    640664/** @} */
  • trunk/include/iprt/ldr.h

    r11888 r12423  
    6969
    7070/**
    71  * Loads a dynamic load library (/shared object) image file using native
    72  * OS facilities.
    73  *
    74  * If the path is specified in the filename, only this path is used.
    75  * If only the image file name is specified, then try to load it from:
    76  *   - RTPathAppPrivateArch
    77  *   - RTPathSharedLibs (legacy)
    78  *
    79  * @returns iprt status code.
    80  * @param   pszFilename Image filename.
     71 * Loads a dynamic load library (/shared object) image file residing in the
     72 * RTPathAppPrivateArch() directory.
     73 *
     74 * Suffix is not required.
     75 *
     76 * @returns iprt status code.
     77 * @param   pszFilename Image filename. No path.
    8178 * @param   phLdrMod    Where to store the handle to the loaded module.
    8279 */
    83 RTDECL(int) RTLdrLoadAppSharedLib(const char *pszFilename, PRTLDRMOD phLdrMod);
     80RTDECL(int) RTLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod);
    8481
    8582/**
  • trunk/src/VBox/Devices/Serial/DevSerial.cpp

    r11284 r12423  
    242242    if (RT_LIKELY(s->pDrvChar))
    243243        s->pDrvChar->pfnSetParameters(s->pDrvChar, speed, parity, data_bits, stop_bits);
     244#ifdef RT_OS_DARWIN
     245    if (RT_LIKELY(s->pDrvChar))
     246        s->cNsDelay = (69444 - 2000) / s->divider; /* 69444 == 1000,000,000 / (115,000 / 8); 2000 = fudge factor */
     247#endif
    244248}
    245249
     
    386390    case 5:
    387391        ret = s->lsr;
     392#ifdef RT_OS_DARWIN
     393        if (    !(ret & UART_LSR_THRE)
     394            &&   pThis->HeldXmitNanoTS
     395            &&  RTTimeNanoTS() - s->HeldXmitNanoTS >= s->cNsDelay) {
     396            ret = s->lsr |= UART_LSR_THRE;
     397        }
     398#endif
    388399        break;
    389400    case 6:
  • trunk/src/VBox/Devices/Storage/VBoxHDD-new.cpp

    r12368 r12423  
    2626#include <VBox/VBoxHDD-new.h>
    2727#include <VBox/err.h>
    28 
     28#include <VBox/sup.h>
    2929#include <VBox/log.h>
     30
    3031#include <iprt/alloc.h>
    3132#include <iprt/assert.h>
     
    195196
    196197        /* Try to load the plugin (RTLdrLoad takes care of the suffix). */
    197         rc = RTLdrLoad(pszPluginName, &hPlugin);
     198        rc = SUPR3HardenedLdrLoad(pszPluginName, &hPlugin);
    198199        if (RT_SUCCESS(rc))
    199200        {
     
    730731            }
    731732
    732             rc = RTLdrLoad(pszPluginPath, &hPlugin);
     733            rc = SUPR3HardenedLdrLoad(pszPluginPath, &hPlugin);
    733734            if (RT_SUCCESS(rc))
    734735            {
     
    10151016            }
    10161017
    1017             rc = RTLdrLoad(pszPluginPath, &hPlugin);
     1018            rc = SUPR3HardenedLdrLoad(pszPluginPath, &hPlugin);
    10181019            if (RT_SUCCESS(rc))
    10191020            {
  • trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp

    r11822 r12423  
    5151#include <iprt/param.h>
    5252#include <iprt/process.h>
     53#include <VBox/sup.h>
    5354#endif
    5455
     
    690691
    691692            Log2(("VBoxHeadless: loading VBoxFFmpegFB shared library\n"));
    692             rrc = RTLdrLoad("VBoxFFmpegFB", &hLdrFFmpegFB);
     693            rrc = SUPR3HardenedLdrLoad("VBoxFFmpegFB", &hLdrFFmpegFB);
    693694
    694695            if (RT_SUCCESS(rrc))
  • trunk/src/VBox/HostDrivers/Support/SUPLib.cpp

    r11889 r12423  
    4747 */
    4848
    49 
    5049/*******************************************************************************
    5150*   Header Files                                                               *
     
    6867#include <iprt/thread.h>
    6968#include <iprt/process.h>
     69#include <iprt/path.h>
    7070#include <iprt/string.h>
    7171#include <iprt/env.h>
     
    738738    {
    739739        RTHCPHYS    Phys = (uintptr_t)pvStart + PAGE_SIZE * 1024;
    740         unsigned    iPage = cPages;
     740        size_t      iPage = cPages;
    741741        while (iPage-- > 0)
    742742            paPages[iPage].Phys = Phys + (iPage << PAGE_SHIFT);
     
    758758        pReq->Hdr.rc = VERR_INTERNAL_ERROR;
    759759        pReq->u.In.pvR3 = pvStart;
    760         pReq->u.In.cPages = cPages; AssertRelease(pReq->u.In.cPages == cPages);
     760        pReq->u.In.cPages = (uint32_t)cPages; AssertRelease(pReq->u.In.cPages == cPages);
    761761        rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_PAGE_LOCK, pReq, SUP_IOCTL_PAGE_LOCK_SIZE(cPages));
    762762        if (RT_SUCCESS(rc))
     
    876876        pReq->Hdr.fFlags = SUPREQHDR_FLAGS_MAGIC | SUPREQHDR_FLAGS_EXTRA_OUT;
    877877        pReq->Hdr.rc = VERR_INTERNAL_ERROR;
    878         pReq->u.In.cPages = cPages; AssertRelease(pReq->u.In.cPages == cPages);
     878        pReq->u.In.cPages = (uint32_t)cPages; AssertRelease(pReq->u.In.cPages == cPages);
    879879        rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_PAGE_ALLOC, pReq, SUP_IOCTL_PAGE_ALLOC_SIZE(cPages));
    880880        if (RT_SUCCESS(rc))
     
    991991    Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
    992992    Req.Hdr.rc = VERR_INTERNAL_ERROR;
    993     Req.u.In.cPages = cPages;
     993    Req.u.In.cPages = (uint32_t)cPages;
    994994    int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_CONT_ALLOC, &Req, SUP_IOCTL_CONT_ALLOC_SIZE);
    995995    if (    RT_SUCCESS(rc)
     
    10601060        /* fake physical addresses. */
    10611061        RTHCPHYS    Phys = (uintptr_t)*ppvPages + PAGE_SIZE * 1024;
    1062         unsigned    iPage = cPages;
     1062        size_t      iPage = cPages;
    10631063        while (iPage-- > 0)
    10641064            paPages[iPage].Phys = Phys + (iPage << PAGE_SHIFT);
     
    10791079        pReq->Hdr.fFlags = SUPREQHDR_FLAGS_MAGIC | SUPREQHDR_FLAGS_EXTRA_OUT;
    10801080        pReq->Hdr.rc = VERR_INTERNAL_ERROR;
    1081         pReq->u.In.cPages = cPages; AssertRelease(pReq->u.In.cPages == cPages);
     1081        pReq->u.In.cPages = (uint32_t)cPages; AssertRelease(pReq->u.In.cPages == cPages);
    10821082        rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_LOW_ALLOC, pReq, SUP_IOCTL_LOW_ALLOC_SIZE(cPages));
    10831083        if (RT_SUCCESS(rc))
     
    11481148    AssertPtr(pszFilename);
    11491149    AssertPtr(pszMsg);
    1150     AssertReturn(!phFile, VERR_NOT_IMPLEMENTED); /** @todo Implement this. The deal is that we make sure the 
     1150    AssertReturn(!phFile, VERR_NOT_IMPLEMENTED); /** @todo Implement this. The deal is that we make sure the
    11511151                                                     file is the same we verified after opening it. */
    11521152
     
    11921192    }
    11931193    else
    1194         LogRel(("SUPLoadModule: Verification of \"%s\" failed, rc=%Rrc\n", rc)); 
     1194        LogRel(("SUPLoadModule: Verification of \"%s\" failed, rc=%Rrc\n", rc));
    11951195    return rc;
    11961196}
     
    18901890}
    18911891
     1892
     1893/**
     1894 * Worker for SUPR3HardenedLdrLoad and SUPR3HardenedLdrLoadAppPriv.
     1895 *
     1896 * @returns iprt status code.
     1897 * @param   pszFilename     The full file name.
     1898 * @param   phLdrMod        Where to store the handle to the loaded module.
     1899 */
     1900static int supR3HardenedLdrLoadIt(const char *pszFilename, PRTLDRMOD phLdrMod)
     1901{
     1902#ifdef VBOX_WITH_HARDENING
     1903    /*
     1904     * Verify the image file.
     1905     */
     1906    rc = supR3HardenedVerifyFile(pszFilename, false /* fFatal */);
     1907    if (RT_FAILURE(rc))
     1908    {
     1909        LogRel(("supR3HardenedLdrLoadIt: Verification of \"%s\" failed, rc=%Rrc\n", rc));
     1910        return rc;
     1911    }
     1912#endif
     1913
     1914    /*
     1915     * Try load it.
     1916     */
     1917    return RTLdrLoad(pszFilename, phLdrMod);
     1918}
     1919
     1920
     1921SUPR3DECL(int) SUPR3HardenedLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod)
     1922{
     1923    /*
     1924     * Validate input.
     1925     */
     1926    AssertPtrReturn(pszFilename, VERR_INVALID_PARAMETER);
     1927    AssertPtrReturn(phLdrMod, VERR_INVALID_PARAMETER);
     1928    *phLdrMod = NIL_RTLDRMOD;
     1929    AssertReturn(RTPathHavePath(pszFilename), VERR_INVALID_PARAMETER);
     1930
     1931    /*
     1932     * Add the default extension if it's missing.
     1933     */
     1934    if (!RTPathHaveExt(pszFilename))
     1935    {
     1936        const char *pszSuff = RTLdrGetSuff();
     1937        size_t      cchSuff = strlen(pszSuff);
     1938        size_t      cchFilename = strlen(pszFilename);
     1939        char       *psz = (char *)alloca(cchFilename + cchSuff + 1);
     1940        AssertReturn(psz, VERR_NO_TMP_MEMORY);
     1941        memcpy(psz, pszFilename, cchFilename);
     1942        memcpy(psz + cchFilename, pszSuff, cchSuff + 1);
     1943        pszFilename = psz;
     1944    }
     1945
     1946    /*
     1947     * Pass it on to the common library loader.
     1948     */
     1949    return supR3HardenedLdrLoadIt(pszFilename, phLdrMod);
     1950}
     1951
     1952
     1953SUPR3DECL(int) SUPR3HardenedLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod)
     1954{
     1955    LogFlow(("SUPR3HardenedLdrLoadAppPriv: pszFilename=%p:{%s} phLdrMod=%p\n", pszFilename, pszFilename, phLdrMod));
     1956
     1957    /*
     1958     * Validate input.
     1959     */
     1960    AssertPtrReturn(phLdrMod, VERR_INVALID_PARAMETER);
     1961    *phLdrMod = NIL_RTLDRMOD;
     1962    AssertPtrReturn(pszFilename, VERR_INVALID_PARAMETER);
     1963    AssertMsgReturn(!RTPathHavePath(pszFilename), ("%s\n", pszFilename), VERR_INVALID_PARAMETER);
     1964
     1965    /*
     1966     * Check the filename.
     1967     */
     1968    size_t cchFilename = strlen(pszFilename);
     1969    AssertMsgReturn(cchFilename < (RTPATH_MAX / 4) * 3, ("%zu\n", cchFilename), VERR_INVALID_PARAMETER);
     1970
     1971    const char *pszExt = "";
     1972    size_t cchExt = 0;
     1973    if (!RTPathHaveExt(pszFilename))
     1974    {
     1975        pszExt = RTLdrGetSuff();
     1976        cchExt = strlen(pszExt);
     1977    }
     1978
     1979    /*
     1980     * Construct the private arch path and check if the file exists.
     1981     */
     1982    char szPath[RTPATH_MAX];
     1983    int rc = RTPathAppPrivateArch(szPath, sizeof(szPath) - 1 - cchExt - cchFilename);
     1984    AssertRCReturn(rc, rc);
     1985
     1986    char *psz = strchr(szPath, '\0');
     1987    *psz++ = RTPATH_SLASH;
     1988    memcpy(psz, pszFilename, cchFilename);
     1989    psz += cchFilename;
     1990    memcpy(psz, pszExt, cchExt + 1);
     1991
     1992    if (!RTPathExists(szPath))
     1993    {
     1994        LogRel(("SUPR3HardenedLdrLoadAppPriv: \"%s\" not found\n", szPath));
     1995        return VERR_FILE_NOT_FOUND;
     1996    }
     1997
     1998    /*
     1999     * Pass it on to SUPR3HardenedLdrLoad.
     2000     */
     2001    rc = SUPR3HardenedLdrLoad(szPath, phLdrMod);
     2002
     2003    LogFlow(("SUPR3HardenedLdrLoadAppPriv: returns %Rrc\n", rc));
     2004    return rc;
     2005}
     2006
  • trunk/src/VBox/Main/ConsoleVRDPServer.cpp

    r12127 r12423  
    19491949    if (!mVRDPLibrary)
    19501950    {
    1951         rc = RTLdrLoadAppSharedLib ("VBoxVRDP", &mVRDPLibrary);
     1951        rc = SUPR3HardenedLdrLoadAppPriv ("VBoxVRDP", &mVRDPLibrary);
    19521952
    19531953        if (VBOX_SUCCESS(rc))
  • trunk/src/VBox/Main/hgcm/HGCM.cpp

    r10807 r12423  
    131131        static DECLCALLBACK(void) svcHlpCallComplete (VBOXHGCMCALLHANDLE callHandle, int32_t rc);
    132132        static DECLCALLBACK(void) svcHlpDisconnectClient (void *pvInstance, uint32_t u32ClientId);
    133        
     133
    134134    public:
    135135
     
    253253    }
    254254
    255     int rc = RTLdrLoadAppSharedLib (m_pszSvcLibrary, &m_hLdrMod);
     255    int rc = SUPR3HardenedLdrLoadAppPriv (m_pszSvcLibrary, &m_hLdrMod);
    256256
    257257    if (VBOX_SUCCESS(rc))
     
    716716{
    717717     HGCMService *pService = static_cast <HGCMService *> (pvInstance);
    718      
     718
    719719     if (pService)
    720720     {
  • trunk/src/VBox/Runtime/common/ldr/ldrNative.cpp

    r11888 r12423  
    137137
    138138/**
    139  * Loads a dynamic load library (/shared object) image file using native
    140  * OS facilities.
    141  *
    142  * If the path is specified in the filename, only this path is used.
    143  * If only the image file name is specified, then try to load it from:
    144  *   - RTPathAppPrivateArch
    145  *   - RTPathSharedLibs (legacy)
     139 * Loads a dynamic load library (/shared object) image file residing in the
     140 * RTPathAppPrivateArch() directory.
     141 *
     142 * Suffix is not required.
    146143 *
    147144 * @returns iprt status code.
    148  * @param   pszFilename Image filename.
     145 * @param   pszFilename Image filename. No path.
    149146 * @param   phLdrMod    Where to store the handle to the loaded module.
    150147 */
    151 RTDECL(int) RTLdrLoadAppSharedLib(const char *pszFilename, PRTLDRMOD phLdrMod)
    152 {
    153     LogFlow(("RTLdrLoadAppSharedLib: pszFilename=%p:{%s} phLdrMod=%p\n", pszFilename, pszFilename, phLdrMod));
     148RTDECL(int) RTLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod)
     149{
     150    LogFlow(("RTLdrLoadAppPriv: pszFilename=%p:{%s} phLdrMod=%p\n", pszFilename, pszFilename, phLdrMod));
    154151
    155152    /*
    156153     * Validate input.
    157154     */
    158     AssertMsgReturn(VALID_PTR(pszFilename), ("pszFilename=%p\n", pszFilename), VERR_INVALID_PARAMETER);
    159     AssertMsgReturn(VALID_PTR(phLdrMod), ("phLdrMod=%p\n", phLdrMod), VERR_INVALID_PARAMETER);
    160 
    161     /*
    162      * If a path is specified, just load the file.
    163      */
    164     if (RTPathHavePath(pszFilename))
    165         return RTLdrLoad(pszFilename, phLdrMod);
    166 
    167     /*
    168      * By default nothing is found.
    169      */
    170     int rc = VERR_FILE_NOT_FOUND;
     155    AssertPtrReturn(phLdrMod, VERR_INVALID_PARAMETER);
    171156    *phLdrMod = NIL_RTLDRMOD;
    172 
    173     /*
    174      * Try default locations.
    175      */
    176     int i;
    177     for (i = 0;; i++)
     157    AssertPtrReturn(pszFilename, VERR_INVALID_PARAMETER);
     158    AssertMsgReturn(!RTPathHavePath(pszFilename), ("%s\n", pszFilename), VERR_INVALID_PARAMETER);
     159
     160    /*
     161     * Check the filename.
     162     */
     163    size_t cchFilename = strlen(pszFilename);
     164    AssertMsgReturn(cchFilename > (RTPATH_MAX / 4) * 3, ("%zu\n", cchFilename), VERR_INVALID_PARAMETER);
     165
     166    const char *pszExt = "";
     167    size_t cchExt = 0;
     168    if (!RTPathHaveExt(pszFilename))
    178169    {
    179         /*
    180          * Get the appropriate base path.
    181          */
    182         char szBase[RTPATH_MAX];
    183         if (i == 0)
    184             rc = RTPathAppPrivateArch(szBase, sizeof (szBase));
    185         else if (i == 1)
    186             rc = RTPathSharedLibs(szBase, sizeof (szBase));
    187         else
    188             break;
    189 
    190         if (RT_SUCCESS(rc))
    191         {
    192             /*
    193              * Got the base path. Construct szPath = pszBase + pszFilename
    194              */
    195             char szPath[RTPATH_MAX];
    196             rc = RTPathAbsEx(szBase, pszFilename, szPath, sizeof (szPath));
    197             if (RT_SUCCESS(rc))
    198             {
    199                 /*
    200                  * Finally try to load the image file.
    201                  */
    202                 rc = RTLdrLoad(szPath, phLdrMod);
    203                 if (RT_SUCCESS(rc))
    204                 {
    205                     /*
    206                      * Successfully loaded the image file.
    207                      */
    208                     LogFlow(("Library loaded: [%s]\n", szPath));
    209                     break;
    210                 }
    211             }
    212         }
     170        pszExt = RTLdrGetSuff();
     171        cchExt = strlen(pszExt);
    213172    }
    214     LogFlow(("RTLdrLoadAppSharedLib: returns %Rrc\n", rc));
     173
     174    /*
     175     * Construct the private arch path and check if the file exists.
     176     */
     177    char szPath[RTPATH_MAX];
     178    int rc = RTPathAppPrivateArch(szPath, sizeof(szPath) - 1 - cchExt - cchFilename);
     179    AssertRCReturn(rc, rc);
     180
     181    char *psz = strchr(szPath, '\0');
     182    *psz++ = RTPATH_SLASH;
     183    memcpy(psz, pszFilename, cchFilename);
     184    psz += cchFilename;
     185    memcpy(psz, pszExt, cchExt + 1);
     186
     187    if (!RTPathExists(szPath))
     188    {
     189        LogRel(("RTLdrLoadAppPriv: \"%s\" not found\n", szPath));
     190        return VERR_FILE_NOT_FOUND;
     191    }
     192
     193    /*
     194     * Pass it on to RTLdrLoad.
     195     */
     196    rc = RTLdrLoad(szPath, phLdrMod);
     197
     198    LogFlow(("RTLdrLoadAppPriv: returns %Rrc\n", rc));
    215199    return rc;
    216200}
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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