6234eba
From a963a37d384d71ad43b3e9e79d68d42fbe0901f3 Mon Sep 17 00:00:00 2001
6234eba
From: Eric Dumazet <edumazet@google.com>
6234eba
Date: Wed, 26 Jun 2013 04:15:07 -0700
6234eba
Subject: [PATCH] ipv6: ip6_sk_dst_check() must not assume ipv6 dst
6234eba
6234eba
It's possible to use AF_INET6 sockets and to connect to an IPv4
6234eba
destination. After this, socket dst cache is a pointer to a rtable,
6234eba
not rt6_info.
6234eba
6234eba
ip6_sk_dst_check() should check the socket dst cache is IPv6, or else
6234eba
various corruptions/crashes can happen.
6234eba
6234eba
Dave Jones can reproduce immediate crash with
6234eba
trinity -q -l off -n -c sendmsg -c connect
6234eba
6234eba
With help from Hannes Frederic Sowa
6234eba
6234eba
Reported-by: Dave Jones <davej@redhat.com>
6234eba
Reported-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
6234eba
Signed-off-by: Eric Dumazet <edumazet@google.com>
6234eba
Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
6234eba
Signed-off-by: David S. Miller <davem@davemloft.net>
6234eba
---
6234eba
 net/ipv6/ip6_output.c | 8 +++++++-
6234eba
 1 file changed, 7 insertions(+), 1 deletion(-)
6234eba
6234eba
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
6234eba
index 95703ba..d5d20cd 100644
6234eba
--- a/net/ipv6/ip6_output.c
6234eba
+++ b/net/ipv6/ip6_output.c
6234eba
@@ -821,11 +821,17 @@ static struct dst_entry *ip6_sk_dst_check(struct sock *sk,
6234eba
 					  const struct flowi6 *fl6)
6234eba
 {
6234eba
 	struct ipv6_pinfo *np = inet6_sk(sk);
6234eba
-	struct rt6_info *rt = (struct rt6_info *)dst;
6234eba
+	struct rt6_info *rt;
6234eba
 
6234eba
 	if (!dst)
6234eba
 		goto out;
6234eba
 
6234eba
+	if (dst->ops->family != AF_INET6) {
6234eba
+		dst_release(dst);
6234eba
+		return NULL;
6234eba
+	}
6234eba
+
6234eba
+	rt = (struct rt6_info *)dst;
6234eba
 	/* Yes, checking route validity in not connected
6234eba
 	 * case is not very simple. Take into account,
6234eba
 	 * that we do not support routing by source, TOS,
6234eba
-- 
6234eba
1.8.2.1
6234eba