VirtualBox

Ignore:
Timestamp:
Jul 5, 2024 2:26:46 PM (7 months ago)
Author:
vboxsync
Message:

Linux/Network: Do not attach netfilter to wrong names or multiple times, bugref:10713

Location:
trunk/src/VBox/HostDrivers/VBoxNetFlt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h

    r99828 r105163  
    203203            struct work_struct    XmitTask;
    204204#  endif
     205            /** Unique identifier of network namespace of device to attach to. */
     206            uint32_t uNamespaceInode;
    205207            /** @} */
    206208# elif defined(RT_OS_SOLARIS)
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c

    r104927 r105163  
    4747#if RTLNX_VER_MIN(2,6,24)
    4848# include <linux/nsproxy.h>
     49#endif
     50#if RTLNX_VER_MIN(3,10,0) /* proc_ns introduced */
     51# define VBOXNETFLT_LINUX_NAMESPACE_SUPPORT
     52# include <linux/proc_ns.h>
    4953#endif
    5054#if RTLNX_VER_MIN(6,4,10) || RTLNX_RHEL_RANGE(9,4, 9,99) || RTLNX_SUSE_MAJ_PREREQ(15, 6)
     
    18421846static int vboxNetFltLinuxAttachToInterface(PVBOXNETFLTINS pThis, struct net_device *pDev)
    18431847{
     1848    bool fAlreadyAttached = false;
    18441849    LogFlow(("vboxNetFltLinuxAttachToInterface: pThis=%p (%s)\n", pThis, pThis->szName));
    18451850
     
    18501855
    18511856    RTSpinlockAcquire(pThis->hSpinlock);
    1852     ASMAtomicUoWritePtr(&pThis->u.s.pDev, pDev);
     1857    if (ASMAtomicUoReadPtrT(&pThis->u.s.pDev, struct net_device *))
     1858        fAlreadyAttached = true;    /* Do not attach multiple times! */
     1859    else
     1860        ASMAtomicUoWritePtr(&pThis->u.s.pDev, pDev);
    18531861    RTSpinlockRelease(pThis->hSpinlock);
     1862
     1863    if (fAlreadyAttached)
     1864    {
     1865        dev_put(pDev);
     1866        Log(("vboxNetFltLinuxAttachToInterface: Not attaching to %p(%s), already attached to %p(%s).\n",
     1867             pDev, pDev->name, pThis->u.s.pDev, pThis->u.s.pDev->name));
     1868        return VINF_ALREADY_INITIALIZED;
     1869    }
    18541870
    18551871    Log(("vboxNetFltLinuxAttachToInterface: Device %p(%s) retained. ref=%d\n",
     
    20632079    if (ulEventType == NETDEV_REGISTER)
    20642080    {
     2081#ifdef VBOXNETFLT_LINUX_NAMESPACE_SUPPORT
     2082# if RTLNX_VER_MIN(3,19,0) /* ns_common introduced */
     2083#  define VBOX_DEV_NET_NS_INUM(dev) dev_net(dev)->ns.inum
     2084# else
     2085#  define VBOX_DEV_NET_NS_INUM(dev) dev_net(dev)->proc_inum
     2086# endif
     2087        if (pThis->u.s.uNamespaceInode == 0 || pThis->u.s.uNamespaceInode == VBOX_DEV_NET_NS_INUM(pDev))
     2088        {
     2089            /* Skip namespace if it is present */
     2090            const char *pcszIfName = strchr(pThis->szName, '/');
     2091            if (pcszIfName)
     2092                ++pcszIfName;
     2093            else
     2094                pcszIfName = pThis->szName;
     2095            if (strcmp(pDev->name, pcszIfName) == 0)
     2096                vboxNetFltLinuxAttachToInterface(pThis, pDev);
     2097            else
     2098                Log(("VBoxNetFlt: not attaching to '%s' as it does not match '%s'\n", pDev->name, pcszIfName));
     2099        }
     2100        else
     2101            Log(("VBoxNetFlt: ignoring '%s' in wrong namespace (%u, expected %u)\n", pDev->name,
     2102                 VBOX_DEV_NET_NS_INUM(pDev), pThis->u.s.uNamespaceInode));
     2103#else /* !VBOXNETFLT_LINUX_NAMESPACE_SUPPORT */
    20652104#if RTLNX_VER_MIN(2,6,24) /* cgroups/namespaces introduced */
    20662105# if RTLNX_VER_MIN(2,6,26)
     
    20822121            }
    20832122        }
     2123#endif /* !VBOXNETFLT_LINUX_NAMESPACE_SUPPORT */
    20842124    }
    20852125    else
     
    25802620    pThis->u.s.fPacketHandler  = false;
    25812621    memset(&pThis->u.s.PacketType, 0, sizeof(pThis->u.s.PacketType));
     2622#ifdef VBOXNETFLT_LINUX_NAMESPACE_SUPPORT
     2623    /* We should get the interface name in the form <namespace>/<ifname>, parse it. */
     2624    pThis->u.s.uNamespaceInode = RTStrToUInt32(pThis->szName);
     2625#else /* !VBOXNETFLT_LINUX_NAMESPACE_SUPPORT */
     2626    pThis->u.s.uNamespaceInode = 0;
     2627#endif /* !VBOXNETFLT_LINUX_NAMESPACE_SUPPORT */
    25822628#ifndef VBOXNETFLT_LINUX_NO_XMIT_QUEUE
    25832629    skb_queue_head_init(&pThis->u.s.XmitQueue);
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