Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp4601681ybh; Tue, 6 Aug 2019 14:39:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOaZfhaVbNlNawAKMxiGyB1RlkEmXqT+6yvodAVRFaJK1fpgB+XEbOq0XjVdfgHSGJGTuX X-Received: by 2002:a63:ff0c:: with SMTP id k12mr4653824pgi.186.1565127585604; Tue, 06 Aug 2019 14:39:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565127585; cv=none; d=google.com; s=arc-20160816; b=SYdOF4UtTY74QyBkhQFnAmLnabMl8GpY02knraUCkuOmpY97YQg7JHAV+JY+riw6jo BXop33Bx6CUBYHNSPvcFfr3vpO2B/LglESjb6eCNieXAK4rFxBv4GHEUJV0MieEvR6mV Pk6LOaHEb74KSHJ7ykIYhK8AHCu82eTrBpobGrU7TwfJtsa5BZmi5kM/ETB9LAzomWCm gRGA/4AQ3lVHHTwEmneE7OMOKFENMl3kiHQzuubVN7ppBS1SuIE5ZsJLRyc8EduUwfsS pk16E/PKl049qJGNs5eAEzBzwAK0JndJmV2UF2cKya4YA68TUGJzshhpK7PtM5E1OUfK R6Rg== 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=tY2h+tXXIqYx/OcMeKVnxy8MPT/xB2ThSXIveWmIsjU=; b=zJq2YqQ2l1utEZeGkPXZERATtyXiR2a0fqpcdgjwNcNvyqBT7cOjxEBiBjJA9eX4Kx KHJs4FTk+/9HFesZckocOVgWCODPVw9lN1Ft8OyOMtSuHgYMxCbBTmT1mlqgVA0OMvK/ dc2M6CnsHHfTQvKK2V0BKUoBiRE73T5/irQJqfTk+FkTaH0VRGmQvqeYk2nKU3bLSXe4 wE1Vj8jR6meBfr6FV1piWrMGJqtZdRBdrtom4wyA7c3Vp+heT9Xoy+eM1FI/fN2HltJF Ty404cCc7JsMibPpIsRt4ZSe2hczniB0EuovtFt44eLIKAYk22l654PoXVfqkXCrHau0 LPvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sW90APsV; 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 t137si45935198pgc.49.2019.08.06.14.39.30; Tue, 06 Aug 2019 14:39:45 -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=sW90APsV; 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 S1728832AbfHFViN (ORCPT + 99 others); Tue, 6 Aug 2019 17:38:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:55844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727570AbfHFViL (ORCPT ); Tue, 6 Aug 2019 17:38:11 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 3F27A20C01; Tue, 6 Aug 2019 21:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565127489; bh=WfJITCGv9bAQKx9HPueqnYT/6ry3FvjBX8ESFIOFElE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sW90APsVeVDQpVt0nOUMuZbfmaBLu3nOLRBaSBz8k4V8L+r81JZ10Z/5GI9GMdI2k E5Dck8mVYOXVDeQyjL+HdyiMBi4o2OfyYudNuWmof4IVOnD7o3R30hKxAGtAYH28nE E9BpGXkLMXNlSiOBAmnjrs8lycC5wmtXrj5ZLL+Q= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Luck, Tony" , Doug Ledford , Sasha Levin , linux-rdma@vger.kernel.org Subject: [PATCH AUTOSEL 4.4 11/14] IB/core: Add mitigation for Spectre V1 Date: Tue, 6 Aug 2019 17:37:45 -0400 Message-Id: <20190806213749.20689-11-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190806213749.20689-1-sashal@kernel.org> References: <20190806213749.20689-1-sashal@kernel.org> MIME-Version: 1.0 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 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