Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2987406imu; Sun, 9 Dec 2018 14:22:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/V2oIO9yBgT9rl2l0gX0yYcLk/3IZKBHKu5/B8oEmpGy/x4EAweJE6XzKb2Ts/rD/ppfi4H X-Received: by 2002:a63:8f45:: with SMTP id r5mr8792183pgn.222.1544394144357; Sun, 09 Dec 2018 14:22:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544394144; cv=none; d=google.com; s=arc-20160816; b=IS0CawB3YFPGZ128D40eMFHsCbbuarOZZ6EivFFAGzH9k9MWGux1qyBFlvEDBSY6xH +rI0NwajtJiU1X5oXYsnaiDmNB2fOe4japOyjkq02lN5FjPMWUsGNq4HtnNg9HwyfI+T +K18Sr++rlaEnpw4T2v6YoYmOoH3w2firjfrgjhds/T2v3cxuAQbbkAZHrg5Ng1jLwJz auE/UTT9qbduVsyNxZonU7SxGDpdqT4rcOy1z09brC83/nNjmf8wet+wjmV8eBpEZh+n B1XHaxkjyEsw3GHOOa7p5zY3JvjswHEBAKP4MnIYWkzKm/HYbjdASuxzX45/5+uAeTAg Iksw== 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=NAx1RU1RNjvWvrZVsqkBuqj549h0zamqckh/n1n7zA0=; b=B2SkApMlTvGhPgt6skYw0yh8j1AIRSHq5jFjxZVKqgy43ZTLEVoG1BIoL8E3rJhq/+ C2R8TdSbF7mhiybmCN0SzMex+gyJIMl5kn/CUCYvwiWpDD+AnY2FdvcJ6YJ4Z3wwLZKp EgmlKVEIcxNdojS/riap0JNLiyqqh9kLihJ+/5gGZ6mBvUCUmkC57JuFRlv/YpVO66yw u4/O6Ss8GfpCUE10tc0EPj1oQH3RfnUCBve8VPTCFfXGgk7fqIXIpqWGyWPOpwiYCVAx zhCkLYqGnTw3sN54uPluUERRMxMXi+94B9U0a9UAh4ukmF41g0808Mik3U7eRO6miwvx qptg== 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 e4si8316621pgd.256.2018.12.09.14.22.09; Sun, 09 Dec 2018 14:22:24 -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 S1727259AbeLIWUx (ORCPT + 99 others); Sun, 9 Dec 2018 17:20:53 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35398 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726546AbeLIVzY (ORCPT ); Sun, 9 Dec 2018 16:55:24 -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-0002il-Vf; Sun, 09 Dec 2018 21:55:22 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72l-0003gn-Cr; 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, "Gustavo A. R. Silva" , "Doug Ledford" 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 314/328] RDMA/ucma: 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 a3671a4f973ee9d9621d60166cc3b037c397d604 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/ucma.c:1686 ucma_write() warn: potential spectre issue 'ucma_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 Signed-off-by: Ben Hutchings --- drivers/infiniband/core/ucma.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/infiniband/core/ucma.c +++ b/drivers/infiniband/core/ucma.c @@ -43,6 +43,8 @@ #include #include +#include + #include #include #include @@ -1540,6 +1542,7 @@ static ssize_t ucma_write(struct file *f if (hdr.cmd >= ARRAY_SIZE(ucma_cmd_table)) return -EINVAL; + hdr.cmd = array_index_nospec(hdr.cmd, ARRAY_SIZE(ucma_cmd_table)); if (hdr.in + sizeof(hdr) > len) return -EINVAL;