Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2461981yba; Mon, 15 Apr 2019 12:08:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbjy1szpgX2OA5dKj46I7AmyzZHQhJ5UdKg+SoBMs6+8MKRgAz9xx2EeNB3c3T6db2I7kw X-Received: by 2002:a17:902:8a4:: with SMTP id 33mr78229966pll.7.1555355332150; Mon, 15 Apr 2019 12:08:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555355332; cv=none; d=google.com; s=arc-20160816; b=QCddmKqDVQe13wDB7c8CnDMooE5ikylNFrb0Qq+KcYBnWX3jOBHF6Lz7/zUWT7mg5T Tttg6bd1SYw1MDywfX4whwD4ovpJaBpQU7Oo1WsYHKCiVP++BHeRQhmd5YsRu6YBBD2r 8z3GcKMVPNUCNIlEkzRYmnq5sSpWqz84v+jIPxBHYo8c0+8SIti2z3bV03BRgBXzIwFp p+CY02GrfgM4H2f6NT8iUlX6hsmGLFM1BmreYt2rcIBMw5Q1FsWloQKQxzA2u7+p6SzN iReceTVhvi62NM/0m27lHSU4JXG59qkEcgOzkRntCqKdK8mJkGMziaXfydJzKCB3J+il SvmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3P5qHZ22LAeGCoiX2Ej7lbQXJsVHMeTGy1xoIwPfc1I=; b=l1qxAiSQQDzvBdISsmu8teKPFSsTVQ8tga5J77Xa6edNBx2M250T/yNVvALgG73Sqf fgvbE0BzmzwIJImbRwHIcFjYwouiQiia/7gkiZ+oaJHgPTWeKuw1cJVZxpipox78kVR0 Oyue8FlQe6wxDfhHx9mOVBunIZhcIn+wT5GZ45vgtymzYXiLWbeLAGioPu+zeLK9PTV0 AIQECv1fVYLHy34jEiiJ+uCmHHX40I2Yz0DUwtQU7yLTMk0AApAQi12vg7bkDTcgcEg+ zTjDEriPhvjVZD4zDMLgtXo21QCAUgEC35eTngdTekuSh32rHQ+BNhi19YiP4tJ+kWSN fYBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BWQAQXLE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si20160827pls.222.2019.04.15.12.08.35; Mon, 15 Apr 2019 12:08:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BWQAQXLE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730145AbfDOTHR (ORCPT + 99 others); Mon, 15 Apr 2019 15:07:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:42068 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730120AbfDOTHP (ORCPT ); Mon, 15 Apr 2019 15:07:15 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2084820880; Mon, 15 Apr 2019 19:07:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355234; bh=R9Ud+9zrGfWDWV7gWM/wQHsWNy9WLdmxSnhwN6502iA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BWQAQXLEIFCJpTIoCWIW6jYGZtO/6HdZjWI5M5C7aE7OC0gBZ1W262zfmiyWvcSK5 WNrQedV31n86cnl2fnse7U1633MNQsQA4HKyZkwS/DwEq1PmL/OuxBE0flx9pWKOVr 3O83uPpUfPvBNqK1KMW3GmxKVXEL7j80QI28vSx4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenzo Bianconi , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 031/101] net: ip6_gre: fix possible use-after-free in ip6erspan_rcv Date: Mon, 15 Apr 2019 20:58:29 +0200 Message-Id: <20190415183742.094876291@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183740.341577907@linuxfoundation.org> References: <20190415183740.341577907@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 2a3cabae4536edbcb21d344e7aa8be7a584d2afb ] erspan_v6 tunnels run __iptunnel_pull_header on received skbs to remove erspan header. This can determine a possible use-after-free accessing pkt_md pointer in ip6erspan_rcv since the packet will be 'uncloned' running pskb_expand_head if it is a cloned gso skb (e.g if the packet has been sent though a veth device). Fix it resetting pkt_md pointer after __iptunnel_pull_header Fixes: 1d7e2ed22f8d ("net: erspan: refactor existing erspan code") Signed-off-by: Lorenzo Bianconi Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv6/ip6_gre.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index faed98dab913..c4a7db62658e 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -540,11 +540,10 @@ static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi) return PACKET_REJECT; } -static int ip6erspan_rcv(struct sk_buff *skb, int gre_hdr_len, - struct tnl_ptk_info *tpi) +static int ip6erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi, + int gre_hdr_len) { struct erspan_base_hdr *ershdr; - struct erspan_metadata *pkt_md; const struct ipv6hdr *ipv6h; struct erspan_md2 *md2; struct ip6_tnl *tunnel; @@ -563,18 +562,16 @@ static int ip6erspan_rcv(struct sk_buff *skb, int gre_hdr_len, if (unlikely(!pskb_may_pull(skb, len))) return PACKET_REJECT; - ershdr = (struct erspan_base_hdr *)skb->data; - pkt_md = (struct erspan_metadata *)(ershdr + 1); - if (__iptunnel_pull_header(skb, len, htons(ETH_P_TEB), false, false) < 0) return PACKET_REJECT; if (tunnel->parms.collect_md) { + struct erspan_metadata *pkt_md, *md; struct metadata_dst *tun_dst; struct ip_tunnel_info *info; - struct erspan_metadata *md; + unsigned char *gh; __be64 tun_id; __be16 flags; @@ -587,6 +584,14 @@ static int ip6erspan_rcv(struct sk_buff *skb, int gre_hdr_len, if (!tun_dst) return PACKET_REJECT; + /* skb can be uncloned in __iptunnel_pull_header, so + * old pkt_md is no longer valid and we need to reset + * it + */ + gh = skb_network_header(skb) + + skb_network_header_len(skb); + pkt_md = (struct erspan_metadata *)(gh + gre_hdr_len + + sizeof(*ershdr)); info = &tun_dst->u.tun_info; md = ip_tunnel_info_opts(info); md->version = ver; @@ -623,7 +628,7 @@ static int gre_rcv(struct sk_buff *skb) if (unlikely(tpi.proto == htons(ETH_P_ERSPAN) || tpi.proto == htons(ETH_P_ERSPAN2))) { - if (ip6erspan_rcv(skb, hdr_len, &tpi) == PACKET_RCVD) + if (ip6erspan_rcv(skb, &tpi, hdr_len) == PACKET_RCVD) return 0; goto out; } -- 2.19.1