Skip to content

Commit 80d875c

Browse files
Shigeru YoshidaPaolo Abeni
authored andcommitted
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: c544193 ("GRE: Refactor GRE tunneling code.") Signed-off-by: Shigeru Yoshida <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Reviewed-by: Suman Ghosh <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent efd563f commit 80d875c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

net/ipv4/ip_gre.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,15 +635,18 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb,
635635
}
636636

637637
if (dev->header_ops) {
638+
int pull_len = tunnel->hlen + sizeof(struct iphdr);
639+
638640
if (skb_cow_head(skb, 0))
639641
goto free_skb;
640642

641643
tnl_params = (const struct iphdr *)skb->data;
642644

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);
647650
skb_reset_mac_header(skb);
648651

649652
if (skb->ip_summed == CHECKSUM_PARTIAL &&

0 commit comments

Comments
 (0)