]> git.hungrycats.org Git - linux/commitdiff
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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 6 Aug 2018 14:18:20 +0000 (16:18 +0200)
commit e978de7a6d382ec378830ca2cf38e902df0b6d84 upstream.

'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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/socket.c

index 0316b380389e46ad2df9775cc9ffc78b083af920..6a6aa84b64c17a2cbb6ec3d1f4f51cbe737b3f71 100644 (file)
@@ -2694,7 +2694,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)