Blob Blame History Raw
From b59b64c0be5f16791c77d1b0104f09fd424ac098 Mon Sep 17 00:00:00 2001
Message-Id: <b59b64c0be5f16791c77d1b0104f09fd424ac098.1578588395.git.lorenzo.bianconi@redhat.com>
In-Reply-To: <600a018ea1136e184b421c86da170b35d05e949f.1578588395.git.lorenzo.bianconi@redhat.com>
References: <600a018ea1136e184b421c86da170b35d05e949f.1578588395.git.lorenzo.bianconi@redhat.com>
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Date: Tue, 7 Jan 2020 17:50:05 +0100
Subject: [PATCH 2/3] DNSSL: copy dnssl string in order to avoid truncated
 value

ipv6_ra_send can run 2 times in a row before prepare_ipv6_ras updates
the dnss list. Copy the dnss dynamic string in packet_put_ra_dnssl_opt
in order to avoid sending truncated dnssl list on the wire.
Moreover move ip6_hdr definition just before accessing it because the
packet can be reallocated if the data area is not big enough for packet
content

Fixes: 5a12a940f ("Add DNSSL support to OVN")
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Numan Siddique <numans@ovn.org>
---
 ovn/controller/pinctrl.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/ovn/controller/pinctrl.c b/ovn/controller/pinctrl.c
index 04ccb25a8..43b4e9299 100644
--- a/ovn/controller/pinctrl.c
+++ b/ovn/controller/pinctrl.c
@@ -2417,14 +2417,15 @@ packet_put_ra_rdnss_opt(struct dp_packet *b, uint8_t num,
 
 static void
 packet_put_ra_dnssl_opt(struct dp_packet *b, ovs_be32 lifetime,
-                        char *dnssl_list)
+                        char *dnssl_data)
 {
+    char *dnssl_list, *t0, *r0 = NULL, dnssl[255] = {};
     size_t prev_l4_size = dp_packet_l4_size(b);
     size_t size = sizeof(struct ovs_nd_dnssl);
-    struct ip6_hdr *nh = dp_packet_l3(b);
-    char *t0, *r0 = NULL, dnssl[255] = {};
     int i = 0;
 
+    dnssl_list = xstrdup(dnssl_data);
+
     /* Multiple DNS Search List must be 'comma' separated
      * (e.g. "a.b.c, d.e.f"). Domain names must be encoded
      * as described in Section 3.1 of RFC1035.
@@ -2437,7 +2438,7 @@ packet_put_ra_dnssl_opt(struct dp_packet *b, ovs_be32 lifetime,
 
         size += strlen(t0) + 2;
         if (size > sizeof(dnssl)) {
-            return;
+            goto out;
         }
 
         for (t1 = strtok_r(t0, ".", &r1); t1;
@@ -2449,6 +2450,8 @@ packet_put_ra_dnssl_opt(struct dp_packet *b, ovs_be32 lifetime,
         dnssl[i++] = 0;
     }
     size = ROUND_UP(size, 8);
+
+    struct ip6_hdr *nh = dp_packet_l3(b);
     nh->ip6_plen = htons(prev_l4_size + size);
 
     struct ovs_nd_dnssl *nd_dnssl = dp_packet_put_uninit(b, sizeof *nd_dnssl);
@@ -2464,6 +2467,8 @@ packet_put_ra_dnssl_opt(struct dp_packet *b, ovs_be32 lifetime,
     uint32_t icmp_csum = packet_csum_pseudoheader6(dp_packet_l3(b));
     ra->icmph.icmp6_cksum = csum_finish(csum_continue(icmp_csum, ra,
                                                       prev_l4_size + size));
+out:
+    free(dnssl_list);
 }
 
 static void
@@ -2571,7 +2576,7 @@ ipv6_ra_send(struct rconn *swconn, struct ipv6_ra_state *ra)
     }
     if (ra->config->dnssl.length) {
         packet_put_ra_dnssl_opt(&packet, htonl(0xffffffff),
-                                ra->config->dnssl.string);
+                                ds_cstr(&ra->config->dnssl));
     }
     if (ra->config->route_info.length) {
         packet_put_ra_route_info_opt(&packet, htonl(0xffffffff),
-- 
2.21.1