VirtualBox

Changeset 102064 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 10, 2023 2:15:11 PM (15 months ago)
Author:
vboxsync
Message:

Additions: X11/Wayland: vboxwl/VBoxClient IPC: Prevent partial reads from IPC socket, bugref:10194.

Do not specify pcbRead parameter to RTLocalIpcSessionRead, so it will attempt to read
entire buffer from IPC socket. This commit also fixes issue when vboxwl was not able to
receive large buffer from VBoxClient.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/wayland-helper-ipc.cpp

    r101878 r102064  
    153153
    154154    vbcl::ipc::packet_t Packet;
    155     size_t cbRead;
    156155
    157156    AssertPtrReturn(ppvData, VERR_INVALID_PARAMETER);
     
    161160    {
    162161        /* Read IPC message header. */
    163         rc = RTLocalIpcSessionRead(hSession, &Packet, sizeof(Packet), &cbRead);
     162        rc = RTLocalIpcSessionRead(hSession, &Packet, sizeof(Packet), NULL);
    164163        if (RT_SUCCESS(rc))
    165164        {
    166             if (cbRead == sizeof(Packet))
    167             {
    168                 bool fCheck = true;
     165            bool fCheck = true;
    169166
    170167#define _CHECK(_cond, _msg, _ptr) \
     
    176173    }
    177174
    178                 _CHECK(Packet.u64Crc > 0,                   "bad crc: 0x%x", Packet.u64Crc);
    179                 _CHECK(Packet.uSessionId == uSessionId,     "bad session id: %u vs %u", (Packet.uSessionId, uSessionId));
    180                 _CHECK(Packet.cbData > sizeof(Packet),      "bad cbData: %u", Packet.cbData);
    181 
    182                 /* Receive the rest of a message. */
    183                 if (fCheck)
     175            _CHECK(Packet.u64Crc > 0,                   "bad crc: 0x%x", Packet.u64Crc);
     176            _CHECK(Packet.uSessionId == uSessionId,     "bad session id: %u vs %u", (Packet.uSessionId, uSessionId));
     177            _CHECK(Packet.cbData > sizeof(Packet),      "bad cbData: %u", Packet.cbData);
     178
     179            /* Receive the rest of a message. */
     180            if (fCheck)
     181            {
     182                uint8_t *puData;
     183
     184                puData = (uint8_t *)RTMemAllocZ(Packet.cbData);
     185                if (RT_VALID_PTR(puData))
    184186                {
    185                     uint8_t *puData;
    186 
    187                     puData = (uint8_t *)RTMemAllocZ(Packet.cbData);
    188                     if (RT_VALID_PTR(puData))
     187                    /* Add generic header to the beginning of the output buffer
     188                     * and receive the rest of the data into it. */
     189                    memcpy(puData, &Packet, sizeof(Packet));
     190
     191                    rc = RTLocalIpcSessionRead(hSession, puData + sizeof(Packet),
     192                                               Packet.cbData - sizeof(Packet), NULL);
     193                    if (RT_SUCCESS(rc))
    189194                    {
    190                         /* Add generic header to the beginning of the output buffer
    191                          * and receive the rest of the data into it. */
    192                         memcpy(puData, &Packet, sizeof(Packet));
    193 
    194                         rc = RTLocalIpcSessionRead(hSession, puData + sizeof(Packet),
    195                                                    Packet.cbData - sizeof(Packet), &cbRead);
    196                         if (RT_SUCCESS(rc))
     195                        if (vbcl::ipc::packet_verify((vbcl::ipc::packet_t *)puData, Packet.cbData))
    197196                        {
    198                             if (cbRead == (Packet.cbData - sizeof(Packet)))
    199                             {
    200                                 if (vbcl::ipc::packet_verify((vbcl::ipc::packet_t *)puData, Packet.cbData))
    201                                 {
    202                                     /* Now return received data to the caller. */
    203                                     *ppvData = puData;
    204                                 }
    205                                 else
    206                                     rc = VERR_NOT_EQUAL;
    207                             }
    208                             else
    209                                 rc = VERR_BUFFER_UNDERFLOW;
     197                            /* Now return received data to the caller. */
     198                            *ppvData = puData;
    210199                        }
    211 
    212                         if (RT_FAILURE(rc))
    213                             RTMemFree(puData);
     200                        else
     201                            rc = VERR_NOT_EQUAL;
    214202                    }
    215                     else
    216                         rc = VERR_NO_MEMORY;
     203
     204                    if (RT_FAILURE(rc))
     205                        RTMemFree(puData);
    217206                }
    218207                else
    219                     rc = VERR_INVALID_PARAMETER;
     208                    rc = VERR_NO_MEMORY;
    220209            }
     210            else
     211                rc = VERR_INVALID_PARAMETER;
    221212
    222213            if (RT_FAILURE(rc))
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