Skip to content

Commit bb5899c

Browse files
jeremyclineZhengShunQian
authored andcommitted
netlink: Fix spectre v1 gadget in netlink_create()
[ 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 <[email protected]> Signed-off-by: Jeremy Cline <[email protected]> Reviewed-by: Josh Poimboeuf <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 257f54c commit bb5899c

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

net/netlink/af_netlink.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include <asm/cacheflush.h>
6363
#include <linux/hash.h>
6464
#include <linux/genetlink.h>
65+
#include <linux/nospec.h>
6566

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

655656
if (protocol < 0 || protocol >= MAX_LINKS)
656657
return -EPROTONOSUPPORT;
658+
protocol = array_index_nospec(protocol, MAX_LINKS);
657659

658660
netlink_lock_table();
659661
#ifdef CONFIG_MODULES

0 commit comments

Comments
 (0)