From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-f194.google.com ([209.85.215.194]:39912 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729176AbeIYATy (ORCPT ); Mon, 24 Sep 2018 20:19:54 -0400 Received: by mail-pg1-f194.google.com with SMTP id 85-v6so6452210pge.6 for ; Mon, 24 Sep 2018 11:16:30 -0700 (PDT) From: Greg Hackmann To: Alexander Viro Cc: Omer Tripp , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Hackmann , stable@vger.kernel.org Subject: [PATCH] fs: fix possible Spectre V1 indexing in __close_fd() Date: Mon, 24 Sep 2018 11:15:00 -0700 Message-Id: <20180924181500.125257-1-ghackmann@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-fsdevel-owner@vger.kernel.org List-ID: __close_fd() is reachable via the close() syscall with a userspace-controlled fd. Ensure that it can't be used to speculatively access past the end of current->fdt. Reported-by: Omer Tripp Cc: stable@vger.kernel.org Signed-off-by: Greg Hackmann --- 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.0.397.gdd90340f6a-goog