Check get packet template allocation failure (VPP-1321) 31/13131/3
authorJohn Lo <loj@cisco.com>
Tue, 19 Jun 2018 19:27:48 +0000 (15:27 -0400)
committerDave Barach <openvpp@barachs.net>
Tue, 19 Jun 2018 21:26:10 +0000 (21:26 +0000)
After calling vlib_packet_template_get_packet(), make sure
packet buffer is allocated before using it.

Change-Id: Idb5199f4e2c9596137b2101e502d611f474a6ffe
Signed-off-by: John Lo <loj@cisco.com>
src/plugins/cdp/cdp_periodic.c
src/vnet/ethernet/arp.c
src/vnet/ip/ip4_forward.c
src/vnet/ip/ip6_forward.c
src/vnet/ip/ip6_neighbor.c

index c67af00..a4c4bb9 100644 (file)
@@ -195,6 +195,9 @@ send_hdlc_hello (cdp_main_t * cm, cdp_neighbor_t * n, int count)
       h0 = vlib_packet_template_get_packet
        (vm, &cm->packet_templates[n->packet_template_index], &bi0);
 
+      if (!h0)
+       break;
+
       hw = vnet_get_sup_hw_interface (vnm, n->sw_if_index);
 
       t0 = (u8 *) & h0->cdp.data;
@@ -251,6 +254,9 @@ send_srp_hello (cdp_main_t * cm, cdp_neighbor_t * n, int count)
       h0 = vlib_packet_template_get_packet
        (vm, &cm->packet_templates[n->packet_template_index], &bi0);
 
+      if (!h0)
+       break;
+
       hw = vnet_get_sup_hw_interface (vnm, n->sw_if_index);
 
       t0 = (u8 *) & h0->cdp.data;
index 37e3e88..a17f7da 100644 (file)
@@ -352,6 +352,8 @@ arp_nbr_probe (ip_adjacency_t * adj)
   h =
     vlib_packet_template_get_packet (vm, &im->ip4_arp_request_packet_template,
                                     &bi);
+  if (!h)
+    return;
 
   hi = vnet_get_sup_hw_interface (vnm, adj->rewrite_header.sw_if_index);
 
@@ -2579,6 +2581,10 @@ send_ip4_garp_w_addr (vlib_main_t * vm,
       u32 bi = 0;
       ethernet_arp_header_t *h = vlib_packet_template_get_packet
        (vm, &i4m->ip4_arp_request_packet_template, &bi);
+
+      if (!h)
+       return;
+
       clib_memcpy (h->ip4_over_ethernet[0].ethernet, hi->hw_address,
                   sizeof (h->ip4_over_ethernet[0].ethernet));
       clib_memcpy (h->ip4_over_ethernet[1].ethernet, hi->hw_address,
index 0035cc8..677f88c 100644 (file)
@@ -1960,6 +1960,9 @@ ip4_probe_neighbor (vlib_main_t * vm, ip4_address_t * dst, u32 sw_if_index,
                                       &im->ip4_arp_request_packet_template,
                                       &bi);
 
+  if (!h)
+    return clib_error_return (0, "ARP request packet allocation failed");
+
   hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
   if (PREDICT_FALSE (!hi->hw_address))
     {
index 5ea7d8d..cf1011f 100644 (file)
@@ -1476,6 +1476,8 @@ ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index,
     vlib_packet_template_get_packet (vm,
                                     &im->discover_neighbor_packet_template,
                                     &bi);
+  if (!h)
+    return clib_error_return (0, "ICMP6 NS packet allocation failed");
 
   hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
 
index e281d7e..6d91224 100644 (file)
@@ -466,6 +466,8 @@ ip6_nbr_probe (ip_adjacency_t * adj)
   h = vlib_packet_template_get_packet (vm,
                                       &im->discover_neighbor_packet_template,
                                       &bi);
+  if (!h)
+    return;
 
   hi = vnet_get_sup_hw_interface (vnm, adj->rewrite_header.sw_if_index);
 
@@ -3285,6 +3287,8 @@ ip6_discover_neighbor_inline (vlib_main_t * vm,
 
            h0 = vlib_packet_template_get_packet
              (vm, &im->discover_neighbor_packet_template, &bi0);
+           if (!h0)
+             continue;
 
            /*
             * Build ethernet header.
@@ -5037,6 +5041,9 @@ send_ip6_na_w_addr (vlib_main_t * vm,
        vlib_packet_template_get_packet (vm,
                                         &i6m->discover_neighbor_packet_template,
                                         &bi);
+      if (!h)
+       return;
+
       ip6_set_reserved_multicast_address (&h->ip.dst_address,
                                          IP6_MULTICAST_SCOPE_link_local,
                                          IP6_MULTICAST_GROUP_ID_all_hosts);