Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751922AbdFHA6U (ORCPT ); Wed, 7 Jun 2017 20:58:20 -0400 Received: from cmccmta2.chinamobile.com ([221.176.66.80]:19264 "EHLO cmccmta2.chinamobile.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751733AbdFHA6S (ORCPT ); Wed, 7 Jun 2017 20:58:18 -0400 X-RM-TRANSID: 2ee65938a1282ee-84206 X-RM-SPAM-FLAG: 00000000 X-RM-TRANSID: 2ee35938a126bef-8e454 From: Haishuang Yan To: "=David S. Miller" , Alexey Kuznetsov , James Morris , Hideaki YOSHIFUJI , Patrick McHardy Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Haishuang Yan , Alexei Starovoitov Subject: [PATCH v2 2/2] ip6_tunnel: fix potential issue in __ip6_tnl_rcv Date: Thu, 8 Jun 2017 08:57:56 +0800 Message-Id: <1496883476-17445-2-git-send-email-yanhaishuang@cmss.chinamobile.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496883476-17445-1-git-send-email-yanhaishuang@cmss.chinamobile.com> References: <1496883476-17445-1-git-send-email-yanhaishuang@cmss.chinamobile.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1176 Lines: 38 When __ip6_tnl_rcv fails, the tun_dst won't be freed, so move skb_dst_set to begin and tun_dst would be freed by kfree_skb. CC: Alexei Starovoitov Fixes: 8d79266bc48c ("ip6_tunnel: add collect_md mode to IPv6 tunnels") Signed-off-by: Haishuang Yan --- net/ipv6/ip6_tunnel.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index 9b37f97..bf45f1b 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -789,6 +789,9 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb, const struct ipv6hdr *ipv6h = ipv6_hdr(skb); int err; + if (tun_dst) + skb_dst_set(skb, (struct dst_entry *)tun_dst); + if ((!(tpi->flags & TUNNEL_CSUM) && (tunnel->parms.i_flags & TUNNEL_CSUM)) || ((tpi->flags & TUNNEL_CSUM) && @@ -852,9 +855,6 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb, skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(tunnel->dev))); - if (tun_dst) - skb_dst_set(skb, (struct dst_entry *)tun_dst); - gro_cells_receive(&tunnel->gro_cells, skb); return 0; -- 1.8.3.1