VirtualBox

Changeset 23293 in vbox for trunk/src/VBox/HostDrivers


Ignore:
Timestamp:
Sep 24, 2009 4:23:43 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
52786
Message:

Solaris/VBoxNetFlt: moved global lock to bracket insert/remove ioctls and kcred checking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFlt-solaris.c

    r23281 r23293  
    377377static RTSEMFASTMUTEX g_VBoxNetFltSolarisMtx = NIL_RTSEMFASTMUTEX;
    378378
     379/** Global credentials using during open/close. */
     380static cred_t *g_pVBoxNetFltSolarisCred = NULL;
     381
    379382/**
    380383 * g_VBoxNetFltInstance is the current PVBOXNETFLTINS to be associated with the stream being created
     
    520523            {
    521524                g_pVBoxNetFltSolarisDip = pDip;
    522 
    523                 /*
    524                  * Get the user prop. for polling interval.
    525                  */
    526                 int Interval = ddi_getprop(DDI_DEV_T_ANY, pDip, DDI_PROP_DONTPASS, VBOXNETFLT_IP6POLLINTERVAL, -1 /* default */);
    527                 if (Interval == -1)
    528                     LogFlow((DEVICE_NAME ":vboxNetFltSolarisSetupIp6Polling: no poll interval property specified. Skipping Ipv6 polling.\n"));
    529                 else if (Interval < 1 || Interval > 120)
     525                g_pVBoxNetFltSolarisCred = crdup(kcred);
     526                if (RT_LIKELY(g_pVBoxNetFltSolarisCred))
    530527                {
    531                     LogRel((DEVICE_NAME ":vboxNetFltSolarisSetupIp6Polling: Invalid polling interval %d. Expected between 1 and 120 secs.\n",
    532                                         Interval));
    533                     Interval = -1;
     528                    /*
     529                     * Get the user prop. for polling interval.
     530                     */
     531                    int Interval = ddi_getprop(DDI_DEV_T_ANY, pDip, DDI_PROP_DONTPASS, VBOXNETFLT_IP6POLLINTERVAL, -1 /* default */);
     532                    if (Interval == -1)
     533                        LogFlow((DEVICE_NAME ":vboxNetFltSolarisSetupIp6Polling: no poll interval property specified. Skipping Ipv6 polling.\n"));
     534                    else if (Interval < 1 || Interval > 120)
     535                    {
     536                        LogRel((DEVICE_NAME ":vboxNetFltSolarisSetupIp6Polling: Invalid polling interval %d. Expected between 1 and 120 secs.\n",
     537                                            Interval));
     538                        Interval = -1;
     539                    }
     540
     541                    g_VBoxNetFltSolarisPollInterval = Interval;
     542                    ddi_report_dev(pDip);
     543                    return DDI_SUCCESS;
    534544                }
    535 
    536                 g_VBoxNetFltSolarisPollInterval = Interval;
    537                 ddi_report_dev(pDip);
    538                 return DDI_SUCCESS;
     545                else
     546                    LogRel((DEVICE_NAME ":failed to alloc credentials.\n"));
    539547            }
    540548            else
     
    570578        {
    571579            int instance = ddi_get_instance(pDip);
     580            if (g_pVBoxNetFltSolarisCred)
     581            {
     582                crfree(g_pVBoxNetFltSolarisCred);
     583                g_pVBoxNetFltSolarisCred = NULL;
     584            }
    572585            ddi_remove_minor_node(pDip, NULL);
    573586            return DDI_SUCCESS;
     
    637650            fOpenMode, fStreamMode));
    638651
    639     int rc = RTSemFastMutexRequest(g_VBoxNetFltSolarisMtx);
    640     AssertRCReturn(rc, rc);
    641 
    642652    /*
    643653     * Already open?
     
    646656    {
    647657        LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen invalid open.\n"));
    648         RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    649658        return ENOENT;
     659    }
     660
     661    /*
     662     * Check kernel credentials.
     663     * Protects us to a minor degree, is someone uses kcred besides us, this check is not sufficient.
     664     */
     665    if (pCred != g_pVBoxNetFltSolarisCred)
     666    {
     667        LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen invalid credentials.\n"));
     668        return EACCES;
    650669    }
    651670
     
    657676    {
    658677        LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed to get VirtualBox instance.\n"));
    659         RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    660678        return ENOENT;
    661679    }
     
    670688    {
    671689        LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed due to undefined VirtualBox open mode. Type=%d\n", g_VBoxNetFltSolarisStreamType));
    672         RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    673690        return ENOENT;
    674691    }
     
    699716        {
    700717            LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed to allocate promiscuous stream data.\n"));
    701             RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    702718            return ENOMEM;
    703719        }
     
    723739        {
    724740            LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed to allocate stream data.\n"));
    725             RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    726741            return ENOMEM;
    727742        }
     
    746761            LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen huh!? Invalid stream type %d\n", pStream->Type));
    747762            RTMemFree(pStream);
    748             RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    749763            return EINVAL;
    750764        }
     
    764778     */
    765779    vboxNetFltRetain(pThis, false /* fBusy */);
    766 
    767     /*
    768      * Release global lock, & do not hold locks across putnext calls.
    769      */
    770     RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    771780
    772781    qprocson(pQueue);
     
    815824
    816825    NOREF(fOpenMode);
    817     NOREF(pCred);
    818826
    819827    LogFlow((DEVICE_NAME ":VBoxNetFltSolarisModOpen returns 0, DevMinor=%d pQueue=%p\n", DevMinor, pStream->pReadQueue));
     
    838846    LogFlow((DEVICE_NAME ":VBoxNetFltSolarisModClose pQueue=%p fOpenMode=%d\n", pQueue, fOpenMode));
    839847
    840     int rc = RTSemFastMutexRequest(g_VBoxNetFltSolarisMtx);
    841     AssertRCReturn(rc, rc);
    842 
    843848    vboxnetflt_stream_t *pStream = NULL;
    844849    vboxnetflt_stream_t **ppPrevStream = NULL;
     
    851856    {
    852857        LogRel((DEVICE_NAME ":VBoxNetFltSolarisModClose failed to get stream.\n"));
    853         RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    854858        return ENXIO;
    855859    }
     
    934938    NOREF(fOpenMode);
    935939    NOREF(pCred);
    936 
    937     RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    938940
    939941    return 0;
     
    18981900        if (!ret)
    18991901        {
     1902            rc = RTSemFastMutexRequest(g_VBoxNetFltSolarisMtx);
     1903            AssertRCReturn(rc, rc);
     1904
    19001905            g_VBoxNetFltSolarisInstance = pThis;
    19011906            g_VBoxNetFltSolarisStreamType = kPromiscStream;
    19021907
    1903             rc = ldi_ioctl(pThis->u.s.hIface, I_PUSH, (intptr_t)DEVICE_NAME, FKIOCTL, kcred, &ret);
     1908            rc = ldi_ioctl(pThis->u.s.hIface, I_PUSH, (intptr_t)DEVICE_NAME, FKIOCTL, g_pVBoxNetFltSolarisCred, &ret);
    19041909
    19051910            g_VBoxNetFltSolarisInstance = NULL;
    19061911            g_VBoxNetFltSolarisStreamType = kUndefined;
     1912
     1913            RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    19071914
    19081915            if (!rc)
     
    20642071                                 * of the inability to pass user data while inserting.
    20652072                                 */
    2066                                 g_VBoxNetFltSolarisInstance = pThis;
    2067                                 g_VBoxNetFltSolarisStreamType = kIp4Stream;
     2073                                rc = RTSemFastMutexRequest(g_VBoxNetFltSolarisMtx);
     2074                                AssertRCReturn(rc, rc);
     2075                               
     2076                                if (fAttach)
     2077                                {
     2078                                    g_VBoxNetFltSolarisInstance = pThis;
     2079                                    g_VBoxNetFltSolarisStreamType = kIp4Stream;
     2080                                }
    20682081
    20692082                                rc = strioctl(pIp4VNode, fAttach ? _I_INSERT : _I_REMOVE, (intptr_t)&StrMod, 0, K_TO_K,
    2070                                             kcred, &ret);
    2071 
    2072                                 g_VBoxNetFltSolarisInstance = NULL;
    2073                                 g_VBoxNetFltSolarisStreamType = kUndefined;
     2083                                            g_pVBoxNetFltSolarisCred, &ret);
     2084
     2085                                if (fAttach)
     2086                                {
     2087                                    g_VBoxNetFltSolarisInstance = NULL;
     2088                                    g_VBoxNetFltSolarisStreamType = kUndefined;
     2089                                }
     2090
     2091                                RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    20742092
    20752093                                if (!rc)
     
    20782096                                     * Inject/Eject from the host ARP stack.
    20792097                                     */
    2080                                     g_VBoxNetFltSolarisInstance = pThis;
    2081                                     g_VBoxNetFltSolarisStreamType = kArpStream;
     2098                                    rc = RTSemFastMutexRequest(g_VBoxNetFltSolarisMtx);
     2099                                    AssertRCReturn(rc, rc);
     2100
     2101                                    if (fAttach)
     2102                                    {
     2103                                        g_VBoxNetFltSolarisInstance = pThis;
     2104                                        g_VBoxNetFltSolarisStreamType = kArpStream;
     2105                                    }
    20822106
    20832107                                    rc = strioctl(pArpVNode, fAttach ? _I_INSERT : _I_REMOVE, (intptr_t)&ArpStrMod, 0, K_TO_K,
    2084                                                 kcred, &ret);
    2085 
    2086                                     g_VBoxNetFltSolarisInstance = NULL;
    2087                                     g_VBoxNetFltSolarisStreamType = kUndefined;
     2108                                                g_pVBoxNetFltSolarisCred, &ret);
     2109
     2110                                    if (fAttach)
     2111                                    {
     2112                                        g_VBoxNetFltSolarisInstance = NULL;
     2113                                        g_VBoxNetFltSolarisStreamType = kUndefined;
     2114                                    }
     2115
     2116                                    RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
    20882117
    20892118                                    if (!rc)
     
    22842313                                 * of the inability to pass user data while inserting.
    22852314                                 */
    2286                                 g_VBoxNetFltSolarisInstance = pThis;
    2287                                 g_VBoxNetFltSolarisStreamType = kIp6Stream;
     2315                                rc = RTSemFastMutexRequest(g_VBoxNetFltSolarisMtx);
     2316                                AssertRCReturn(rc, rc);
     2317
     2318                                if (fAttach)
     2319                                {
     2320                                    g_VBoxNetFltSolarisInstance = pThis;
     2321                                    g_VBoxNetFltSolarisStreamType = kIp6Stream;
     2322                                }
    22882323
    22892324                                /*
     
    22912326                                 */
    22922327                                rc = strioctl(pIp6VNode, fAttach ? _I_INSERT : _I_REMOVE, (intptr_t)&StrMod, 0, K_TO_K,
    2293                                             kcred, &ret);
    2294                                 if (!rc)
     2328                                            g_pVBoxNetFltSolarisCred, &ret);
     2329
     2330                                if (fAttach)
    22952331                                {
    22962332                                    g_VBoxNetFltSolarisInstance = NULL;
    22972333                                    g_VBoxNetFltSolarisStreamType = kUndefined;
    2298 
     2334                                }
     2335
     2336                                RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
     2337
     2338                                if (!rc)
     2339                                {
    22992340                                    /*
    23002341                                     * Our job's not yet over; we need to relink the upper and lower streams
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