Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp460430pxx; Wed, 28 Oct 2020 08:51:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzF8GbD22q1gP87fIiz1l/AKOJwmUc3LscwZM0tGm6Da9K9bo49WT92tZ6W8kG3xf6I2MqP X-Received: by 2002:a17:906:3e48:: with SMTP id t8mr8052197eji.104.1603900288913; Wed, 28 Oct 2020 08:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603900288; cv=none; d=google.com; s=arc-20160816; b=hw/qqa73+nA0EbdL/I1irJvcL0Qoieo1nZZMUYu9xL97x2eoox/3wl1ZUWDwAuP3cV hOGDZTfiuLlPNuLqm0W9Fmf1HbtW11tmbq3m+qKfF+qqqrQDSfe/EthR3uDmh2GnEtcA SHdc5M+uSM4k9C+uNGkZxbiUU6OW24dZrkD5WeHQI3OrmDpzT3bm9ow0EMCG1DQtxDvU krkWtM7yL3oIvVYvjjhoXPuPh3bAskcLUxkrmbQ+/zIraVPPBCVOgg6C03zZlxwUoI+9 ItDUYaX02eZ7uRBfvSBxBUM2/ZPfP4IY3vXz0N3m7kT1WpE1YIYBnG3AVWasjFPPGE6/ r5nw== 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=gOgYJMzHWxCaWasSxWCnCT54lCd6JmieIoPVo94SM9k=; b=AUc0JzSlLAzbOs9LcoYZBgBk1xItL+PT1K/NkRe13WkK69Xz8pPgdRyIy1rXCKDzD4 lNj2wvfjFk8cYIoG88P/3VxsuYlUW185ckExAXqArJOi+7fuIG/iY5lX6ypfGMt3A+jl XXv+oWoJ95HXLEmzZXFmdAJGMqhUaBslpAiw7vez+0JItUHbvRxJUzoHSL4sFlq6OMZM DZCC4mCVQKkgdNTqh1GKRDXC9MF4exIpQnNHF5KmfA5eV6CKzo8600qA9li/ROsskzG4 hRPM9azvBL8dxk4kPdrNzMWOA1a0+9PE/bOoEycy27mc2OgawHZPb6Zl8VCb5YfrjLLD JEFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=liDdhUhX; 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 dk22si2709939edb.258.2020.10.28.08.51.06; Wed, 28 Oct 2020 08:51:28 -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=liDdhUhX; 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 S1813278AbgJ0Qtq (ORCPT + 99 others); Tue, 27 Oct 2020 12:49:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:50470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1794798AbgJ0PNk (ORCPT ); Tue, 27 Oct 2020 11:13:40 -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 E7C6E20657; Tue, 27 Oct 2020 15:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811619; bh=876ugGTYUCG5GvmuzmLBh8mkjKMdy2vxqd0GNel4T/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=liDdhUhXXbM3SXiL1HnBfRHejKk2345M9VBzz8ylMhh6/UF+QYR66NWjb44jGSyBY O90WXry32qZZ7CDNQa3RkyNPXIfxgGDRHJfSxIJvJWEpcU/EdybYRNcfdA+ImRHR7t t01meXS2D9mMEqMPRj7/aS5kTcOM9SITiUB2p6q4= 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.8 558/633] ip_gre: set dev->hard_header_len and dev->needed_headroom properly Date: Tue, 27 Oct 2020 14:55:01 +0100 Message-Id: <20201027135548.989318788@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@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 4e31f23e4117e..e70291748889b 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -625,9 +625,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; @@ -748,7 +746,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); @@ -944,6 +946,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; @@ -987,10 +990,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