From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45C5EFA372C for ; Fri, 8 Nov 2019 19:04:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 125E8214DB for ; Fri, 8 Nov 2019 19:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573239850; bh=JOTNkX92quIQ57fhN+3MB4G/ymxl5+lWeGvD6VYEQcE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=gzxj0NNuZv7fAmZeWztrEkz4mPILTFf/XAX9zGf/1kofKU9vUpud19WhEGfqPbMaw iqg1kvMbbfjOBKKHfmqK/iFfIrbJGx0+LUMZblfrQTSZZ8Qgz+4J8cBt+jVEs1ZE3t PuQi7CdPenOOE0ydkJZ6PAw2a8WbEp7O+LWv9zBY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390931AbfKHTEJ (ORCPT ); Fri, 8 Nov 2019 14:04:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:33938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732780AbfKHTEG (ORCPT ); Fri, 8 Nov 2019 14:04:06 -0500 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 1F2A7214DB; Fri, 8 Nov 2019 19:04:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573239845; bh=JOTNkX92quIQ57fhN+3MB4G/ymxl5+lWeGvD6VYEQcE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hoH6Mj8n3HpDqPvZtbenvfPsC2BFO/dw0hT+sVjtotDmtf9abhqlNZo4JFlwSEWUX gxraz1z1fjJTLoBRZyyvUtMU34diwz5Dor/E4Yz29K/OWA/PpH7GgrOR/nZ4VOi0Dz I8FVemxEgfPy0XEplx34k4S6kCC5ZR5dMfTIlN8k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Long , "David S. Miller" Subject: [PATCH 4.19 39/79] erspan: fix the tun_info options_len check for erspan Date: Fri, 8 Nov 2019 19:50:19 +0100 Message-Id: <20191108174808.812916068@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174745.495640141@linuxfoundation.org> References: <20191108174745.495640141@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Xin Long [ Upstream commit 2eb8d6d2910cfe3dc67dc056f26f3dd9c63d47cd ] The check for !md doens't really work for ip_tunnel_info_opts(info) which only does info + 1. Also to avoid out-of-bounds access on info, it should ensure options_len is not less than erspan_metadata in both erspan_xmit() and ip6erspan_tunnel_xmit(). Fixes: 1a66a836da ("gre: add collect_md mode to ERSPAN tunnel") Signed-off-by: Xin Long Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/ip_gre.c | 4 ++-- net/ipv6/ip6_gre.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -589,9 +589,9 @@ static void erspan_fb_xmit(struct sk_buf key = &tun_info->key; if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT)) goto err_free_rt; + if (tun_info->options_len < sizeof(*md)) + goto err_free_rt; md = ip_tunnel_info_opts(tun_info); - if (!md) - goto err_free_rt; /* ERSPAN has fixed 8 byte GRE header */ version = md->version; --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -1000,9 +1000,9 @@ static netdev_tx_t ip6erspan_tunnel_xmit dsfield = key->tos; if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT)) goto tx_err; - md = ip_tunnel_info_opts(tun_info); - if (!md) + if (tun_info->options_len < sizeof(*md)) goto tx_err; + md = ip_tunnel_info_opts(tun_info); tun_id = tunnel_id_to_key32(key->tun_id); if (md->version == 1) {