public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v2] ipv4: ip_gre: Avoid skb_pull() failure in ipgre_xmit()
@ 2023-12-02 16:14 Shigeru Yoshida
  2023-12-03  6:58 ` [EXT] " Suman Ghosh
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Shigeru Yoshida @ 2023-12-02 16:14 UTC (permalink / raw)
  To: davem, dsahern, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, Shigeru Yoshida

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>
---
v1 -> v2:
- Change the title
- Update the code with Eric's suggestion
  https://lore.kernel.org/all/20231126151652.372783-1-syoshida@redhat.com/
---
 net/ipv4/ip_gre.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 22a26d1d29a0..5169c3c72cff 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -635,15 +635,18 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb,
 	}
 
 	if (dev->header_ops) {
+		int pull_len = tunnel->hlen + sizeof(struct iphdr);
+
 		if (skb_cow_head(skb, 0))
 			goto free_skb;
 
 		tnl_params = (const struct iphdr *)skb->data;
 
-		/* Pull skb since ip_tunnel_xmit() needs skb->data pointing
-		 * to gre header.
-		 */
-		skb_pull(skb, tunnel->hlen + sizeof(struct iphdr));
+		if (!pskb_network_may_pull(skb, pull_len))
+			goto free_skb;
+
+		/* ip_tunnel_xmit() needs skb->data pointing to gre header. */
+		skb_pull(skb, pull_len);
 		skb_reset_mac_header(skb);
 
 		if (skb->ip_summed == CHECKSUM_PARTIAL &&
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-12-06  9:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-02 16:14 [PATCH net v2] ipv4: ip_gre: Avoid skb_pull() failure in ipgre_xmit() Shigeru Yoshida
2023-12-03  6:58 ` [EXT] " Suman Ghosh
2023-12-03 11:03   ` Eric Dumazet
2023-12-03 11:54   ` Shigeru Yoshida
2023-12-03 15:17     ` Suman Ghosh
2023-12-03 15:38       ` Shigeru Yoshida
2023-12-03 15:18 ` Suman Ghosh
2023-12-06  9:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox