From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-f195.google.com ([209.85.214.195]:34126 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725601AbeLXO06 (ORCPT ); Mon, 24 Dec 2018 09:26:58 -0500 Received: by mail-pl1-f195.google.com with SMTP id w4so5657294plz.1 for ; Mon, 24 Dec 2018 06:26:58 -0800 (PST) From: Greg Hackmann To: Alexander Viro Cc: Omer Tripp , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, Greg Hackmann , stable@vger.kernel.org Subject: [PATCH v2] fs: fix possible Spectre V1 indexing in __close_fd() Date: Mon, 24 Dec 2018 06:26:42 -0800 Message-Id: <20181224142642.7385-1-ghackmann@android.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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 Cc: stable@vger.kernel.org Signed-off-by: Greg Hackmann --- 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 #include #include +#include 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