Commit 80d875cf authored by Shigeru Yoshida's avatar Shigeru Yoshida Committed by Paolo Abeni

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: c5441932 ("GRE: Refactor GRE tunneling code.")
Signed-off-by: default avatarShigeru Yoshida <syoshida@redhat.com>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Reviewed-by: default avatarSuman Ghosh <sumang@marvell.com>
Link: https://lore.kernel.org/r/20231202161441.221135-1-syoshida@redhat.comSigned-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent efd563ff
...@@ -635,15 +635,18 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb, ...@@ -635,15 +635,18 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb,
} }
if (dev->header_ops) { if (dev->header_ops) {
int pull_len = tunnel->hlen + sizeof(struct iphdr);
if (skb_cow_head(skb, 0)) if (skb_cow_head(skb, 0))
goto free_skb; goto free_skb;
tnl_params = (const struct iphdr *)skb->data; tnl_params = (const struct iphdr *)skb->data;
/* Pull skb since ip_tunnel_xmit() needs skb->data pointing if (!pskb_network_may_pull(skb, pull_len))
* to gre header. goto free_skb;
*/
skb_pull(skb, tunnel->hlen + sizeof(struct iphdr)); /* ip_tunnel_xmit() needs skb->data pointing to gre header. */
skb_pull(skb, pull_len);
skb_reset_mac_header(skb); skb_reset_mac_header(skb);
if (skb->ip_summed == CHECKSUM_PARTIAL && if (skb->ip_summed == CHECKSUM_PARTIAL &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment