Skip to contentSkip to conversation

ipv4: fix a bug in ping_err().

PATCH In review Li Wei 2 participants 3 messages Feb 21, 2013

Subsystems (2)
lore
Share & tools
lore

Li Wei

author
#0 lore raw

PATCH 1/1 ipv4: fix a bug in ping_err().

We should get 'type' and 'code' from the outer ICMP header.

---
 net/ipv4/ping.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/ping.c +2 -2
index 55c4ee1..2e91006 100644
@@ -322,8 +322,8 @@ void ping_err(struct sk_buff *skb, u32 info)
 	struct iphdr *iph = (struct iphdr *)skb->data;
 	struct icmphdr *icmph = (struct icmphdr *)(skb->data+(iph->ihl<<2));
 	struct inet_sock *inet_sock;
-	int type = icmph->type;
-	int code = icmph->code;
+	int type = icmp_hdr(skb)->type;
+	int code = icmp_hdr(skb)->code;
 	struct net *net = dev_net(skb->dev);
 	struct sock *sk;
 	int harderr;
Signature · 1 line
1.8.0.2
maintainer
#1 lore raw

From: Li Wei <[email protected]>
Date: Thu, 21 Feb 2013 18:09:54 +0800

Quoted 12 lines

We should get 'type' and 'code' from the outer ICMP header.

---
 net/ipv4/ping.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/ping.c +0 -0
index 55c4ee1..2e91006 100644

net/ipv4/ping.c void ping_err(struct sk_buff *skb, u32 info) · line 326

Quoted 7 lines
net/ipv4/ping.c +2 -2
@@ -322,8 +322,8 @@ void ping_err(struct sk_buff *skb, u32 info)
 	struct iphdr *iph = (struct iphdr *)skb->data;
 	struct icmphdr *icmph = (struct icmphdr *)(skb->data+(iph->ihl<<2));
 	struct inet_sock *inet_sock;
-	int type = icmph->type;
-	int code = icmph->code;
+	int type = icmp_hdr(skb)->type;
+	int code = icmp_hdr(skb)->code;

Isn't that the same thing at this point? skb->data points to the outer IPv4 header at this point, doesn't it?

maintainer
#2 lore raw

From: David Miller <[email protected]>
Date: Thu, 21 Feb 2013 13:08:09 -0500 (EST)

Quoted 10 lines

From: Li Wei <[email protected]>
Date: Thu, 21 Feb 2013 18:09:54 +0800

Quoted 7 lines

We should get 'type' and 'code' from the outer ICMP header.

---
 net/ipv4/ping.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 15 lines

net/ipv4/ping.c void ping_err(struct sk_buff *skb, u32 info) · line 326

Quoted 12 lines
net/ipv4/ping.c +2 -2
index 55c4ee1..2e91006 100644
@@ -322,8 +322,8 @@ void ping_err(struct sk_buff *skb, u32 info)
 	struct iphdr *iph = (struct iphdr *)skb->data;
 	struct icmphdr *icmph = (struct icmphdr *)(skb->data+(iph->ihl<<2));
 	struct inet_sock *inet_sock;
-	int type = icmph->type;
-	int code = icmph->code;
+	int type = icmp_hdr(skb)->type;
+	int code = icmp_hdr(skb)->code;

Isn't that the same thing at this point? skb->data points to the outer IPv4 header at this point, doesn't it?

Answering myself...

Obviously it isn't, ip_rcv() __skb_pull()'s the IP header before it calls down into ICMP, so we have to use the transport header here.

Applied and queued up for -stable, thanks.