VirtualBox

Changeset 23916 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Oct 20, 2009 5:14:40 PM (15 years ago)
Author:
vboxsync
Message:

Verify VMMREQUEST (xTracker #4336).

Location:
trunk/src/VBox/Additions/common
Files:
2 edited

Legend:

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

    r23388 r23916  
    10041004        return VERR_INVALID_PARAMETER;
    10051005    }
     1006    int rc = VbglGRVerify(pReqHdr, cbData);
     1007    if (RT_FAILURE(rc))
     1008    {
     1009        Log(("VBoxGuestCommonIOCtl: VMMREQUEST: invalid header: size %#x, expected >= %#x (hdr); type=%#x; rc %d!!\n",
     1010             cbData, cbReq, enmType, rc));
     1011        return rc;
     1012    }
    10061013
    10071014    /*
     
    10131020     */
    10141021    VMMDevRequestHeader *pReqCopy;
    1015     int rc = VbglGRAlloc(&pReqCopy, cbReq, enmType);
     1022    rc = VbglGRAlloc(&pReqCopy, cbReq, enmType);
    10161023    if (RT_FAILURE(rc))
    10171024    {
  • trunk/src/VBox/Additions/common/VBoxGuestLib/GenericRequest.cpp

    r21461 r23916  
    2424#include <iprt/assert.h>
    2525#include <iprt/string.h>
     26
     27DECLVBGL(int) VbglGRVerify (const VMMDevRequestHeader *pReq, size_t cbReq)
     28{
     29    if (!pReq || cbReq < sizeof (VMMDevRequestHeader))
     30    {
     31        dprintf(("VbglGRVerify: Invalid parameter: pReq = %p, cbReq = %d\n", pReq, cbReq));
     32        return VERR_INVALID_PARAMETER;
     33    }
     34
     35    if (pReq->size > cbReq)
     36    {
     37        dprintf(("VbglGRVerify: request size %d > buffer size %d\n", pReq->size, cbReq));
     38        return VERR_INVALID_PARAMETER;
     39    }
     40
     41    /* The request size must correspond to the request type. */
     42    size_t cbReqExpected = vmmdevGetRequestSize(pReq->requestType);
     43
     44    if (cbReq < cbReqExpected)
     45    {
     46        dprintf(("VbglGRVerify: buffer size %d < expected size %d\n", cbReq, cbReqExpected));
     47        return VERR_INVALID_PARAMETER;
     48    }
     49
     50    if (cbReqExpected == cbReq)
     51    {
     52        /* This is most likely a fixed size request, and in this case the request size
     53         * must be also equal to the expected size.
     54         */
     55        if (pReq->size != cbReqExpected)
     56        {
     57            dprintf(("VbglGRVerify: request size %d != expected size %d\n", pReq->size, cbReqExpected));
     58            return VERR_INVALID_PARAMETER;
     59        }
     60
     61        return VINF_SUCCESS;
     62    }
     63
     64    /* This can be a variable size request. Check the request type and limit the size
     65     * to VMMDEV_MAX_VMMDEVREQ_SIZE, which is max size supported by the host.
     66     */
     67    if (   pReq->requestType == VMMDevReq_LogString
     68        || pReq->requestType == VMMDevReq_VideoSetVisibleRegion
     69        || pReq->requestType == VMMDevReq_SetPointerShape
     70#ifdef VBOX_WITH_64_BITS_GUESTS
     71        || pReq->requestType == VMMDevReq_HGCMCall32
     72        || pReq->requestType == VMMDevReq_HGCMCall64
     73#else
     74        || pReq->requestType == VMMDevReq_HGCMCall
     75#endif /* VBOX_WITH_64_BITS_GUESTS */
     76        || pReq->requestType == VMMDevReq_ChangeMemBalloon)
     77    {
     78        if (cbReq > VMMDEV_MAX_VMMDEVREQ_SIZE)
     79        {
     80            dprintf(("VbglGRVerify: VMMDevReq_LogString: buffer size %d too big\n", cbReq));
     81            return VERR_BUFFER_OVERFLOW; /* @todo is this error code ok? */
     82        }
     83    }
     84    else
     85    {
     86        dprintf(("VbglGRVerify: request size %d > buffer size %d\n", pReq->size, cbReq));
     87        return VERR_IO_BAD_LENGTH; /* @todo is this error code ok? */
     88    }
     89
     90    return VINF_SUCCESS;
     91}
    2692
    2793DECLVBGL(int) VbglGRAlloc (VMMDevRequestHeader **ppReq, uint32_t cbSize, VMMDevRequestType reqType)
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