[ovs-dev,ERSPAN,RFC,14/25] ip_gre: fix potential memory leak in erspan_rcv

Message ID 1521756461-3870-15-git-send-email-gvrose8192@gmail.com
State RFC
Headers show
  • Introduce ERSPAN for OVS
Related show

Commit Message

Gregory Rose March 22, 2018, 10:07 p.m.
From: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>

Upstream commit:
    commit 50670b6ee9bc4ae8f9ce3112b437987adf273245
    Author: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
    Date:   Wed Dec 20 10:07:00 2017 +0800

    ip_gre: fix potential memory leak in erspan_rcv

    If md is NULL, tun_dst must be freed, otherwise it will cause memory

    Fixes: 1a66a836da6 ("gre: add collect_md mode to ERSPAN tunnel")
    Cc: William Tu <u9012063@gmail.com>
    Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Cc:  Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
Signed-off-by: Greg Rose <gvrose8192@gmail.com>
 datapath/linux/compat/ip_gre.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)


diff --git a/datapath/linux/compat/ip_gre.c b/datapath/linux/compat/ip_gre.c
index 7cd35a3..f315b16 100644
--- a/datapath/linux/compat/ip_gre.c
+++ b/datapath/linux/compat/ip_gre.c
@@ -193,8 +193,10 @@  static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 					  tun_id, sizeof(*md));
 			md = ip_tunnel_info_opts(&tun_dst.u.tun_info);
-			if (!md)
+			if (!md) {
+				dst_release((struct dst_entry *)tun_dst);
 				return PACKET_REJECT;
+			}
 			memcpy(md, pkt_md, sizeof(*md));
 			info = &tun_dst.u.tun_info;