VirtualBox

Changeset 75753 in vbox


Ignore:
Timestamp:
Nov 27, 2018 12:45:55 AM (6 years ago)
Author:
vboxsync
Message:

VBoxGuestR0LibHGCMInternal.cpp: Adjusted copy back of VMMDevHGCMParmType_Embedded buffers, allowing the host to return a too large buffer size in error cases so it can convey useful info in buffer overflow scenarios.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibHGCMInternal.cpp

    r75554 r75753  
    862862            case VMMDevHGCMParmType_Embedded:
    863863            {
    864                 uint32_t cb;
    865                 pDstParm->u.Embedded.cbData = cb = pSrcParm->u.Embedded.cbData;
    866                 if (    cb > 0
     864                uint32_t const cbDst = pDstParm->u.Embedded.cbData;
     865                uint32_t       cbSrc;
     866                pDstParm->u.Embedded.cbData = cbSrc = pSrcParm->u.Embedded.cbData;
     867                if (    cbSrc > 0
    867868                    && (pDstParm->u.Embedded.fFlags & VBOX_HGCM_F_PARM_DIRECTION_FROM_HOST))
    868869                {
    869870                    uint32_t const offDst = pDstParm->u.Embedded.offData;
    870                     uint32_t const offSrc = pDstParm->u.Embedded.offData;
     871                    uint32_t const offSrc = pSrcParm->u.Embedded.offData;
     872
    871873                    AssertReturn(offDst < cbCallInfo, VERR_INTERNAL_ERROR_2);
    872874                    AssertReturn(offDst >= sizeof(*pCallInfo) + cParms * sizeof(*pDstParm), VERR_INTERNAL_ERROR_2);
    873                     AssertReturn(cb <= cbCallInfo - offDst , VERR_INTERNAL_ERROR_2);
     875                    AssertReturn(cbDst  <= cbCallInfo - offDst , VERR_INTERNAL_ERROR_2);
     876
    874877                    AssertReturn(offSrc < cbCallInfo, VERR_INTERNAL_ERROR_2);
    875878                    AssertReturn(offSrc >= sizeof(*pHGCMCall) + cParms * sizeof(*pSrcParm), VERR_INTERNAL_ERROR_2);
    876                     AssertReturn(cb <= cbHGCMCall - offSrc, VERR_INTERNAL_ERROR_2);
    877 
    878                     memcpy((uint8_t *)pCallInfo + offDst, (uint8_t const *)pHGCMCall + offSrc, cb);
     879                    if (cbSrc <= cbHGCMCall - offSrc)
     880                    { /* likely */ }
     881                    else
     882                    {
     883                        /* Special case: Buffer overflow w/ correct size given. */
     884                        AssertReturn(RT_FAILURE_NP(rc), VERR_INTERNAL_ERROR_2);
     885                        cbSrc = cbHGCMCall - offSrc;
     886                    }
     887                    memcpy((uint8_t *)pCallInfo + offDst, (uint8_t const *)pHGCMCall + offSrc, RT_MIN(cbSrc, cbDst));
    879888                }
    880889                break;
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