examples/ipsec-secgw: fix IP version check
authorTomasz Duszynski <tdu@semihalf.com>
Fri, 13 Oct 2017 12:50:09 +0000 (14:50 +0200)
committerPablo de Lara <pablo.de.lara.guarch@intel.com>
Wed, 25 Oct 2017 16:10:32 +0000 (18:10 +0200)
Since new_ip and ip4 are overlapping buffers copying ip4 over new_ip
using memmove() might overwrite memory at ip4. This could happen if
following condition holds:

ip_hdr_len > sizeof(struct esp_hdr) + sa->iv_len

Thus using ip4 to check ip version is wrong as it might not contain
proper value.

Fixes: f159e70b0922 ("examples/ipsec-secgw: support transport mode")
Cc: stable@dpdk.org
Signed-off-by: Tomasz Duszynski <tdu@semihalf.com>
Acked-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
Reviewed-by: Aviad Yehezkel <aviadye@mellanox.com>
examples/ipsec-secgw/esp.c

index 70bb81f..56ad7a0 100644 (file)
@@ -306,8 +306,8 @@ esp_outbound(struct rte_mbuf *m, struct ipsec_sa *sa,
                                sizeof(struct esp_hdr) + sa->iv_len);
                memmove(new_ip, ip4, ip_hdr_len);
                esp = (struct esp_hdr *)(new_ip + ip_hdr_len);
+               ip4 = (struct ip *)new_ip;
                if (likely(ip4->ip_v == IPVERSION)) {
-                       ip4 = (struct ip *)new_ip;
                        ip4->ip_p = IPPROTO_ESP;
                        ip4->ip_len = htons(rte_pktmbuf_data_len(m));
                } else {