From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 140BAC3A5A1 for ; Thu, 22 Aug 2019 17:24:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6F0D2341A for ; Thu, 22 Aug 2019 17:24:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566494654; bh=vBxPfPKj+SsMCAA09XAgHduQ2I76vkPQwHl0VU0fJcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=TclUWdwLrtedUeQO1TANgHuLe/I4iinEo0piVlMl1yOGzmn+QeavL93M3z3OQOxUz ee08/ySSWSpKFvt0tGbN0Hn4lp/ezCBqpQdcRmE24uO66dsFCdzEN/Pg9VWRTzZZwW AxwcKjwxAKa6Ru3IT1d/IquV9C/Js+ht7A8H8yJw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404123AbfHVRYN (ORCPT ); Thu, 22 Aug 2019 13:24:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:41448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391454AbfHVRWp (ORCPT ); Thu, 22 Aug 2019 13:22:45 -0400 Received: from localhost (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 42CEE233FD; Thu, 22 Aug 2019 17:22:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566494564; bh=vBxPfPKj+SsMCAA09XAgHduQ2I76vkPQwHl0VU0fJcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sRzN7Ex823ZdJLp6Ak42xUQ786phUFgc9z1Xes/HrwmES+Im3jTwl6OvcfU6YYkFX FWqfjvnZOuCMQR4lkO+fJwYTdInYoa5ldyRJRn6lzBnEydTrkOEIXKbdhLE6CwBhY+ zGwLZBaCjubNqmYdG5wY8u64TOoIxzztfYSBGvus= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tony Luck , Doug Ledford , Sasha Levin Subject: [PATCH 4.4 52/78] IB/core: Add mitigation for Spectre V1 Date: Thu, 22 Aug 2019 10:18:56 -0700 Message-Id: <20190822171833.548577018@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822171832.012773482@linuxfoundation.org> References: <20190822171832.012773482@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 61f259821dd3306e49b7d42a3f90fb5a4ff3351b ] Some processors may mispredict an array bounds check and speculatively access memory that they should not. With a user supplied array index we like to play things safe by masking the value with the array size before it is used as an index. Signed-off-by: Tony Luck Link: https://lore.kernel.org/r/20190731043957.GA1600@agluck-desk2.amr.corp.intel.com Signed-off-by: Doug Ledford Signed-off-by: Sasha Levin --- drivers/infiniband/core/user_mad.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c index 57f281f8d6862..e9e75f40714cb 100644 --- a/drivers/infiniband/core/user_mad.c +++ b/drivers/infiniband/core/user_mad.c @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -842,11 +843,14 @@ static int ib_umad_unreg_agent(struct ib_umad_file *file, u32 __user *arg) if (get_user(id, arg)) return -EFAULT; + if (id >= IB_UMAD_MAX_AGENTS) + return -EINVAL; mutex_lock(&file->port->file_mutex); mutex_lock(&file->mutex); - if (id >= IB_UMAD_MAX_AGENTS || !__get_agent(file, id)) { + id = array_index_nospec(id, IB_UMAD_MAX_AGENTS); + if (!__get_agent(file, id)) { ret = -EINVAL; goto out; } -- 2.20.1