All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>
Subject: [PATCH] statfs: fix potential Spectre v1
Date: Wed, 15 Aug 2018 08:36:08 -0500	[thread overview]
Message-ID: <20180815133608.GA27979@embeddedor.com> (raw)

user_params.request is indirectly controlled by user-space, hence leading
to a potential exploitation of the Spectre variant 1 vulnerability.

This issue was detected with the help of Smatch:

fs/statfs.c:908 __do_sys_fsinfo() warn: potential spectre issue
'fsinfo_buffer_sizes' [r]

Fix this by sanitizing user_params.request before using it to index
fsinfo_buffer_sizes

Notice that given that speculation windows are large, the policy is
to kill the speculation on the first load and not worry if it can be
completed with a dependent load/store [1].

[1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2

Cc: stable@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 fs/statfs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/statfs.c b/fs/statfs.c
index f714f05..d74a60a 100644
--- a/fs/statfs.c
+++ b/fs/statfs.c
@@ -11,6 +11,7 @@
 #include <linux/compat.h>
 #include <linux/fsinfo.h>
 #include <linux/fs_parser.h>
+#include <linux/nospec.h>
 #include "internal.h"
 
 static int flags_by_mnt(int mnt_flags)
@@ -886,6 +887,8 @@ SYSCALL_DEFINE5(fsinfo,
 			return -EINVAL;
 		if (user_params.request >= FSINFO_ATTR__NR)
 			return -EOPNOTSUPP;
+		user_params.request = array_index_nospec(user_params.request,
+							 FSINFO_ATTR__NR);
 		params.at_flags = user_params.at_flags;
 		params.request = user_params.request;
 		params.Nth = user_params.Nth;
-- 
2.7.4

                 reply	other threads:[~2018-08-15 13:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20180815133608.GA27979@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.