netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ipv4/ip_gre: make ipgre_tunnel_xmit() not parse network header as IP unconditionally
@ 2012-12-21  1:12 Isaku Yamahata
  2012-12-21  1:48 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Isaku Yamahata @ 2012-12-21  1:12 UTC (permalink / raw)
  To: netdev; +Cc: yamahata

ipgre_tunnel_xmit() parses network header as IP unconditionally.
But transmitting packets are not always IP packet. For example such packet
can be sent by packet socket with sockaddr_ll.sll_protocol set.
So make the function check if skb->protocol is IP.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 net/ipv4/ip_gre.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index a85ae2f..8fcf0ed 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -760,7 +760,10 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
 
 	if (dev->header_ops && dev->type == ARPHRD_IPGRE) {
 		gre_hlen = 0;
-		tiph = (const struct iphdr *)skb->data;
+		if (skb->protocol == htons(ETH_P_IP))
+			tiph = (const struct iphdr *)skb->data;
+		else
+			tiph = &tunnel->parms.iph;
 	} else {
 		gre_hlen = tunnel->hlen;
 		tiph = &tunnel->parms.iph;
-- 
1.7.10.4

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

* Re: [PATCH] ipv4/ip_gre: make ipgre_tunnel_xmit() not parse network header as IP unconditionally
  2012-12-21  1:12 [PATCH] ipv4/ip_gre: make ipgre_tunnel_xmit() not parse network header as IP unconditionally Isaku Yamahata
@ 2012-12-21  1:48 ` Eric Dumazet
  2012-12-21 21:15   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2012-12-21  1:48 UTC (permalink / raw)
  To: Isaku Yamahata; +Cc: netdev

On Fri, 2012-12-21 at 10:12 +0900, Isaku Yamahata wrote:
> ipgre_tunnel_xmit() parses network header as IP unconditionally.
> But transmitting packets are not always IP packet. For example such packet
> can be sent by packet socket with sockaddr_ll.sll_protocol set.
> So make the function check if skb->protocol is IP.
> 
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
> ---
>  net/ipv4/ip_gre.c |    5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
> index a85ae2f..8fcf0ed 100644
> --- a/net/ipv4/ip_gre.c
> +++ b/net/ipv4/ip_gre.c
> @@ -760,7 +760,10 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
>  
>  	if (dev->header_ops && dev->type == ARPHRD_IPGRE) {
>  		gre_hlen = 0;
> -		tiph = (const struct iphdr *)skb->data;
> +		if (skb->protocol == htons(ETH_P_IP))
> +			tiph = (const struct iphdr *)skb->data;
> +		else
> +			tiph = &tunnel->parms.iph;
>  	} else {
>  		gre_hlen = tunnel->hlen;
>  		tiph = &tunnel->parms.iph;

Seems good to me thanks !

Acked-by: Eric Dumazet <edumazet@google.com>

BTW, it seems another bug exists at line 931 : We dereference tiph while
it could point to freed memory because of the skb_realloc_headroom() at
line 893

I'll send a patch.

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

* Re: [PATCH] ipv4/ip_gre: make ipgre_tunnel_xmit() not parse network header as IP unconditionally
  2012-12-21  1:48 ` Eric Dumazet
@ 2012-12-21 21:15   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2012-12-21 21:15 UTC (permalink / raw)
  To: eric.dumazet; +Cc: yamahata, netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 20 Dec 2012 17:48:41 -0800

> On Fri, 2012-12-21 at 10:12 +0900, Isaku Yamahata wrote:
>> ipgre_tunnel_xmit() parses network header as IP unconditionally.
>> But transmitting packets are not always IP packet. For example such packet
>> can be sent by packet socket with sockaddr_ll.sll_protocol set.
>> So make the function check if skb->protocol is IP.
>> 
>> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
>> ---
>>  net/ipv4/ip_gre.c |    5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>> 
>> diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
>> index a85ae2f..8fcf0ed 100644
>> --- a/net/ipv4/ip_gre.c
>> +++ b/net/ipv4/ip_gre.c
>> @@ -760,7 +760,10 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
>>  
>>  	if (dev->header_ops && dev->type == ARPHRD_IPGRE) {
>>  		gre_hlen = 0;
>> -		tiph = (const struct iphdr *)skb->data;
>> +		if (skb->protocol == htons(ETH_P_IP))
>> +			tiph = (const struct iphdr *)skb->data;
>> +		else
>> +			tiph = &tunnel->parms.iph;
>>  	} else {
>>  		gre_hlen = tunnel->hlen;
>>  		tiph = &tunnel->parms.iph;
> 
> Seems good to me thanks !
> 
> Acked-by: Eric Dumazet <edumazet@google.com>

Applied.

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

end of thread, other threads:[~2012-12-21 21:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-21  1:12 [PATCH] ipv4/ip_gre: make ipgre_tunnel_xmit() not parse network header as IP unconditionally Isaku Yamahata
2012-12-21  1:48 ` Eric Dumazet
2012-12-21 21:15   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).