Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1121857pxx; Tue, 27 Oct 2020 08:45:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxz4jBkgT3TaLRowIeONWxCIL0hJI00JvaRjil3nCQhVZ/Yuv/S0mQE8r82DVBT9kLvIFZd X-Received: by 2002:a50:f41a:: with SMTP id r26mr2801205edm.251.1603813501458; Tue, 27 Oct 2020 08:45:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603813501; cv=none; d=google.com; s=arc-20160816; b=t1WIOfDfGJzs02LngZRDqjB/BMbuMiC8Te/3ly+fEEX4VTd8MwftWxeVbnEfnm0Mw7 8neo6C0WymeX3tz3lenvCpL/HP8YEwLPKswmojIBh9q05gC+xCljVZKBXRdKDBoMwtta j5WRv2E4x7rhUZOEI0iVpD5zmud3sAsdEWXx/9YbdxDG44s8Iq1IYdE5RDLT4Vv5TLmG F546ETgA5P3cNauxzH6w6K4vC1mcedFdrkHua7YX76rIbSmDj1S0GDt/TVJTKkK+TWWH D/tyLuRcxq+Tkvv2Eqcvy89Yis2JradKqoSfXUP8uH3gpD0bwIf8mTq8Gnq0GnQ9bOEP K5IA== 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=ODDyZwOkVHjt7CuZ7PZP7Zl0op+6nQstwRfR6v9Ct+U=; b=bMCpeZWgSW5irSInBomWwQjF+Y7GZ5wF1C7/EluYaRFo5EwYGhyx17z0whjghU9aQ8 9Tgfv6M+okDxbnQfmpwT+NQbWln9vnoV1r6r2X5QdgSa3C/OE2uU1JfXJeBit1WIkBTF YpLuLGft+puhb8H+jKQoNOxXD1nyhl9bjZy23xSBxGK6hTRUC5YgTJklBeBOigaGaHb1 r4h2EKe26A6iYqRMoFJLfOf+r5/Dsjm00jrogxD4eSQ0Qu9A7oA8pJOLonXSMokbniSX jxOqCgef5y1ed8eZ2Hdgt2KFGS9JBRrrbsIf/dwxRgqRN8rz4axkLqBs5kjvJPCCHesB Vz6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Gb6EI0tw; 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=fail (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 z8si1370742eja.81.2020.10.27.08.44.39; Tue, 27 Oct 2020 08:45:01 -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=@kernel.org header.s=default header.b=Gb6EI0tw; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1764010AbgJ0Op7 (ORCPT + 99 others); Tue, 27 Oct 2020 10:45:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:45756 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1763985AbgJ0Opv (ORCPT ); Tue, 27 Oct 2020 10:45:51 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 3082220773; Tue, 27 Oct 2020 14:45:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809949; bh=nCDXuJ8QS5hM+gIDi2XeymGN25m1pU86CVegkbydedc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gb6EI0twfJ0GcKx6rahi/o+6yVwozxMOBdpOnQfHkXgfcj9RL7N6ZlLDm9yBEksi0 jdwFZRUxhv5aUshrqlC/n9S4D0M8L7LDfd3rhfOL3EdOJBOw1vAvzSaXQdkQNxlF2Z 1vBdrx1hNYMtPQXRuok7jNW/VEKHTBFy6c8ZTVH0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, William Tu , Willem de Bruijn , Cong Wang , Xie He , Jakub Kicinski , Sasha Levin , syzbot+4a2c52677a8a1aa283cb@syzkaller.appspotmail.com Subject: [PATCH 5.4 349/408] ip_gre: set dev->hard_header_len and dev->needed_headroom properly Date: Tue, 27 Oct 2020 14:54:47 +0100 Message-Id: <20201027135511.205180498@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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: Cong Wang [ Upstream commit fdafed459998e2be0e877e6189b24cb7a0183224 ] GRE tunnel has its own header_ops, ipgre_header_ops, and sets it conditionally. When it is set, it assumes the outer IP header is already created before ipgre_xmit(). This is not true when we send packets through a raw packet socket, where L2 headers are supposed to be constructed by user. Packet socket calls dev_validate_header() to validate the header. But GRE tunnel does not set dev->hard_header_len, so that check can be simply bypassed, therefore uninit memory could be passed down to ipgre_xmit(). Similar for dev->needed_headroom. dev->hard_header_len is supposed to be the length of the header created by dev->header_ops->create(), so it should be used whenever header_ops is set, and dev->needed_headroom should be used when it is not set. Reported-and-tested-by: syzbot+4a2c52677a8a1aa283cb@syzkaller.appspotmail.com Cc: William Tu Acked-by: Willem de Bruijn Signed-off-by: Cong Wang Acked-by: Xie He Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv4/ip_gre.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index 85ba1453ba5ca..fedad3a3e61b8 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -603,9 +603,7 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb, } if (dev->header_ops) { - /* Need space for new headers */ - if (skb_cow_head(skb, dev->needed_headroom - - (tunnel->hlen + sizeof(struct iphdr)))) + if (skb_cow_head(skb, 0)) goto free_skb; tnl_params = (const struct iphdr *)skb->data; @@ -723,7 +721,11 @@ static void ipgre_link_update(struct net_device *dev, bool set_mtu) len = tunnel->tun_hlen - len; tunnel->hlen = tunnel->hlen + len; - dev->needed_headroom = dev->needed_headroom + len; + if (dev->header_ops) + dev->hard_header_len += len; + else + dev->needed_headroom += len; + if (set_mtu) dev->mtu = max_t(int, dev->mtu - len, 68); @@ -926,6 +928,7 @@ static void __gre_tunnel_init(struct net_device *dev) tunnel->parms.iph.protocol = IPPROTO_GRE; tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen; + dev->needed_headroom = tunnel->hlen + sizeof(tunnel->parms.iph); dev->features |= GRE_FEATURES; dev->hw_features |= GRE_FEATURES; @@ -969,10 +972,14 @@ static int ipgre_tunnel_init(struct net_device *dev) return -EINVAL; dev->flags = IFF_BROADCAST; dev->header_ops = &ipgre_header_ops; + dev->hard_header_len = tunnel->hlen + sizeof(*iph); + dev->needed_headroom = 0; } #endif } else if (!tunnel->collect_md) { dev->header_ops = &ipgre_header_ops; + dev->hard_header_len = tunnel->hlen + sizeof(*iph); + dev->needed_headroom = 0; } return ip_tunnel_init(dev); -- 2.25.1