Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2566304lkm; Mon, 20 Sep 2021 18:53:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsvXhTN5mw7A31MG33kkdSTOMAvD70JwETS8Ah8GtFNBWWF5rpOwmeEo6ra08hiNzSwUch X-Received: by 2002:a05:6e02:12e1:: with SMTP id l1mr11018986iln.286.1632189098824; Mon, 20 Sep 2021 18:51:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189098; cv=none; d=google.com; s=arc-20160816; b=OTohY7MIQkua/eIcXUGpG0XExUdHTdYfBiyMWsBxrtnjsBqK1Hp2iXcqKJbEW9x6Vh vhw5NDrk08cpPaNedSv7GBbJ4ptX1sfOamg7jB5pthPr23xJK1wXXo40Fp5mPoi8X0mt 0tbL6RPp6y8PDSg9xbyhjNKE0QY1oQ3WhFrsEsXAMCVfkXvNRkLYgfIp8MI+Z2f2BJzf 1j57t0Fhe7J/Ji3JSSA/b8WchNNKKrlg1+wYz0kmo90dDdonSEHjQry3YVLc4og+ZzTQ 9tSW4LQSUlEmXilt4P48k5rS64BqCFFwiJWcub7soUHETEkfICDRp/pGpl1qYcFERaAS 7z9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VlASvV8QvyG5nhl7RMQaUi+HBZbB6RHyJDDX1zmws7M=; b=FaTiNGAl4QK4jS5B2L4+5ngrvzR55NuojVC6yD24GmO2x2cAzgfJOzg6koE3QoBjgj 4/fo79dMNaALWJizgfv/TxK+tHd6uNT6/Mr8nwMAZjkOA6Ed6KfZMfsD+SUuaGVxDb7c TPAXelivtZmYxNPoPXx0A4U0Fg2VIBcif7ODX9Cr4qZi5/v5eBGwnRT0cSCjuxP7k1u1 SJIQ7MARVmKARC/NdCXKd6HgQMZcY6E81N6WP5g87iu1bZfuJ3XZis+Ehvqxzi5F3DBN 252oDHpcrOKdpPi+dM7v5spdQ93g1xkNFLjyavJS8tjSK5ApT+MiGtqdVOq9TLDcZx0k n3BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fZiqzvNj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x13si4871362ilg.76.2021.09.20.18.51.27; Mon, 20 Sep 2021 18:51:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fZiqzvNj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357436AbhITSET (ORCPT + 99 others); Mon, 20 Sep 2021 14:04:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:57650 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355969AbhITR5z (ORCPT ); Mon, 20 Sep 2021 13:57:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 75ED2619F7; Mon, 20 Sep 2021 17:14:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158092; bh=ys3biWQe7I6RSUYd68KwBvrTpC36mPZIbuMdI6/sCm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fZiqzvNjewzeGRjHHpxcxq5ry6O4HhUtBbuKFrhSQ4npKwoAYsSekUGjVosvorHbo /1d2zi6HEXhxlYf3SwDYnOLh6KwAmzgWH92xCCG4w+rrBFFaUjMVwaJ1lqH8bh+zUr RGfmY/36VdGaFyCPKZ9JQaYrS7Sm1zIPLDt11MNA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ido Schimmel , Alexander Duyck , Willem de Bruijn , Alexander Duyck , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 292/293] ip_gre: validate csum_start only on pull Date: Mon, 20 Sep 2021 18:44:14 +0200 Message-Id: <20210920163943.422689841@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Willem de Bruijn [ Upstream commit 8a0ed250f911da31a2aef52101bc707846a800ff ] The GRE tunnel device can pull existing outer headers in ipge_xmit. This is a rare path, apparently unique to this device. The below commit ensured that pulling does not move skb->data beyond csum_start. But it has a false positive if ip_summed is not CHECKSUM_PARTIAL and thus csum_start is irrelevant. Refine to exclude this. At the same time simplify and strengthen the test. Simplify, by moving the check next to the offending pull, making it more self documenting and removing an unnecessary branch from other code paths. Strengthen, by also ensuring that the transport header is correct and therefore the inner headers will be after skb_reset_inner_headers. The transport header is set to csum_start in skb_partial_csum_set. Link: https://lore.kernel.org/netdev/YS+h%2FtqCJJiQei+W@shredder/ Fixes: 1d011c4803c7 ("ip_gre: add validation for csum_start") Reported-by: Ido Schimmel Suggested-by: Alexander Duyck Signed-off-by: Willem de Bruijn Reviewed-by: Alexander Duyck Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/ip_gre.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index a8a37d112820..0c431fd4b120 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -449,8 +449,6 @@ static void __gre_xmit(struct sk_buff *skb, struct net_device *dev, static int gre_handle_offloads(struct sk_buff *skb, bool csum) { - if (csum && skb_checksum_start(skb) < skb->data) - return -EINVAL; return iptunnel_handle_offloads(skb, csum ? SKB_GSO_GRE_CSUM : SKB_GSO_GRE); } @@ -682,15 +680,20 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb, } if (dev->header_ops) { + const int pull_len = tunnel->hlen + sizeof(struct iphdr); + if (skb_cow_head(skb, 0)) goto free_skb; tnl_params = (const struct iphdr *)skb->data; + if (pull_len > skb_transport_offset(skb)) + goto free_skb; + /* Pull skb since ip_tunnel_xmit() needs skb->data pointing * to gre header. */ - skb_pull(skb, tunnel->hlen + sizeof(struct iphdr)); + skb_pull(skb, pull_len); skb_reset_mac_header(skb); } else { if (skb_cow_head(skb, dev->needed_headroom)) -- 2.30.2