Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netlink: Fix spectre v1 gadget in netlink_create()

'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>

authored by

Jeremy Cline and committed by
David S. Miller
bc5b6c0b e02ee981

+2
+2
net/netlink/af_netlink.c
··· 63 63 #include <linux/hash.h> 64 64 #include <linux/genetlink.h> 65 65 #include <linux/net_namespace.h> 66 + #include <linux/nospec.h> 66 67 67 68 #include <net/net_namespace.h> 68 69 #include <net/netns/generic.h> ··· 680 679 681 680 if (protocol < 0 || protocol >= MAX_LINKS) 682 681 return -EPROTONOSUPPORT; 682 + protocol = array_index_nospec(protocol, MAX_LINKS); 683 683 684 684 netlink_lock_table(); 685 685 #ifdef CONFIG_MODULES