Skip to content

Commit

Permalink
netlink: Fix spectre v1 gadget in netlink_create()
Browse files Browse the repository at this point in the history
[ Upstream commit bc5b6c0 ]

'protocol' is a user-controlled value, so sanitize it after the bounds
check to avoid using it for speculative out-of-bounds access to arrays
indexed by it.

This addresses the following accesses detected with the help of smatch:

* net/netlink/af_netlink.c:654 __netlink_create() warn: potential
  spectre issue 'nlk_cb_mutex_keys' [w]

* net/netlink/af_netlink.c:654 __netlink_create() warn: potential
  spectre issue 'nlk_cb_mutex_key_strings' [w]

* net/netlink/af_netlink.c:685 netlink_create() warn: potential spectre
  issue 'nl_table' [w] (local cap)

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Jeremy Cline <jcline@redhat.com>
Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jeremy Cline authored and Greg Kroah-Hartman committed Aug 6, 2018
1 parent b5fef54 commit 8cac0ce
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions net/netlink/af_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#include <asm/cacheflush.h>
#include <linux/hash.h>
#include <linux/genetlink.h>
#include <linux/nospec.h>

#include <net/net_namespace.h>
#include <net/sock.h>
Expand Down Expand Up @@ -654,6 +655,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol,

if (protocol < 0 || protocol >= MAX_LINKS)
return -EPROTONOSUPPORT;
protocol = array_index_nospec(protocol, MAX_LINKS);

netlink_lock_table();
#ifdef CONFIG_MODULES
Expand Down

0 comments on commit 8cac0ce

Please sign in to comment.