Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3019846imu; Sun, 9 Dec 2018 15:16:31 -0800 (PST) X-Received: by 2002:a62:1289:: with SMTP id 9mr10369971pfs.102.1544397151923; Sun, 09 Dec 2018 15:12:31 -0800 (PST) X-Google-Smtp-Source: AFSGD/Udd+kn/gsxzuIqtMNyvoP227ljKVR7XU3YYCVJLJtyDJkLYxXziF1ixs+1+FkoZs9oDnSN X-Received: by 2002:a62:1289:: with SMTP id 9mr10369906pfs.102.1544397151008; Sun, 09 Dec 2018 15:12:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544397150; cv=none; d=google.com; s=arc-20160816; b=OBlvlfvuVpFNlxRK4yhasd0jMf1Oums3GpE3+ZumuF9niiLXwNDBMoL2zZ2cIaGVnM lt7CEpvYePYaNOWAlc3L5Rvzc+DQuWAK6J2JFNrT9vsWz6c6xYi/ZU3/q8XFdZYymurH g/MgDckXJ92KF4At2ySEZzeY+LcUpurUzz7hHIdrQ+rWJw4Qp3UHZFWn6UpdDsVxFpqx 6JiTOAtOoBXhm3yVyvqMQnb8/XtjqJOhNhsLrwkRxPxDJb4LhyhDspCImC0TjmNRrq2C GdYX/lO5h93tHyjI2uwW0ZZC/WUNCRUkQlaM01HFQxk5J+6Di21XxcYf6/QNJVc7+yMt s6Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=fMjw0g5FlPlrzDNlMgjZDO/EmzpmDmZwiBjel3X3jNw=; b=BJ72z3DKm9sICcaE1yHk+6Qjkgz1T503zxKh0O6W/oWsCUPCbYWIM8mox0EScuB7k9 cqTU32Te0kk3mZRo4B1FvoubvY3Ap6GJpKMosT6ndd60RbiHA5ENLpiau+VRUyh/buK1 lFtWl6GWNj8CP+Br3Tg8psSbJj3xZa04tjHbrD8Q4TCpBmNRcLGuCIPcP/yhya84PvA3 pXBskZWJiDPQXo+juq883bhv4sTibgGZPsxnpOyIEBTp0aqGuaBIezXw4nBr/qd2eOvR JkZ3PKhyImMBCZRN4s8SuVx68CowQzYZlXhO6JwM50YlW+Bd+RpKMzOJRMg/6hbuAtDJ 2/RQ== 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 g19si8071576pgj.358.2018.12.09.15.12.15; Sun, 09 Dec 2018 15:12:30 -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 S1727375AbeLIWUW (ORCPT + 99 others); Sun, 9 Dec 2018 17:20:22 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35418 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726552AbeLIVzZ (ORCPT ); Sun, 9 Dec 2018 16:55:25 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW72n-0002ir-Vf; Sun, 09 Dec 2018 21:55:22 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72l-0003gj-BS; Sun, 09 Dec 2018 21:55:19 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Doug Ledford" , "Gustavo A. R. Silva" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 313/328] IB/ucm: Fix Spectre v1 vulnerability In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: "Gustavo A. R. Silva" commit 0295e39595e1146522f2722715dba7f7fba42217 upstream. hdr.cmd can be indirectly controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability. This issue was detected with the help of Smatch: drivers/infiniband/core/ucm.c:1127 ib_ucm_write() warn: potential spectre issue 'ucm_cmd_table' [r] (local cap) Fix this by sanitizing hdr.cmd before using it to index ucm_cmd_table. Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1]. [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2 Signed-off-by: Gustavo A. R. Silva Signed-off-by: Doug Ledford [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- drivers/infiniband/core/ucm.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/infiniband/core/ucm.c +++ b/drivers/infiniband/core/ucm.c @@ -46,6 +46,8 @@ #include #include +#include + #include #include @@ -1116,6 +1118,7 @@ static ssize_t ib_ucm_write(struct file if (hdr.cmd >= ARRAY_SIZE(ucm_cmd_table)) return -EINVAL; + hdr.cmd = array_index_nospec(hdr.cmd, ARRAY_SIZE(ucm_cmd_table)); if (hdr.in + sizeof(hdr) > len) return -EINVAL;