VirtualBox

Changeset 52575 in vbox


Ignore:
Timestamp:
Sep 3, 2014 7:36:27 AM (10 years ago)
Author:
vboxsync
Message:

SUPDrv: Several fixes, thanks to Mathias Krause.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.c

    r52192 r52575  
    22932293 * @param   pReqHdr     The request header.
    22942294 */
    2295 int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr)
     2295int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr, size_t cbReq)
    22962296{
    22972297    int rc;
     
    23012301     * Validate the request.
    23022302     */
    2303     /* this first check could probably be omitted as its also done by the OS specific code... */
     2303    if (RT_UNLIKELY(cbReq < sizeof(*pReqHdr)))
     2304    {
     2305        OSDBGPRINT(("vboxdrv: Bad ioctl request size; cbReq=%#lx\n", (long)cbReq));
     2306        VBOXDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VINF_SUCCESS);
     2307        return VERR_INVALID_PARAMETER;
     2308    }
    23042309    if (RT_UNLIKELY(   (pReqHdr->fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC
    23052310                    || pReqHdr->cbIn < sizeof(*pReqHdr)
    2306                     || pReqHdr->cbOut < sizeof(*pReqHdr)))
     2311                    || pReqHdr->cbIn > cbReq
     2312                    || pReqHdr->cbOut < sizeof(*pReqHdr)
     2313                    || pReqHdr->cbOut > cbReq))
    23072314    {
    23082315        OSDBGPRINT(("vboxdrv: Bad ioctl request header; cbIn=%#lx cbOut=%#lx fFlags=%#lx\n",
     
    44484455            &&  !memcmp(pImage->szName, pReq->u.In.szName, cchName))
    44494456        {
    4450             /** @todo check cbImageBits and cbImageWithTabs here, if they differs that indicates that the images are different. */
    4451             pImage->cUsage++;
    4452             pReq->u.Out.pvImageBase   = pImage->pvImage;
    4453             pReq->u.Out.fNeedsLoading = pImage->uState == SUP_IOCTL_LDR_OPEN;
    4454             pReq->u.Out.fNativeLoader = pImage->fNative;
    4455             supdrvLdrAddUsage(pSession, pImage);
     4457            if (RT_LIKELY(pImage->cUsage < UINT32_MAX / 2U))
     4458            {
     4459                /** @todo check cbImageBits and cbImageWithTabs here, if they differs that indicates that the images are different. */
     4460                pImage->cUsage++;
     4461                pReq->u.Out.pvImageBase   = pImage->pvImage;
     4462                pReq->u.Out.fNeedsLoading = pImage->uState == SUP_IOCTL_LDR_OPEN;
     4463                pReq->u.Out.fNativeLoader = pImage->fNative;
     4464                supdrvLdrAddUsage(pSession, pImage);
     4465                supdrvLdrUnlock(pDevExt);
     4466                return VINF_SUCCESS;
     4467            }
    44564468            supdrvLdrUnlock(pDevExt);
    4457             return VINF_SUCCESS;
     4469            Log(("supdrvIOCtl_LdrOpen: To many existing references to '%s'!\n", pReq->u.In.szName));
     4470            return VERR_INTERNAL_ERROR_3; /** @todo add VERR_TOO_MANY_REFERENCES */
    44584471        }
    44594472    }
  • trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h

    r52353 r52575  
    823823*******************************************************************************/
    824824/* SUPDrv.c */
    825 int  VBOXCALL   supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr);
     825int  VBOXCALL   supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr, size_t cbReq);
    826826int  VBOXCALL   supdrvIOCtlFast(uintptr_t uIOCtl, VMCPUID idCpu, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
    827827int  VBOXCALL   supdrvIDC(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQHDR pReqHdr);
  • trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp

    r52192 r52575  
    689689            return rc;
    690690        }
     691        if (Hdr.cbIn < cbReq)
     692            RT_BZERO((uint8_t *)pHdr + Hdr.cbIn, cbReq - Hdr.cbIn)
    691693    }
    692694    else
     
    699701     * Process the IOCtl.
    700702     */
    701     int rc = supdrvIOCtl(iCmd, &g_DevExt, pSession, pHdr);
     703    int rc = supdrvIOCtl(iCmd, &g_DevExt, pSession, pHdr, cbReq);
    702704    if (RT_LIKELY(!rc))
    703705    {
  • trunk/src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c

    r52192 r52575  
    411411            return rc;
    412412        }
     413        if (Hdr.cbIn < cbReq)
     414            RT_BZERO((uint8_t *)pHdr + Hdr.cbIn, cbReq - Hdr.cbIn)
    413415    }
    414416    else
     
    421423     * Process the IOCtl.
    422424     */
    423     int rc = supdrvIOCtl(ulCmd, &g_VBoxDrvFreeBSDDevExt, pSession, pHdr);
     425    int rc = supdrvIOCtl(ulCmd, &g_VBoxDrvFreeBSDDevExt, pSession, pHdr, cbReq);
    424426    if (RT_LIKELY(!rc))
    425427    {
  • trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c

    r52192 r52575  
    719719        return -E2BIG;
    720720    }
    721     if (RT_UNLIKELY(cbBuf != _IOC_SIZE(uCmd) && _IOC_SIZE(uCmd)))
     721    if (RT_UNLIKELY(_IOC_SIZE(uCmd) ? cbBuf != _IOC_SIZE(uCmd) : Hdr.cbIn < sizeof(Hdr)))
    722722    {
    723723        Log(("VBoxDrvLinuxIOCtl: bad ioctl cbBuf=%#x _IOC_SIZE=%#x; uCmd=%#x.\n", cbBuf, _IOC_SIZE(uCmd), uCmd));
     
    736736        return -EFAULT;
    737737    }
     738    if (Hdr.cbIn < cbBuf)
     739        RT_BZERO((uint8_t *)pHdr + Hdr.cbIn, cbBuf - Hdr.cbIn)
    738740
    739741    /*
    740742     * Process the IOCtl.
    741743     */
    742     rc = supdrvIOCtl(uCmd, &g_DevExt, pSession, pHdr);
     744    rc = supdrvIOCtl(uCmd, &g_DevExt, pSession, pHdr, cbBuf);
    743745
    744746    /*
  • trunk/src/VBox/HostDrivers/Support/os2/SUPDrv-os2.cpp

    r52192 r52575  
    335335                 * Process the IOCtl.
    336336                 */
    337                 rc = supdrvIOCtl(iFunction, &g_DevExt, pSession, pHdr);
     337                rc = supdrvIOCtl(iFunction, &g_DevExt, pSession, pHdr, cbReq);
    338338            }
    339339            else
  • trunk/src/VBox/HostDrivers/Support/solaris/SUPDrv-solaris.c

    r52553 r52575  
    816816     * Process the IOCtl.
    817817     */
    818     rc = supdrvIOCtl(iCmd, &g_DevExt, pSession, pHdr);
     818    rc = supdrvIOCtl(iCmd, &g_DevExt, pSession, pHdr, cbBuf);
    819819
    820820    /*
  • trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp

    r52529 r52575  
    10091009                         * Now call the common code to do the real work.
    10101010                         */
    1011                         rc = supdrvIOCtl(uCmd, pDevExt, pSession, pHdr);
     1011                        rc = supdrvIOCtl(uCmd, pDevExt, pSession, pHdr, cbBuf);
    10121012                        if (RT_SUCCESS(rc))
    10131013                        {
     
    11591159                &&  pStack->Parameters.DeviceIoControl.OutputBufferLength ==  pHdr->cbOut)
    11601160            {
     1161                /* Zero extra output bytes to make sure we don't leak anything. */
     1162                if (pHdr->cbIn < pHdr->cbOut)
     1163                    RtlZeroMemory((uint8_t *)pHdr + pHdr->cbIn, pHdr->cbOut - pHdr->cbIn);
     1164
    11611165                /*
    11621166                 * Do the job.
    11631167                 */
    1164                 rc = supdrvIOCtl(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
     1168                rc = supdrvIOCtl(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr,
     1169                                 RT_MAX(pHdr->cbIn, pHdr->cbOut));
    11651170                if (!rc)
    11661171                {
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