All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] fs: fix possible Spectre V1 indexing in __close_fd()
@ 2018-12-24 14:26 Greg Hackmann
  2018-12-24 14:40 ` Matthew Wilcox
  0 siblings, 1 reply; 2+ messages in thread
From: Greg Hackmann @ 2018-12-24 14:26 UTC (permalink / raw)
  To: Alexander Viro
  Cc: Omer Tripp, linux-fsdevel, linux-kernel, gregkh, Greg Hackmann, stable

Omer Tripp's analysis of a Spectre V1 gadget in __close_fd():

"1.  __close_fd() is reachable via the close() syscall with a
     user-controlled fd.

 2.  If said bounds check is mispredicted, then a user-controlled
     address fdt->fd[fd] is obtained then dereferenced, and the value of
     a user-controlled address is loaded into the local variable file.

 3.  file is then passed as an argument to filp_close, where the cache
     lines secret + offsetof(f_op) and secret + offsetof(f_mode) are hot
     and vulnerable to a timing channel attack."

Address this by using array_index_nospec() to prevent speculation past
the end of current->fdt.

Reported-by: Omer Tripp <trippo@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Hackmann <ghackmann@android.com>
---
v2: include Omer Tripp's analysis in commit message, and update my email
    address

 fs/file.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/file.c b/fs/file.c
index 7ffd6e9d103d..a80cf82be96b 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -18,6 +18,7 @@
 #include <linux/bitops.h>
 #include <linux/spinlock.h>
 #include <linux/rcupdate.h>
+#include <linux/nospec.h>
 
 unsigned int sysctl_nr_open __read_mostly = 1024*1024;
 unsigned int sysctl_nr_open_min = BITS_PER_LONG;
@@ -626,6 +627,7 @@ int __close_fd(struct files_struct *files, unsigned fd)
 	fdt = files_fdtable(files);
 	if (fd >= fdt->max_fds)
 		goto out_unlock;
+	fd = array_index_nospec(fd, fdt->max_fds);
 	file = fdt->fd[fd];
 	if (!file)
 		goto out_unlock;
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] fs: fix possible Spectre V1 indexing in __close_fd()
  2018-12-24 14:26 [PATCH v2] fs: fix possible Spectre V1 indexing in __close_fd() Greg Hackmann
@ 2018-12-24 14:40 ` Matthew Wilcox
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2018-12-24 14:40 UTC (permalink / raw)
  To: Greg Hackmann
  Cc: Alexander Viro, Omer Tripp, linux-fsdevel, linux-kernel, gregkh, stable

On Mon, Dec 24, 2018 at 06:26:42AM -0800, Greg Hackmann wrote:
> +++ b/fs/file.c
> @@ -18,6 +18,7 @@
>  #include <linux/bitops.h>
>  #include <linux/spinlock.h>
>  #include <linux/rcupdate.h>
> +#include <linux/nospec.h>
>  
>  unsigned int sysctl_nr_open __read_mostly = 1024*1024;
>  unsigned int sysctl_nr_open_min = BITS_PER_LONG;
> @@ -626,6 +627,7 @@ int __close_fd(struct files_struct *files, unsigned fd)
>  	fdt = files_fdtable(files);
>  	if (fd >= fdt->max_fds)
>  		goto out_unlock;
> +	fd = array_index_nospec(fd, fdt->max_fds);
>  	file = fdt->fd[fd];
>  	if (!file)
>  		goto out_unlock;

This is insufficient.  do_dup2() has a similar problem.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-12-24 14:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-24 14:26 [PATCH v2] fs: fix possible Spectre V1 indexing in __close_fd() Greg Hackmann
2018-12-24 14:40 ` Matthew Wilcox

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.