Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3666137imu; Mon, 24 Dec 2018 06:29:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/V5s4/em1lw6yY1y95WB3ZvyKGIiib0srbNg5T9Yzit675cIqTrm5Ec9AvbxPlVGm+lXO/I X-Received: by 2002:a62:7042:: with SMTP id l63mr13919270pfc.89.1545661744727; Mon, 24 Dec 2018 06:29:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545661744; cv=none; d=google.com; s=arc-20160816; b=qEWy3uTef9IUR4fjSsW0eiVyFb4JzNXz9m+zWS2U1CHyhP6LjFtPFpg6VQNE8tZ3XA Pm6msgmcS0fCGBkLpQtDfpstXCDfku9XXO+cuHfKB/svMy97woNW8YS3Eu3R25YzsenC UiritSnVG3hVLxr7QGZjiOeu2eoi3WDPcF/Ous1kUbjjSsLrvyR3T24pwaDTRQpGeAEq Txu642ZUFKlCpHyIXpDlyM7qCZcBVKPpJAJmQJRidayYznf6LNCWHGVHJDxuRraQjagH 0hrKYc34rEsDANuTPABF21CAsZW/ro6Eo3S5cifLnJKIN6aDESGmfcoZEt3T/4+uJvot MHuw== 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=icjQTW3x6UjcsbYwELCUWBNGNwIM9zb4XrsIvHI9ZYo=; b=AkFQdGdPhDA4JZNycqVqTdQ1I+OXE+Ee1c4lIE+D9NrW+BF2QeYA+Audrk4cBGAo89 OQRDoE4KEEaZsXBqOwJicBU0/yhugyRfYHdU6BqT2HMyYioQXyLIdUoaP50hzfxdHbrO /eBaMCSQaNO9tNTsiMVakVQyexRqNvNEh/2WXNnX0xWZktncndZvrQ4ahWYm8zdNQ962 QZkW+61WZxUr/+yLeeDih1b2iH4tfnBuKXp4fbptk2aWQjDmQmhPVaJSo3p/DjwbUj0x 4jWJzxuPEVP88YF1lRNLjCiHmhDhI6kaHpFxcKYCb8sV8PirnmFD+Hkoru5s88wB+TWZ Gugg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=b37rW2Ll; 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 c17si28178456pgl.385.2018.12.24.06.28.49; Mon, 24 Dec 2018 06:29:04 -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; dkim=pass header.i=@android.com header.s=20161025 header.b=b37rW2Ll; 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 S1725888AbeLXO06 (ORCPT + 99 others); Mon, 24 Dec 2018 09:26:58 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:41433 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbeLXO06 (ORCPT ); Mon, 24 Dec 2018 09:26:58 -0500 Received: by mail-pl1-f194.google.com with SMTP id u6so5643292plm.8 for ; Mon, 24 Dec 2018 06:26:58 -0800 (PST) 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=icjQTW3x6UjcsbYwELCUWBNGNwIM9zb4XrsIvHI9ZYo=; b=b37rW2LlnpC3BbmHr+BZB4oGNAvcbpE2PyquWC00zLdY+lzf/Nq3FTXvliVQaAyqWA VBnEQrbbkxQ/lNpH0tKW+j5v8r5InV33/IDIo6mcczBI4VwwF4X9xHawxHe1Do7p5dOt 5Qu1z6idOIe3w36S0i+E0R2e/hOu3LziQ1qn5XBb+TAfX3wdJOUEeb/0SnzpPgRtEnEx K0lgfV3jS6ICDVmEyl/WDbEglOmJX1kHuhCNfvntFDGDy3kp+iI3jrlMH36mkN7WNyey jcZ6K1nveblKlxq+Hz91R9eH4p7PjW/juZecbeAZOMD7ts94OxlFPflTGkEciPBnBcY+ ZP4Q== 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=icjQTW3x6UjcsbYwELCUWBNGNwIM9zb4XrsIvHI9ZYo=; b=Kglg5RwXJvvxRjw1toJUI7A9hg739XQzCDOZv/6smnph4trQrrCpMt8E6DbhXTgdFw RQmkwWVGpJagFQ3HbGZV43eF7/i2maw+i4K2DQ6xik/+V+0hMEDEviAHPZ0YiI5K8R16 XEEdj3q61378OqEohorpkIqGtkHSoz6s5ROBZeN6Y8HJUp0oYNaedDf3HZkPMxNUx6D4 t9/y/BBIip0BWx53LfkvPTut0OGd48Io65ceHvgPg9Ux4isZ9fxJvG5k9wgh8bj5vr/+ 0QkRxvwJ/4s3D7yiig3CTBx1Rx0DyefLu+jV8+WJOh28ecpJILiHrXTNZBn1FwN/uTlV IJCQ== X-Gm-Message-State: AJcUukcWTB1+ACLPYBjrnHkyToNVkfPiGVxz78V/8YVcOO5eq0AXM95q PiWmDXyBLS7ydAJE70mJNkdQNg== X-Received: by 2002:a17:902:20b:: with SMTP id 11mr13180587plc.57.1545661617675; Mon, 24 Dec 2018 06:26:57 -0800 (PST) Received: from localhost.localdomain (23-24-209-193-static.hfc.comcastbusiness.net. [23.24.209.193]) by smtp.gmail.com with ESMTPSA id x3sm101731522pgt.45.2018.12.24.06.26.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Dec 2018 06:26:56 -0800 (PST) From: Greg Hackmann To: Alexander Viro Cc: Omer Tripp , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, Greg Hackmann , stable@vger.kernel.org Subject: [PATCH v2] fs: fix possible Spectre V1 indexing in __close_fd() Date: Mon, 24 Dec 2018 06:26:42 -0800 Message-Id: <20181224142642.7385-1-ghackmann@android.com> X-Mailer: git-send-email 2.19.1 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 Omer Tripp's analysis of a Spectre V1 gadget in __close_fd(): "1. __close_fd() is reachable via the close() syscall with a user-controlled fd. 2. If said bounds check is mispredicted, then a user-controlled address fdt->fd[fd] is obtained then dereferenced, and the value of a user-controlled address is loaded into the local variable file. 3. file is then passed as an argument to filp_close, where the cache lines secret + offsetof(f_op) and secret + offsetof(f_mode) are hot and vulnerable to a timing channel attack." Address this by using array_index_nospec() to prevent speculation past the end of current->fdt. Reported-by: Omer Tripp Cc: stable@vger.kernel.org Signed-off-by: Greg Hackmann --- v2: include Omer Tripp's analysis in commit message, and update my email address 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.1