VirtualBox

Changeset 58055 in vbox for trunk/src/VBox/VMM/VMMR3


Ignore:
Timestamp:
Oct 6, 2015 3:01:30 PM (9 years ago)
Author:
vboxsync
Message:

VMM/GIM: Filter out 'bad' packets (DHCP BOOTP, NETBIOS etc.) over the Hyper-V debug transport link and send only UDP packets intended for the debugger.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/GIMHv.cpp

    r58014 r58055  
    10581058            if (cbWrite > sizeof(RTNETETHERHDR))
    10591059            {
    1060                 PRTNETETHERHDR pEtherHdr = (PRTNETETHERHDR)pbData;
    1061                 if (pEtherHdr->EtherType != RT_H2N_U16_C(RTNET_ETHERTYPE_IPV4))
    1062                     fIgnorePacket = true;       /* Supress passing ARP and other non IPv4 frames to debugger. */
    1063                 else if (cbWrite > sizeof(RTNETETHERHDR) + RTNETIPV4_MIN_LEN + RTNETUDP_MIN_LEN)
     1060                PCRTNETETHERHDR pEtherHdr = (PCRTNETETHERHDR)pbData;
     1061                if (pEtherHdr->EtherType == RT_H2N_U16_C(RTNET_ETHERTYPE_IPV4))
    10641062                {
    1065                     /* Extract UDP payload, recording the guest IP address to pass to the debugger. */
    1066                     PRTNETIPV4 pIp4Hdr = (PRTNETIPV4)(pbData + sizeof(RTNETETHERHDR));
    1067                     if (   pIp4Hdr->ip_v == 4
    1068                         && pIp4Hdr->ip_p == RTNETIPV4_PROT_UDP)
     1063                    if (cbWrite > sizeof(RTNETETHERHDR) + RTNETIPV4_MIN_LEN + RTNETUDP_MIN_LEN)
    10691064                    {
    1070                         pHv->DbgGuestAddr = pIp4Hdr->ip_src;
    1071                         pbData += sizeof(RTNETETHERHDR) + RTNETIPV4_MIN_LEN + RTNETUDP_MIN_LEN;
    1072                         cbWrite -= sizeof(RTNETETHERHDR) + RTNETIPV4_MIN_LEN + RTNETUDP_MIN_LEN;
     1065                        size_t const cbMaxIpHdr = cbWrite - sizeof(RTNETETHERHDR) - sizeof(RTNETUDP) - 1;
     1066                        size_t const cbMaxIpPkt = cbWrite - sizeof(RTNETETHERHDR);
     1067                        PCRTNETIPV4  pIp4Hdr    = (PCRTNETIPV4)(pbData + sizeof(RTNETETHERHDR));
     1068                        bool const   fValidIp4  = RTNetIPv4IsHdrValid(pIp4Hdr, cbMaxIpHdr, cbMaxIpPkt, false /*fChecksum*/);
     1069                        if (   fValidIp4
     1070                            && pIp4Hdr->ip_p == RTNETIPV4_PROT_UDP)
     1071                        {
     1072                            size_t const cbIpHdr     = pIp4Hdr->ip_hl * 4;
     1073                            size_t const cbMaxUdpPkt = cbWrite - sizeof(RTNETETHERHDR) - cbIpHdr;
     1074                            PCRTNETUDP pUdpHdr       = (PCRTNETUDP)((uint8_t *)pIp4Hdr + cbIpHdr);
     1075                            if (   pUdpHdr->uh_ulen > RT_H2N_U16(sizeof(RTNETUDP))
     1076                                && pUdpHdr->uh_ulen <= RT_H2N_U16(cbMaxUdpPkt))
     1077                            {
     1078                                /*
     1079                                 * Extract the UDP payload and pass it to the debugger and record the guest IP address.
     1080                                 * Hyper-V sends UDP debugger packets with source and destination port as 0. If we don't
     1081                                 * filter out the ports here, we would receive BOOTP, NETBIOS and other UDP sub-protocol
     1082                                 * packets which the debugger yells as "Bad packet received from...".
     1083                                 */
     1084                                if (   !pUdpHdr->uh_dport
     1085                                    && !pUdpHdr->uh_sport)
     1086                                {
     1087                                    size_t const cbFrameHdr = sizeof(RTNETETHERHDR) + cbIpHdr + sizeof(RTNETUDP);
     1088                                    pbData  += cbFrameHdr;
     1089                                    cbWrite -= cbFrameHdr;
     1090                                    pHv->DbgGuestAddr = pIp4Hdr->ip_src;
     1091                                }
     1092                                else
     1093                                {
     1094                                    LogFlow(("GIM: HyperV: Ignoring UDP packet not src and dst port 0\n"));
     1095                                    fIgnorePacket = true;
     1096                                }
     1097                            }
     1098                            else
     1099                            {
     1100                                LogFlow(("GIM: HyperV: Ignoring malformed UDP packet. cbMaxUdpPkt=%u UdpPkt.len=%u\n",
     1101                                         cbMaxUdpPkt, RT_N2H_U16(pUdpHdr->uh_ulen)));
     1102                                fIgnorePacket = true;
     1103                            }
     1104                        }
     1105                        else
     1106                        {
     1107                            LogFlow(("GIM: HyperV: Ignoring non-IP / non-UDP packet. fValidIp4=%RTBool Proto=%u\n", fValidIp4,
     1108                                      pIp4Hdr->ip_p));
     1109                            fIgnorePacket = true;
     1110                        }
    10731111                    }
    10741112                    else
    1075                         fIgnorePacket = true;   /* Supress passing non-UDP packets to the debugger. */
     1113                    {
     1114                        LogFlow(("GIM: HyperV: Ignoring IPv4 packet; too short to be valid UDP. cbWrite=%u\n", cbWrite));
     1115                        fIgnorePacket = true;
     1116                    }
     1117                }
     1118                else
     1119                {
     1120                    LogFlow(("GIM: HyperV: Ignoring non-IP packet. Ethertype=%#x\n", RT_N2H_U16(pEtherHdr->EtherType)));
     1121                    fIgnorePacket = true;
    10761122                }
    10771123            }
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