From patchwork Fri Feb 23 10:42:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 10237447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7364F602DC for ; Fri, 23 Feb 2018 11:25:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 664B729530 for ; Fri, 23 Feb 2018 11:25:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5767F29505; Fri, 23 Feb 2018 11:25:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 51C2C29505 for ; Fri, 23 Feb 2018 11:25:39 +0000 (UTC) Received: (qmail 18401 invoked by uid 550); 23 Feb 2018 11:23:05 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 5366 invoked from network); 23 Feb 2018 10:42:50 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profitbricks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WBjvIMFX0iglmu4LyG0rds0QKA8m0SA8ry9XpJw/b5w=; b=hThb0/evKkB5WGS438XenVdoUKpUlpro2VUK2WtkdFINLJMAMtlkAejcc416Y3hPUU hMd3OHHfGRs4uyP0l58Myu8x61gw10reYxfzAkA24qhlz75iWU8KDJvNn7ZYHgIkq8TO ijWCeY3VMDPkezcGESKn+vkanWqN2HXLh50xfqd0KUDARsVJwR9D4/W0IyNt06HFwkam Pg+f6UBBswHOB5vcdusa3c9RoFoOWurcanbixhCtBJY+3n1wHcQhE+dTpR70J+9Q4zpu OouHao/EVVE52cvZpQ4uqv5EjgHKznim6ROxmDUPpoSMWb3VYpjbGBqtWLB08TJxHKTI 4zMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WBjvIMFX0iglmu4LyG0rds0QKA8m0SA8ry9XpJw/b5w=; b=QIK+pK2MfV90Qin5vOLIS0m9JyHhNBKQqOCFHemTiiaaBm0t53X9cmkghvkvVzmAG8 agTAkKnGNmrBOUqOTk3wXGQ/H+JINnsuR67mzg9KP9WEmxtDBCLSWR8++YWzLDE5U5+S +hfRcx3Ev22rjej43Y6uRFj4lHcO45R2exEzOgEyXTtfMqD+UWfYZlK3v+7MrFLgDt/t 91H2me+PjnsdUHdvT6NqrkgvPRYN+jsyiqY4/CKEinL2SeO7iXWSAplPi+3H2SMCInmo nXNsMv/7++9ooWYPXa+HbEnW3XzIB5Tdlozq3k9d5C73xk6DpVKdRpWjA7Wyl22h/0U8 +ATw== X-Gm-Message-State: APf1xPCQwryh44V4VgD/R6TXUsyg8aKVPZADb7+xcp6GeJWEz7hl0SYQ 8BRQ5RZwNujCCiEZpRyn1xU1QA== X-Google-Smtp-Source: AG47ELsz5+opXsdl6rUfCUSYS9n/oljnrjKVcSZDd0ZOOdp2AlgAF5Hcy0oDNA60N/7NkplcFlraJA== X-Received: by 10.28.184.8 with SMTP id i8mr1456647wmf.52.1519382559522; Fri, 23 Feb 2018 02:42:39 -0800 (PST) From: Jack Wang X-Google-Original-From: Jack Wang To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Dan Williams , Thomas Gleixner , linux-arch@vger.kernel.org, kernel-hardening@lists.openwall.com, Al Viro , torvalds@linux-foundation.org, alan@linux.intel.com, David Woodhouse , Jack Wang Subject: [stable 4.4 16/29] vfs, fdtable: Prevent bounds-check bypass via speculative execution Date: Fri, 23 Feb 2018 11:42:05 +0100 Message-Id: <1519382538-15143-17-git-send-email-jinpu.wangl@profitbricks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519382538-15143-1-git-send-email-jinpu.wangl@profitbricks.com> References: <1519382538-15143-1-git-send-email-jinpu.wangl@profitbricks.com> X-Virus-Scanned: ClamAV using ClamSMTP From: Dan Williams (cherry picked from commit 56c30ba7b348b90484969054d561f711ba196507) 'fd' is a user controlled value that is used as a data dependency to read from the 'fdt->fd' array. In order to avoid potential leaks of kernel memory values, block speculative execution of the instruction stream that could issue reads based on an invalid 'file *' returned from __fcheck_files. Co-developed-by: Elena Reshetova Signed-off-by: Dan Williams Signed-off-by: Thomas Gleixner Cc: linux-arch@vger.kernel.org Cc: kernel-hardening@lists.openwall.com Cc: gregkh@linuxfoundation.org Cc: Al Viro Cc: torvalds@linux-foundation.org Cc: alan@linux.intel.com Link: https://lkml.kernel.org/r/151727418500.33451.17392199002892248656.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman [jwang: cherry pick to 4.4] Signed-off-by: Jack Wang --- include/linux/fdtable.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h index 5295535..a7b7a05 100644 --- a/include/linux/fdtable.h +++ b/include/linux/fdtable.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -81,8 +82,10 @@ static inline struct file *__fcheck_files(struct files_struct *files, unsigned i { struct fdtable *fdt = rcu_dereference_raw(files->fdt); - if (fd < fdt->max_fds) + if (fd < fdt->max_fds) { + fd = array_index_nospec(fd, fdt->max_fds); return rcu_dereference_raw(fdt->fd[fd]); + } return NULL; }