Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipv4: ip_gre: Avoid skb_pull() failure in ipgre_xmit()

In ipgre_xmit(), skb_pull() may fail even if pskb_inet_may_pull() returns
true. For example, applications can use PF_PACKET to create a malformed
packet with no IP header. This type of packet causes a problem such as
uninit-value access.

This patch ensures that skb_pull() can pull the required size by checking
the skb with pskb_network_may_pull() before skb_pull().

Fixes: c54419321455 ("GRE: Refactor GRE tunneling code.")
Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Suman Ghosh <sumang@marvell.com>
Link: https://lore.kernel.org/r/20231202161441.221135-1-syoshida@redhat.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Shigeru Yoshida and committed by
Paolo Abeni
80d875cf efd563ff

+7 -4
+7 -4
net/ipv4/ip_gre.c
··· 635 635 } 636 636 637 637 if (dev->header_ops) { 638 + int pull_len = tunnel->hlen + sizeof(struct iphdr); 639 + 638 640 if (skb_cow_head(skb, 0)) 639 641 goto free_skb; 640 642 641 643 tnl_params = (const struct iphdr *)skb->data; 642 644 643 - /* Pull skb since ip_tunnel_xmit() needs skb->data pointing 644 - * to gre header. 645 - */ 646 - skb_pull(skb, tunnel->hlen + sizeof(struct iphdr)); 645 + if (!pskb_network_may_pull(skb, pull_len)) 646 + goto free_skb; 647 + 648 + /* ip_tunnel_xmit() needs skb->data pointing to gre header. */ 649 + skb_pull(skb, pull_len); 647 650 skb_reset_mac_header(skb); 648 651 649 652 if (skb->ip_summed == CHECKSUM_PARTIAL &&