VirtualBox

Changeset 104159 in vbox


Ignore:
Timestamp:
Apr 4, 2024 3:35:39 PM (10 months ago)
Author:
vboxsync
Message:

VBoxNetFlt: Fix UBSAN warnings by switching to flexible arrays, bugref:10585.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/intnet.h

    r104045 r104159  
    356356    uint16_t            cSegsUsed;
    357357    /** Variable sized list of segments. */
    358     INTNETSEG           aSegs[1];
     358    RT_FLEXIBLE_ARRAY_EXTENSION
     359    INTNETSEG           aSegs[RT_FLEXIBLE_ARRAY];
    359360} INTNETSG;
    360361AssertCompileSizeAlignment(INTNETSG, 8);
  • trunk/src/VBox/Devices/Network/SrvIntNetR0.cpp

    r103025 r104159  
    41054105             */
    41064106            INTNETSWDECISION    enmSwDecision = INTNETSWDECISION_BROADCAST;
    4107             INTNETSG            Sg; /** @todo this will have to be changed if we're going to use async sending
    4108                                      * with buffer sharing for some OS or service. Darwin copies everything so
    4109                                      * I won't bother allocating and managing SGs right now. Sorry. */
     4107
     4108            /** @todo this will have to be changed if we're going to use async sending
     4109             * with buffer sharing for some OS or service. Darwin copies everything so
     4110             * I won't bother allocating and managing SGs right now. Sorry. */
     4111            union
     4112            {
     4113                uint8_t     abBuf[sizeof(INTNETSG) + sizeof(INTNETSEG)];
     4114                INTNETSG    SG;
     4115            } u;
     4116
    41104117            PINTNETHDR          pHdr;
    41114118            while ((pHdr = IntNetRingGetNextFrameToRead(&pIf->pIntBuf->Send)) != NULL)
     
    41164123                    /* Send regular frame. */
    41174124                    void *pvCurFrame = IntNetHdrGetFramePtr(pHdr, pIf->pIntBuf);
    4118                     IntNetSgInitTemp(&Sg, pvCurFrame, pHdr->cbFrame);
     4125                    IntNetSgInitTemp(&u.SG, pvCurFrame, pHdr->cbFrame);
    41194126                    if (pNetwork->fFlags & INTNET_OPEN_FLAGS_SHARED_MAC_ON_WIRE)
    4120                         intnetR0IfSnoopAddr(pIf, (uint8_t *)pvCurFrame, pHdr->cbFrame, false /*fGso*/, (uint16_t *)&Sg.fFlags);
    4121                     enmSwDecision = intnetR0NetworkSend(pNetwork, pIf,  0 /*fSrc*/, &Sg, pDstTab);
     4127                        intnetR0IfSnoopAddr(pIf, (uint8_t *)pvCurFrame, pHdr->cbFrame, false /*fGso*/, (uint16_t *)&u.SG.fFlags);
     4128                    enmSwDecision = intnetR0NetworkSend(pNetwork, pIf,  0 /*fSrc*/, &u.SG, pDstTab);
    41224129                }
    41234130                else if (u8Type == INTNETHDR_TYPE_GSO)
     
    41294136                    {
    41304137                        void       *pvCurFrame = pGso + 1;
    4131                         IntNetSgInitTempGso(&Sg, pvCurFrame, cbFrame, pGso);
     4138                        IntNetSgInitTempGso(&u.SG, pvCurFrame, cbFrame, pGso);
    41324139                        if (pNetwork->fFlags & INTNET_OPEN_FLAGS_SHARED_MAC_ON_WIRE)
    4133                             intnetR0IfSnoopAddr(pIf, (uint8_t *)pvCurFrame, cbFrame, true /*fGso*/, (uint16_t *)&Sg.fFlags);
    4134                         enmSwDecision = intnetR0NetworkSend(pNetwork, pIf, 0 /*fSrc*/, &Sg, pDstTab);
     4140                            intnetR0IfSnoopAddr(pIf, (uint8_t *)pvCurFrame, cbFrame, true /*fGso*/, (uint16_t *)&u.SG.fFlags);
     4141                        enmSwDecision = intnetR0NetworkSend(pNetwork, pIf, 0 /*fSrc*/, &u.SG, pDstTab);
    41354142                    }
    41364143                    else
  • trunk/src/VBox/Devices/Network/testcase/tstIntNetR0.cpp

    r98103 r104159  
    204204                            PSUPDRVSESSION pSession, void const *pvBuf, size_t cbBuf)
    205205{
    206     INTNETSG Sg;
    207     IntNetSgInitTemp(&Sg, (void *)pvBuf, (uint32_t)cbBuf);
    208     int rc = intnetR0RingWriteFrame(pRingBuf, &Sg, NULL);
     206    union
     207    {
     208        uint8_t abBuf[sizeof(INTNETSG) + sizeof(INTNETSEG)];
     209        INTNETSG SG;
     210    } u;
     211    IntNetSgInitTemp(&u.SG, (void *)pvBuf, (uint32_t)cbBuf);
     212    int rc = intnetR0RingWriteFrame(pRingBuf, &u.SG, NULL);
    209213    if (RT_SUCCESS(rc))
    210214        rc = IntNetR0IfSend(hIf, pSession);
     
    270274        pHdr->iFrame = iFrame;
    271275
    272         INTNETSG Sg;
    273         IntNetSgInitTemp(&Sg, abBuf, cb);
    274         RTTEST_CHECK_RC_OK(g_hTest, rc = intnetR0RingWriteFrame(&pArgs->pBuf->Send, &Sg, NULL));
     276        union
     277        {
     278            uint8_t abBuf[sizeof(INTNETSG) + sizeof(INTNETSEG)];
     279            INTNETSG SG;
     280        } u;
     281        IntNetSgInitTemp(&u.SG, abBuf, cb);
     282        RTTEST_CHECK_RC_OK(g_hTest, rc = intnetR0RingWriteFrame(&pArgs->pBuf->Send, &u.SG, NULL));
    275283        if (RT_SUCCESS(rc))
    276284            RTTEST_CHECK_RC_OK(g_hTest, rc = IntNetR0IfSend(pArgs->hIf, g_pSession));
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltRt-win.cpp

    r98103 r104159  
    11421142     * 2. buffer of cbPacket containing the entire packet */
    11431143    AssertCompileSizeAlignment(INTNETSG, sizeof(PVOID));
    1144     Status = vboxNetFltWinMemAlloc((PVOID*)&pSG, cbPacket + sizeof(INTNETSG));
     1144    Status = vboxNetFltWinMemAlloc((PVOID*)&pSG, cbPacket + RT_UOFFSETOF_DYN(INTNETSG, aSegs[1]));
    11451145    if (Status == NDIS_STATUS_SUCCESS)
    11461146    {
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