Commit cc12f35b authored by Jeremy Cline's avatar Jeremy Cline Committed by Kleber Sacilotto de Souza

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

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 <jpoimboe@redhat.com>
Cc: konrad.wilk@oracle.com
Cc: jamie.iles@oracle.com
Cc: liran.alon@oracle.com
Cc: stable@vger.kernel.org
Signed-off-by: default avatarJeremy Cline <jcline@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>

CVE-2017-5753

(backported from commit 66b51b0a)
[juergh: Adjusted for missing sock_is_registered().]
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Acked-by: default avatarStefan Bader <stefan.bader@canonical.com>
Acked-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 8ee7e2b8
......@@ -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>
......@@ -225,6 +226,7 @@ static int __sock_diag_rcv_msg(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)
request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
......
......@@ -2428,14 +2428,11 @@ int sock_register(const struct net_proto_family *ops)
}
spin_lock(&net_family_lock);
if (rcu_dereference_protected(
net_families[array_index_nospec(ops->family, NPROTO)],
lockdep_is_held(&net_family_lock)))
if (rcu_dereference_protected(net_families[ops->family],
lockdep_is_held(&net_family_lock)))
err = -EEXIST;
else {
rcu_assign_pointer(
net_families[array_index_nospec(ops->family, NPROTO)],
ops);
rcu_assign_pointer(net_families[ops->family], ops);
err = 0;
}
spin_unlock(&net_family_lock);
......
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