Skip to content

Commit

Permalink
net: socket: Fix potential spectre v1 gadget in sock_is_registered
Browse files Browse the repository at this point in the history
'family' can be a user-controlled value, so sanitize it after the bounds
check to avoid speculative out-of-bounds access.

Cc: Josh Poimboeuf <[email protected]>
Cc: [email protected]
Signed-off-by: Jeremy Cline <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jeremycline authored and davem330 committed Jul 29, 2018
1 parent c8e8cd5 commit e978de7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e978de7

Please sign in to comment.