diff options
author | Jeremy Cline <jcline@redhat.com> | 2018-08-13 18:23:13 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-08-14 13:01:24 -0400 |
commit | 66b51b0a0341fd42ce657739bdae0561b0410a85 (patch) | |
tree | fd78fd9cb07be5628896380c282ab7d0e841d7d8 /net/core/sock_diag.c | |
parent | 1c89a8e3d9a235454169e189ea6c463bfa8749ab (diff) |
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: e978de7a6d38 ("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: Jeremy Cline <jcline@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/sock_diag.c')
-rw-r--r-- | net/core/sock_diag.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c index c37b5be7c5e4..3312a5849a97 100644 --- a/net/core/sock_diag.c +++ b/net/core/sock_diag.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/kernel.h> | 10 | #include <linux/kernel.h> |
11 | #include <linux/tcp.h> | 11 | #include <linux/tcp.h> |
12 | #include <linux/workqueue.h> | 12 | #include <linux/workqueue.h> |
13 | #include <linux/nospec.h> | ||
13 | 14 | ||
14 | #include <linux/inet_diag.h> | 15 | #include <linux/inet_diag.h> |
15 | #include <linux/sock_diag.h> | 16 | #include <linux/sock_diag.h> |
@@ -218,6 +219,7 @@ static int __sock_diag_cmd(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
218 | 219 | ||
219 | if (req->sdiag_family >= AF_MAX) | 220 | if (req->sdiag_family >= AF_MAX) |
220 | return -EINVAL; | 221 | return -EINVAL; |
222 | req->sdiag_family = array_index_nospec(req->sdiag_family, AF_MAX); | ||
221 | 223 | ||
222 | if (sock_diag_handlers[req->sdiag_family] == NULL) | 224 | if (sock_diag_handlers[req->sdiag_family] == NULL) |
223 | sock_load_diag_module(req->sdiag_family, 0); | 225 | sock_load_diag_module(req->sdiag_family, 0); |