Commit cd0fb1cb authored by Jeremy Cline's avatar Jeremy Cline Committed by Greg Kroah-Hartman
Browse files

net: sock_diag: Fix spectre v1 gadget in __sock_diag_cmd()

[ Upstream commit 66b51b0a ]

req->sdiag_family is a user-controlled value that's used as an array
index. Sanitize it after the bounds check to avoid speculative
out-of-bounds array access.

This also protects the sock_is_registered() call, so this removes the
sanitize call there.

Fixes: e978de7a

 ("net: socket: Fix potential spectre v1 gadget in sock_is_registered")
Cc: Josh Poimboeuf <>
Signed-off-by: default avatarJeremy Cline <>
Signed-off-by: default avatarDavid S. Miller <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent 3909ccf1
......@@ -10,6 +10,7 @@
#include <linux/kernel.h>
#include <linux/tcp.h>
#include <linux/workqueue.h>
#include <linux/nospec.h>
#include <linux/inet_diag.h>
#include <linux/sock_diag.h>
......@@ -218,6 +219,7 @@ static int __sock_diag_cmd(struct sk_buff *skb, struct nlmsghdr *nlh)
if (req->sdiag_family >= AF_MAX)
return -EINVAL;
req->sdiag_family = array_index_nospec(req->sdiag_family, AF_MAX);
if (sock_diag_handlers[req->sdiag_family] == NULL)
sock_load_diag_module(req->sdiag_family, 0);
......@@ -2690,8 +2690,7 @@ EXPORT_SYMBOL(sock_unregister);
bool sock_is_registered(int family)
return family < NPROTO &&
rcu_access_pointer(net_families[array_index_nospec(family, NPROTO)]);
return family < NPROTO && rcu_access_pointer(net_families[family]);
static int __init sock_init(void)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment