Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1418688ybl; Thu, 22 Aug 2019 14:19:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzNAVcCC5lg1kVX7v3gABVC+3pc7XynGnKktGSwQffCWjMoJmfBY6MRd2vRbX/o+M3gcza X-Received: by 2002:a17:902:e38b:: with SMTP id ch11mr830078plb.275.1566508761450; Thu, 22 Aug 2019 14:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566508761; cv=none; d=google.com; s=arc-20160816; b=bumxxBayxRYi9JYK8sjxxrcFZ1FY/9/SsXtaltBVPCYmMaW9OtQbz3zgceggkFRmzQ 5ppSZlSzAzX8VurIj94dMAixRwIJ4Z8s9PciUBtEfwn6uMbHY4a6NboXwHhNCiB2J77t KqaS0h6fzbR8BY1/fU4t/1mQRmE98T3JZzvDx6V/336QvCOxU9+oge9YnDyfClTG6LUR Bllfqf3JrNR6T8tNEMpuUPi6ujRLLm8FuAJXiyA/lpVtyrgBG1MZQPTkf6enEydaV55h TPyYBb1JL7NJB4KZm9fcJSyeevXPqtS3yq5aK896dQOsdeMWMCtrc+y9deY2MybUj1wa FUDA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pfza/yuFWH/mdgh3vqubaPd4sQmf+3Jb6ZYN+Wn9/RA=; b=SyGcN95V+F3aDNQMYQ1gtT5WL+xbi5ulrqxMLICSR+Du6zMWB/q92bkE3SoxjwtkhQ e17v35S5i3nLB/VBB99B3PI3PINPZval4HxPZY8awHCj3osm0sjJYCNJbJJ/FPEsgMSQ 25auVOEa4zDrAoaSGuFnnHERf0DisYdjH1UC3lJGpUqfIu60DCG9IdgH19VNf07y4gGJ BzG8UbkCw91lzGyZVgvQ6cjNm1i5sC/35dkql6UnXtGK5Zv4V1DhSwKjCHs4VGjx2EVB iaTopFtZEakOLGKtNp3af3zF+/rIktVeVqqqal1xP1oScDcjUadmFQwY3x68uoeBs6CV elUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KaDR15K4; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c4si349305pgk.257.2019.08.22.14.19.06; Thu, 22 Aug 2019 14:19:21 -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=@kernel.org header.s=default header.b=KaDR15K4; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390606AbfHVRI7 (ORCPT + 99 others); Thu, 22 Aug 2019 13:08:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:59006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390576AbfHVRI4 (ORCPT ); Thu, 22 Aug 2019 13:08:56 -0400 Received: from sasha-vm.mshome.net (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8283E2341B; Thu, 22 Aug 2019 17:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566493735; bh=XPa39C+ImOWiH3ShEPLYIBOk+rk+TWk7X2QkYKWN7SU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KaDR15K4z4Hrzqu0Yd6ISM9yK3Kr/KJXJCbwXXGKIfVmbVG0A9kenY2lJ1lqVW8DC rpj+U2S9Wvh4Cm377FvmFGz3h+uIkcI++d0pr3j0Aa8qIcBwRhlSjMT859IxPTpUHq 7Cjr+vuhq68egkAzJF5DRxsQ37RpJwVRGRtE7JAQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Luck, Tony" , Doug Ledford , Sasha Levin Subject: [PATCH 5.2 076/135] IB/core: Add mitigation for Spectre V1 Date: Thu, 22 Aug 2019 13:07:12 -0400 Message-Id: <20190822170811.13303-77-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822170811.13303-1-sashal@kernel.org> References: <20190822170811.13303-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.2.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.2.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.2.10-rc1 X-KernelTest-Deadline: 2019-08-24T17:07+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Luck, Tony" [ 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 671f07ba1fad6..025b6d86a61fc 100644 --- a/drivers/infiniband/core/user_mad.c +++ b/drivers/infiniband/core/user_mad.c @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -883,11 +884,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