Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2934577imm; Mon, 24 Sep 2018 12:31:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV61EqhlP7o4u7rYOORn/C4PmC23L10LMUI+ZoXaWDle+C922x5VuTCoZB01XS2FH61uUGBHl X-Received: by 2002:a65:448a:: with SMTP id l10-v6mr215103pgq.382.1537817493248; Mon, 24 Sep 2018 12:31:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537817493; cv=none; d=google.com; s=arc-20160816; b=l6GE8S+/dGQWFs8HfvJe0qbMOU0V92RgsmuEb6fjbaJDn3mB3voYrINtpcuS4WfsUb dxiw+o2cKLIfLthIPzMkCrdg433SsW1/qNjTUQ0TwhSqXIwQCnV8FmElqhygchyBC1m2 AQYTokOTF7vw+y31hS2AwKwFW3zvLtolNJ32bJ6AgB+RFsolLWpPhWhEkfgN5BxL5R8F 5/mMHGWC0IueMk84L16Qm6VURbfVGR2Q3waHp9BvaHINEPcGk///9/QoCFkPy7pq/j0g 6GG56yM17w+Un8jNK7wUuQ1nZ/iSwXkU/axQXz61a8j7kpEXz91BFpxZ/0LIP82y+lWp DsBQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=pwPxX45gZm6RhM5vkMPVW/U8WnPtyGy8RjrhrRy6BQg=; b=UhYeXn1+gAQ0/MmOM6gX4D8hdDWGnDgzU0Bw0QBzX+xkjmhofTvMSWiX+XEZj94/F9 crKtrJSLIv/dQFfFGo1cQqR+wuWVDukctrqdQLZJljdXK412CbMrtW75l8CaMUFJbJVm EZ1TXZadf36YIg4ojJY531fJ7DIH1xPatrp/5i1N4s3eu0LcXTjYPvf8/uqWnWaz66Dq EnQinngLlFT8uD/aIyIlX0JfGsQf+IRGD4r0bhsQ5DtwjooBeedN/VWgsqbqTzSZQFyX yKBsywb5kQMx+6ISWP52a8I/eDsMk9OQSiwqwncvVTH1G3+x08+iehEyGgc3GVSfniG3 r55w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b="fID3/n1o"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 78-v6si135154pfm.264.2018.09.24.12.30.39; Mon, 24 Sep 2018 12:31:33 -0700 (PDT) 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; dkim=pass header.i=@android.com header.s=20161025 header.b="fID3/n1o"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732268AbeIYATz (ORCPT + 99 others); Mon, 24 Sep 2018 20:19:55 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:45349 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730407AbeIYATy (ORCPT ); Mon, 24 Sep 2018 20:19:54 -0400 Received: by mail-pf1-f196.google.com with SMTP id a23-v6so1691706pfi.12 for ; Mon, 24 Sep 2018 11:16:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=pwPxX45gZm6RhM5vkMPVW/U8WnPtyGy8RjrhrRy6BQg=; b=fID3/n1o/jp9PG1h69DDVj4VLN8kHopsqh78fV9/OyBY/nD//flWC6c2JfjS9Hgth3 0NLhjmKoM4amGC5QjfGMwydmgOZxuhAhQsWT3qSjonTobEF5bm6vhl90Ea1vEl7LR/NY FilXtuNJIAfWxOPFxWR08aL5u0lrGF6KqAr57+gi2Ck+BrECzvrteLiGSz7zmCLLsgQc 8+RLOiZdP00ytLHbHXK4Ocdq3J5xW0de5Q5C8MSvm1Yusfv61Gz1nzxYPjv6cWMVpRuJ drZZGCJtm88NyaAjTFYKLkUt2ckGPnTKc9tzCDyrAtX/2DW1UZMYx/MX3wReP07BGXCF LvbA== 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:mime-version :content-transfer-encoding; bh=pwPxX45gZm6RhM5vkMPVW/U8WnPtyGy8RjrhrRy6BQg=; b=Mx9CYmYL+0UljgIf8/RIOU9gjXOqmAZZq4rEfMQiw0lvHxgkxjPEhmBWEmplTter9U Xf/f5+eLuwLR7RR+61Q6TDMWSJhSrtm8Xc5XebR0sjol2WhLnji0LpIDhlZIAJh2zn7a Qf627i3H6WPyYnMVBUVqk9zcJwXZaaIn84Ysb9aBM8BUuuV02Rhp9Ssbvf4xDGewymxT Y/XHQ2TkQFv9Sa2eiXj2kO+GHOvHGHOEjVDhcDYQ9nYNa+lFHfMD0EQBJ3rXmYRSno6m JqCebEIttojcedK5kZ+sXxA21QYahxS0gE6xhVEuuCJS6gZDqHamzDVRtmBOTesNYBZu 92Wg== X-Gm-Message-State: ABuFfojJjeXw5lvjO+oj/Tvor1r4BmN/gWpky2Xq0CS1gPPepG6yxwms ZkFKoGsZAiD1a5r1JDmrHK0EUw== X-Received: by 2002:a62:4e0a:: with SMTP id c10-v6mr35131pfb.240.1537812989947; Mon, 24 Sep 2018 11:16:29 -0700 (PDT) Received: from hackmann.mtv.corp.google.com ([2620:0:1000:1601:82f7:8f1:8c08:a97a]) by smtp.gmail.com with ESMTPSA id 77-v6sm7991149pfw.159.2018.09.24.11.16.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 11:16:29 -0700 (PDT) From: Greg Hackmann X-Google-Original-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> X-Mailer: git-send-email 2.19.0.444.g18242da7ef-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __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