VirtualBox

Changeset 19091 in vbox


Ignore:
Timestamp:
Apr 21, 2009 8:57:38 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
46239
Message:

Additions/common and linux: don'\t try to lock zero-length buffers when we do HGCM copies

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

Legend:

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

    r15606 r19091  
    3636    int rc = VINF_SUCCESS;
    3737
     38    /* Ugly edge case - zero size buffers shouldn't be locked. */
     39    if (u32Size == 0)
     40    {
     41        *ppvCtx = NIL_RTR0MEMOBJ;
     42        return VINF_SUCCESS;
     43    }
    3844#ifdef RT_OS_WINDOWS
    3945    PMDL pMdl = IoAllocateMdl (pv, u32Size, FALSE, FALSE, NULL);
     
    6874    /** @todo r=frank: Linux: pv is at least in some cases, e.g. with VBoxMapFolder,
    6975     *  an R0 address -- the memory was allocated with kmalloc(). I don't know
    70      *  if this is true in any case. */
     76     *  if this is true in any case.
     77     * r=michael: on Linux, we sometimes have R3 addresses (e.g. shared
     78     *  clipboard) and sometimes R0 (e.g. shared folders).  We really ought
     79     *  to have two separate paths here - at any rate, Linux R0 shouldn't
     80     *  end up calling this API.  In practice, Linux R3 does it's own thing
     81     *  before winding up in the R0 path - which calls this stub API.
     82     */
    7183    NOREF(ppvCtx);
    7284    NOREF(pv);
     
    92104    NOREF(u32Size);
    93105
     106    /* Ugly edge case - zero size buffers aren't be locked. */
     107    if (pvCtx == NIL_RTR0MEMOBJ)
     108        return;
    94109#ifdef RT_OS_WINDOWS
    95110    PMDL pMdl = (PMDL)pvCtx;
  • trunk/src/VBox/Additions/linux/module/vboxmod.c

    r18361 r19091  
    442442
    443443    AssertPtrReturn(ppBuf, -EINVAL);
    444     AssertPtrReturn(pUser, -EINVAL);
    445444
    446445    pBuf = RTMemAlloc(sizeof(*pBuf));
     
    449448    if (rc >= 0)
    450449    {
    451         pKernel = RTMemAlloc(cb);
    452         if (pKernel == NULL)
    453             rc = -ENOMEM;
    454     }
    455     if (   rc >= 0
    456         && copy
    457         && copy_from_user(pKernel, pUser, cb) != 0)
    458         rc = -EFAULT;
     450        if (cb > 0)
     451        {
     452            pKernel = RTMemAlloc(cb);
     453            if (pKernel == NULL)
     454                rc = -ENOMEM;
     455            if (   rc >= 0
     456                && copy
     457                && copy_from_user(pKernel, pUser, cb) != 0)
     458                rc = -EFAULT;
     459        }
     460        else
     461            /* Empty buffers are allowed, but then the user pointer is not
     462             * required to be valid, and we definitely don't want to copy
     463             * anything. */
     464            pKernel = NULL;
     465    }
    459466    if (rc >= 0)
    460467    {
     
    478485    int rc = 0;
    479486    AssertPtrReturn(pBuf, -EINVAL);
    480     if (copy && copy_to_user(pBuf->pUser, pBuf->pKernel, pBuf->cb) != 0)
     487    if ((pBuf->cb > 0)
     488        && copy
     489        && copy_to_user(pBuf->pUser, pBuf->pKernel, pBuf->cb) != 0)
    481490        rc = -EFAULT;
    482491    RTMemFree(pBuf->pKernel);  /* We want to do this whatever the outcome. */
Note: See TracChangeset for help on using the changeset viewer.

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