public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] ip_gre: fix a possible crash in parse_gre_header()
@ 2013-04-05  1:41 Eric Dumazet
  2013-04-08 16:01 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2013-04-05  1:41 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Pravin B Shelar

From: Eric Dumazet <edumazet@google.com>

pskb_may_pull() can change skb->head, so we must init iph/greh after
calling it.

Bug added in commit c54419321455 (GRE: Refactor GRE tunneling code.)

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Pravin B Shelar <pshelar@nicira.com>
---
 net/ipv4/ip_gre.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index e5dfd28..987a4e5 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -159,14 +159,14 @@ static int ip_gre_calc_hlen(__be16 o_flags)
 static int parse_gre_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 			    bool *csum_err, int *hdr_len)
 {
-	struct iphdr *iph = ip_hdr(skb);
-	struct gre_base_hdr *greh;
+	unsigned int ip_hlen = ip_hdrlen(skb);
+	const struct gre_base_hdr *greh;
 	__be32 *options;
 
 	if (unlikely(!pskb_may_pull(skb, sizeof(struct gre_base_hdr))))
 		return -EINVAL;
 
-	greh = (struct gre_base_hdr *)((u8 *)iph + (iph->ihl << 2));
+	greh = (struct gre_base_hdr *)(skb_network_header(skb) + ip_hlen);
 	if (unlikely(greh->flags & (GRE_VERSION | GRE_ROUTING)))
 		return -EINVAL;
 
@@ -176,6 +176,8 @@ static int parse_gre_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 	if (!pskb_may_pull(skb, *hdr_len))
 		return -EINVAL;
 
+	greh = (struct gre_base_hdr *)(skb_network_header(skb) + ip_hlen);
+
 	tpi->proto = greh->protocol;
 
 	options = (__be32 *)(greh + 1);

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

* Re: [PATCH net-next] ip_gre: fix a possible crash in parse_gre_header()
  2013-04-05  1:41 [PATCH net-next] ip_gre: fix a possible crash in parse_gre_header() Eric Dumazet
@ 2013-04-08 16:01 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2013-04-08 16:01 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev, pshelar

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 04 Apr 2013 18:41:27 -0700

> From: Eric Dumazet <edumazet@google.com>
> 
> pskb_may_pull() can change skb->head, so we must init iph/greh after
> calling it.
> 
> Bug added in commit c54419321455 (GRE: Refactor GRE tunneling code.)
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Applied.

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

end of thread, other threads:[~2013-04-08 16:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-05  1:41 [PATCH net-next] ip_gre: fix a possible crash in parse_gre_header() Eric Dumazet
2013-04-08 16:01 ` David Miller

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