bbaaef
From b59b64c0be5f16791c77d1b0104f09fd424ac098 Mon Sep 17 00:00:00 2001
bbaaef
Message-Id: <b59b64c0be5f16791c77d1b0104f09fd424ac098.1578588395.git.lorenzo.bianconi@redhat.com>
bbaaef
In-Reply-To: <600a018ea1136e184b421c86da170b35d05e949f.1578588395.git.lorenzo.bianconi@redhat.com>
bbaaef
References: <600a018ea1136e184b421c86da170b35d05e949f.1578588395.git.lorenzo.bianconi@redhat.com>
bbaaef
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
bbaaef
Date: Tue, 7 Jan 2020 17:50:05 +0100
bbaaef
Subject: [PATCH 2/3] DNSSL: copy dnssl string in order to avoid truncated
bbaaef
 value
bbaaef
bbaaef
ipv6_ra_send can run 2 times in a row before prepare_ipv6_ras updates
bbaaef
the dnss list. Copy the dnss dynamic string in packet_put_ra_dnssl_opt
bbaaef
in order to avoid sending truncated dnssl list on the wire.
bbaaef
Moreover move ip6_hdr definition just before accessing it because the
bbaaef
packet can be reallocated if the data area is not big enough for packet
bbaaef
content
bbaaef
bbaaef
Fixes: 5a12a940f ("Add DNSSL support to OVN")
bbaaef
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
bbaaef
Signed-off-by: Numan Siddique <numans@ovn.org>
bbaaef
---
bbaaef
 ovn/controller/pinctrl.c | 15 ++++++++++-----
bbaaef
 1 file changed, 10 insertions(+), 5 deletions(-)
bbaaef
bbaaef
diff --git a/ovn/controller/pinctrl.c b/ovn/controller/pinctrl.c
bbaaef
index 04ccb25a8..43b4e9299 100644
bbaaef
--- a/ovn/controller/pinctrl.c
bbaaef
+++ b/ovn/controller/pinctrl.c
bbaaef
@@ -2417,14 +2417,15 @@ packet_put_ra_rdnss_opt(struct dp_packet *b, uint8_t num,
bbaaef
 
bbaaef
 static void
bbaaef
 packet_put_ra_dnssl_opt(struct dp_packet *b, ovs_be32 lifetime,
bbaaef
-                        char *dnssl_list)
bbaaef
+                        char *dnssl_data)
bbaaef
 {
bbaaef
+    char *dnssl_list, *t0, *r0 = NULL, dnssl[255] = {};
bbaaef
     size_t prev_l4_size = dp_packet_l4_size(b);
bbaaef
     size_t size = sizeof(struct ovs_nd_dnssl);
bbaaef
-    struct ip6_hdr *nh = dp_packet_l3(b);
bbaaef
-    char *t0, *r0 = NULL, dnssl[255] = {};
bbaaef
     int i = 0;
bbaaef
 
bbaaef
+    dnssl_list = xstrdup(dnssl_data);
bbaaef
+
bbaaef
     /* Multiple DNS Search List must be 'comma' separated
bbaaef
      * (e.g. "a.b.c, d.e.f"). Domain names must be encoded
bbaaef
      * as described in Section 3.1 of RFC1035.
bbaaef
@@ -2437,7 +2438,7 @@ packet_put_ra_dnssl_opt(struct dp_packet *b, ovs_be32 lifetime,
bbaaef
 
bbaaef
         size += strlen(t0) + 2;
bbaaef
         if (size > sizeof(dnssl)) {
bbaaef
-            return;
bbaaef
+            goto out;
bbaaef
         }
bbaaef
 
bbaaef
         for (t1 = strtok_r(t0, ".", &r1;; t1;
bbaaef
@@ -2449,6 +2450,8 @@ packet_put_ra_dnssl_opt(struct dp_packet *b, ovs_be32 lifetime,
bbaaef
         dnssl[i++] = 0;
bbaaef
     }
bbaaef
     size = ROUND_UP(size, 8);
bbaaef
+
bbaaef
+    struct ip6_hdr *nh = dp_packet_l3(b);
bbaaef
     nh->ip6_plen = htons(prev_l4_size + size);
bbaaef
 
bbaaef
     struct ovs_nd_dnssl *nd_dnssl = dp_packet_put_uninit(b, sizeof *nd_dnssl);
bbaaef
@@ -2464,6 +2467,8 @@ packet_put_ra_dnssl_opt(struct dp_packet *b, ovs_be32 lifetime,
bbaaef
     uint32_t icmp_csum = packet_csum_pseudoheader6(dp_packet_l3(b));
bbaaef
     ra->icmph.icmp6_cksum = csum_finish(csum_continue(icmp_csum, ra,
bbaaef
                                                       prev_l4_size + size));
bbaaef
+out:
bbaaef
+    free(dnssl_list);
bbaaef
 }
bbaaef
 
bbaaef
 static void
bbaaef
@@ -2571,7 +2576,7 @@ ipv6_ra_send(struct rconn *swconn, struct ipv6_ra_state *ra)
bbaaef
     }
bbaaef
     if (ra->config->dnssl.length) {
bbaaef
         packet_put_ra_dnssl_opt(&packet, htonl(0xffffffff),
bbaaef
-                                ra->config->dnssl.string);
bbaaef
+                                ds_cstr(&ra->config->dnssl));
bbaaef
     }
bbaaef
     if (ra->config->route_info.length) {
bbaaef
         packet_put_ra_route_info_opt(&packet, htonl(0xffffffff),
bbaaef
-- 
bbaaef
2.21.1
bbaaef