Patch "ip_gre: set dev->hard_header_len and dev->needed_headroom properly" has been added to the 5.8-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    ip_gre: set dev->hard_header_len and dev->needed_headroom properly

to the 5.8-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     ip_gre-set-dev-hard_header_len-and-dev-needed_headro.patch
and it can be found in the queue-5.8 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit e8cfd2949489e21c2482173e3201500d7dcb46d9
Author: Cong Wang <xiyou.wangcong@xxxxxxxxx>
Date:   Mon Oct 12 16:17:21 2020 -0700

    ip_gre: set dev->hard_header_len and dev->needed_headroom properly
    
    [ 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@xxxxxxxxxxxxxxxxxxxxxxxxx
    Cc: William Tu <u9012063@xxxxxxxxx>
    Acked-by: Willem de Bruijn <willemb@xxxxxxxxxx>
    Signed-off-by: Cong Wang <xiyou.wangcong@xxxxxxxxx>
    Acked-by: Xie He <xie.he.0141@xxxxxxxxx>
    Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

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);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux