Subject: [PATCH 3.17 100/122] net/ping: handle protocol mismatching scenario

From: Greg Kroah-Hartman <[email-masked]>
Date: Fri, 5 Dec 2014 14:44:34 -0800

3.17-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Jane Zhou <[email-masked]>

commit 91a0b603469069cdcce4d572b7525ffc9fd352a6 upstream.

ping_lookup() may return a wrong sock if sk_buff's and sock's protocols
dont' match. For example, sk_buff's protocol is ETH_P_IPV6, but sock's
sk_family is AF_INET, in that case, if sk->sk_bound_dev_if is zero, a wrong
sock will be returned.
the fix is to "continue" the searching, if no matching, return NULL.

Cc: "David S. Miller" <[email-masked]>
Cc: Alexey Kuznetsov <[email-masked]>
Cc: James Morris <[email-masked]>
Cc: Hideaki YOSHIFUJI <[email-masked]>
Cc: Patrick McHardy <[email-masked]>
Cc: [email-masked]
Signed-off-by: Jane Zhou <[email-masked]>
Signed-off-by: Yiwei Zhao <[email-masked]>
Signed-off-by: David S. Miller <[email-masked]>
Signed-off-by: Greg Kroah-Hartman <[email-masked]>

---
 net/ipv4/ping.c |    2 ++
 1 file changed, 2 insertions(+)

--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -217,6 +217,8 @@ static struct sock *ping_lookup(struct n
 					     &ipv6_hdr(skb)->daddr))
 				continue;
 #endif
+		} else {
+			continue;
 		}
 
 		if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif)