Received: by 10.223.176.46 with SMTP id f43csp207466wra; Thu, 18 Jan 2018 16:15:16 -0800 (PST) X-Google-Smtp-Source: ACJfBoumuyQMc+X+bveFwd1tiJGKyqLxf77NkgwfBzekVGUn6BDY6MVvAjCF1UZU4tWzWYpj8ItG X-Received: by 10.98.17.21 with SMTP id z21mr20291387pfi.86.1516320916658; Thu, 18 Jan 2018 16:15:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516320916; cv=none; d=google.com; s=arc-20160816; b=YtC40Pj92sBenRUYPvLhm8/mBcINOkRfxp8D5MMt6dRBHTdZ15WGJry7hHBFDvhP62 hnjApNeAXFFQwRvMvfqjfg1rneD39GhSQ39dvuLcJF2QAX2EV7xNofTfT1/F0kGtePua qJzeer8fI0P31nP77gtHP0hN+6DzO2ezEGwUOtwGGRjWBD0fq9FbfSLd2bg3HKaTYK+/ 8GfrKhEkj9JJ5DgTQmnYuAMl6LDDdzLbR6kDAadr1lFehwgTLUtVWkwA+rNt8reLId/e hVqQHquud+jJcVA69XXu4C5ftbukqtg/XILXhFLeFoiWo3s2/XWS676VltXPPlYtXLOX uZ7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:arc-authentication-results; bh=rA7sUqHYtInQspx0EnQDAI/iz7WHlJoZ5dQKdVqhNDU=; b=vNfs9hM/TY+9T8VisbeKgPn/r8D0eeontV3lfdt+VuulRFPKxYH0lPD5q4/AEZ+Hut d+KraKGsY1o7q2i4VhGXbkRzo8zJiLd+0EgHX3XQ5EJinlKzp8tMIZdNHsNnG174qcRW GnUrEfqT0o/lXFjjeEBzOMBS2uS4fStcvWoxzWpotHOsgNoh9VeoVsxvKa3WL+TJGLmn jEoPJMIgIQgkfMOKy0pOqri2S/jXQMVCC35kpBdlrJOsnbHbmAZwnoKKX+/pX+5tL6L6 j3OGws93KE535CdlSi/67IegaaP02CT88UlKZUrhK4x06jSeXc1uXLaL4bTjg7g/5dEm ALKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7si6961583pgp.583.2018.01.18.16.15.02; Thu, 18 Jan 2018 16:15:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932913AbeASAM4 (ORCPT + 99 others); Thu, 18 Jan 2018 19:12:56 -0500 Received: from mga01.intel.com ([192.55.52.88]:44709 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755285AbeASALc (ORCPT ); Thu, 18 Jan 2018 19:11:32 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jan 2018 16:11:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,379,1511856000"; d="scan'208";a="11726507" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga006.jf.intel.com with ESMTP; 18 Jan 2018 16:11:31 -0800 Subject: [PATCH v4 08/10] vfs, fdtable: prevent bounds-check bypass via speculative execution From: Dan Williams To: linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org, kernel-hardening@lists.openwall.com, gregkh@linuxfoundation.org, Al Viro , tglx@linutronix.de, torvalds@linux-foundation.org, akpm@linux-foundation.org, alan@linux.intel.com Date: Thu, 18 Jan 2018 16:02:26 -0800 Message-ID: <151632014611.21271.2373946384226391096.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <151632009605.21271.11304291057104672116.stgit@dwillia2-desk3.amr.corp.intel.com> References: <151632009605.21271.11304291057104672116.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org '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. Cc: Al Viro Co-developed-by: Elena Reshetova Signed-off-by: Dan Williams --- include/linux/fdtable.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h index 1c65817673db..9731f1a255db 100644 --- a/include/linux/fdtable.h +++ b/include/linux/fdtable.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -81,9 +82,11 @@ struct dentry; static inline struct file *__fcheck_files(struct files_struct *files, unsigned int fd) { struct fdtable *fdt = rcu_dereference_raw(files->fdt); + struct file __rcu **fdp; - if (fd < fdt->max_fds) - return rcu_dereference_raw(fdt->fd[fd]); + fdp = array_ptr(fdt->fd, fd, fdt->max_fds); + if (fdp) + return rcu_dereference_raw(*fdp); return NULL; }