linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeremy Cline <jcline@redhat.com>
To: "David S . Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Jeremy Cline <jcline@redhat.com>,
	stable@vger.kernel.org
Subject: [PATCH 1/2] net: socket: fix potential spectre v1 gadget in socketcall
Date: Fri, 27 Jul 2018 22:43:01 +0000	[thread overview]
Message-ID: <20180727224302.5503-2-jcline@redhat.com> (raw)
In-Reply-To: <20180727224302.5503-1-jcline@redhat.com>

'call' is a user-controlled value, so sanitize the array index after the
bounds check to avoid speculating past the bounds of the 'nargs' array.

Found with the help of Smatch:

net/socket.c:2508 __do_sys_socketcall() warn: potential spectre issue
'nargs' [r] (local cap)

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Jeremy Cline <jcline@redhat.com>
---
 net/socket.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/socket.c b/net/socket.c
index 3015ddace71e..f15d5cbb3ba4 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -89,6 +89,7 @@
 #include <linux/magic.h>
 #include <linux/slab.h>
 #include <linux/xattr.h>
+#include <linux/nospec.h>
 
 #include <linux/uaccess.h>
 #include <asm/unistd.h>
@@ -2504,6 +2505,7 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args)
 
 	if (call < 1 || call > SYS_SENDMMSG)
 		return -EINVAL;
+	call = array_index_nospec(call, SYS_SENDMMSG + 1);
 
 	len = nargs[call];
 	if (len > sizeof(a))
-- 
2.17.1


  reply	other threads:[~2018-07-27 22:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-27 22:43 [PATCH 0/2] net: socket: Fix potential spectre v1 gadgets Jeremy Cline
2018-07-27 22:43 ` Jeremy Cline [this message]
2018-07-29 13:59   ` [PATCH 1/2] net: socket: fix potential spectre v1 gadget in socketcall Josh Poimboeuf
2018-07-27 22:43 ` [PATCH 2/2] net: socket: Fix potential spectre v1 gadget in sock_is_registered Jeremy Cline
2018-07-29 13:59   ` Josh Poimboeuf
2018-07-29 15:59     ` Jeremy Cline
2018-08-13 17:16       ` Josh Poimboeuf
2018-08-13 19:03         ` Jeremy Cline
2018-07-29  5:45 ` [PATCH 0/2] net: socket: Fix potential spectre v1 gadgets David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180727224302.5503-2-jcline@redhat.com \
    --to=jcline@redhat.com \
    --cc=davem@davemloft.net \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).