net: socket: Fix potential spectre v1 gadget in sock_is_registered
authorJeremy Cline <jcline@redhat.com>
Fri, 27 Jul 2018 22:43:02 +0000 (22:43 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sun, 29 Jul 2018 05:43:30 +0000 (22:43 -0700)
'family' can be a user-controlled value, so sanitize it after the bounds
check to avoid speculative out-of-bounds access.

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Jeremy Cline <jcline@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/socket.c

index 4ac3b834cce901d9f30f8af85535c9e0fe0d74af..8c24d5dc4bc8f7f4faab62638e41f6d2ac66a842 100644 (file)
@@ -2690,7 +2690,8 @@ EXPORT_SYMBOL(sock_unregister);
 
 bool sock_is_registered(int family)
 {
-       return family < NPROTO && rcu_access_pointer(net_families[family]);
+       return family < NPROTO &&
+               rcu_access_pointer(net_families[array_index_nospec(family, NPROTO)]);
 }
 
 static int __init sock_init(void)