From: Theodore Ts'o Date: Mon, 6 Mar 2023 18:54:50 +0000 (-0500) Subject: fs: prevent out-of-bounds array speculation when closing a file descriptor X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=f8cd8754a03a3748384ee438c572423643c9c315;p=linux.git fs: prevent out-of-bounds array speculation when closing a file descriptor commit 609d54441493c99f21c1823dfd66fa7f4c512ff4 upstream. Google-Bug-Id: 114199369 Signed-off-by: Theodore Ts'o Signed-off-by: Al Viro Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/file.c b/fs/file.c index 214364e19d76f..ee1c350ec58a2 100644 --- a/fs/file.c +++ b/fs/file.c @@ -646,6 +646,7 @@ static struct file *pick_file(struct files_struct *files, unsigned fd) file = ERR_PTR(-EINVAL); goto out_unlock; } + fd = array_index_nospec(fd, fdt->max_fds); file = fdt->fd[fd]; if (!file) { file = ERR_PTR(-EBADF);