Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2461706yba; Mon, 15 Apr 2019 12:08:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqz19U4UVYmBM50UIrpW6mkEdEgLEM/40qcFA+ONzAT2a7Fxh4+2yjamDEaY6vDVXkxEJKup X-Received: by 2002:aa7:83ce:: with SMTP id j14mr48656328pfn.57.1555355311852; Mon, 15 Apr 2019 12:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555355311; cv=none; d=google.com; s=arc-20160816; b=K7Vm3SZ1TMzUzphRPte030XFGqRYtbMPtqg3V3DfrGaJt7h6705h+TXYM9dC4J6Voc 7U2YkmhOYFB4ceCuL8f5T0/AI5/4utmmuDAdMjgtACWlHDGynUFXNYMRDl2HA4GXQVSJ e/K3xN7bV+Al3nTMrorTcmuMP5/XenLZ9EwfMs9ZcaCX9/koT9NXn85Y2uz0lmlgl8eU Y1mckM1SkeqA73kneMw9kLdPaFsqXaZNUT+JGm1js/1JQRjREuiwIJ+RrdSRYxecatJa hQo8KZ3zUPfDUgRoT9doT3nVsxDXVagf2/Oxp9rVcDrkY3mbp2WPw68nW8IEuAg3yGx1 dYLA== 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=sduqBXvJrNCr0CVcwHiGm8TmRf11u/4ACTWK+yDxZsw=; b=NzAMUlc0RVhor/Mj4IjoGJEZ6VNA0chNxI7Kj2eqlKdrvV29wirF1Ufynk6NRoKY9Z yY4AlkxnP6VhF46oULwreEDUSxorK12iH64vUUSBPvt8GPqQg6JgwDCjsnI30fqGHdkm qOL4RKsIq0frrbjRk1eQL+RJcotpTRqT4aW234zu9un2tUx3qfSUMOH/y9YbQ0gQ+5td 7T0hdRYNqkPnY1j4PEKoB80ab1Ztru9Yhgqwby7ndrJvDskqTch1GhXq/I6K09LE+etC VG5fzRUXKJeIeAbO/9rzxyfAOFRT7ciGr7WtbvWpJ0UFKPeDVs5hHs+cmood/XnzReVh CIeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kbx7RnUg; 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 e3si30268999pgc.98.2019.04.15.12.08.15; Mon, 15 Apr 2019 12:08:31 -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=kbx7RnUg; 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 S1729777AbfDOTFs (ORCPT + 99 others); Mon, 15 Apr 2019 15:05:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:39678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729294AbfDOTFq (ORCPT ); Mon, 15 Apr 2019 15:05:46 -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 764B72087C; Mon, 15 Apr 2019 19:05:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355145; bh=74NF6t6x76by8bHCCmeDDrtQE+57CZunci9bkwuwZIE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kbx7RnUgOAB+wihBpCoxPOLvgp6iI6ZdnzZtoZrjhI+pTW0WJAnifLtuq3nvVdf06 Yy68l+Ya/BtVSBaKP3tmrl+3F63NRiMr740GHye/VXmt4cx32D6C4IquSpYSLmFvmf OGs94Iv35sb1owk3d5gOSebhZknUR63AcXWPgxLc= 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 030/101] net: ip_gre: fix possible use-after-free in erspan_rcv Date: Mon, 15 Apr 2019 20:58:28 +0200 Message-Id: <20190415183742.032647007@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 492b67e28ee5f2a2522fb72e3d3bcb990e461514 ] erspan tunnels run __iptunnel_pull_header on received skbs to remove gre and erspan headers. This can determine a possible use-after-free accessing pkt_md pointer in erspan_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/ipv4/ip_gre.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index f199945f6e4a..3c734832bb7c 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -260,7 +260,6 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi, struct net *net = dev_net(skb->dev); struct metadata_dst *tun_dst = NULL; struct erspan_base_hdr *ershdr; - struct erspan_metadata *pkt_md; struct ip_tunnel_net *itn; struct ip_tunnel *tunnel; const struct iphdr *iph; @@ -283,9 +282,6 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi, if (unlikely(!pskb_may_pull(skb, len))) return PACKET_REJECT; - ershdr = (struct erspan_base_hdr *)(skb->data + gre_hdr_len); - pkt_md = (struct erspan_metadata *)(ershdr + 1); - if (__iptunnel_pull_header(skb, len, htons(ETH_P_TEB), @@ -293,8 +289,9 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi, goto drop; if (tunnel->collect_md) { + struct erspan_metadata *pkt_md, *md; struct ip_tunnel_info *info; - struct erspan_metadata *md; + unsigned char *gh; __be64 tun_id; __be16 flags; @@ -307,6 +304,14 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi, 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)); md = ip_tunnel_info_opts(&tun_dst->u.tun_info); md->version = ver; md2 = &md->u.md2; -- 2.19.1