Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5532008ybi; Tue, 30 Jul 2019 22:51:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXTDJIUrZb1tdproOqTmHrDnd9t/vSxJJvuNMIoVc3bZ0F+HkDibvf05/zYbf5n/wDktIp X-Received: by 2002:a17:90a:a613:: with SMTP id c19mr1131049pjq.17.1564552318512; Tue, 30 Jul 2019 22:51:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564552318; cv=none; d=google.com; s=arc-20160816; b=m5IwF+TdUJD0nD6NOHloQ1XBTdJBfCQroLKvxrRD+AfBcORBWYAZ3xYtKh9MvIfGt3 rddna6HXSdySZYFu/NRatdRY5FpKAHyAti94LTTkEY6eHJPXoGwT9TersVEjR6bEVnhz Z0OloH6O5hccUGhircIZuSkRXWnxMVnFP7mbM3x+fO8Qj/wEpXuv1BJ+ETJLnF8QY528 P46cEeNJ4Wo114+vUiOmxUGZB5QAdkml6+SkE4bAN9PrewTCM7bEWFe4C/F3Ic3bAGJu swi7swnbyz/VLn/4ev/gGwBwlGA5q3JpbIIvjg7l5R2wqueKit26sB7w3poOOpoKJGoo OP6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=XcdeUWKxHCJ7qzsohRjLsRJnwUrzn0FEVK/ZmDk8rGk=; b=t2pEFYOZ2ePrrK1d+pdDBXx6jyChNJXMDe1NXyFCudtXpJx0rJAoeYkgRYziKcez4Q 6bmAUIRyuPeLjQKN+o4BEBdikWgrNtYpw2G65SyK+9bjxbY5dawLG9yFhORt4xfp7ziC ckZkmeVQOXSpbomYmEG1LajSHOOPtHrlOrw4i/YGunhdZXIVj3sfWXdVw1yjBU1d2tz8 RdUYZMwQCewaFlaL9GKpKxuUZb7h6vb8lTbfolKAIrsadveLQdouiX33NW39/uNsQjJA VVq+NMxzBDKiGEu4ucxhEkDAKhJsojYnsVVnHQoVLiifcT+2AIdU2f+OKBML4Fu4Fn65 GdQA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w16si38699765pfq.70.2019.07.30.22.51.43; Tue, 30 Jul 2019 22:51:58 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728710AbfGaEj7 (ORCPT + 99 others); Wed, 31 Jul 2019 00:39:59 -0400 Received: from mga05.intel.com ([192.55.52.43]:6686 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726439AbfGaEj7 (ORCPT ); Wed, 31 Jul 2019 00:39:59 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jul 2019 21:39:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,328,1559545200"; d="scan'208";a="162980318" Received: from agluck-desk2.sc.intel.com (HELO agluck-desk2.amr.corp.intel.com) ([10.3.52.68]) by orsmga007.jf.intel.com with ESMTP; 30 Jul 2019 21:39:58 -0700 Date: Tue, 30 Jul 2019 21:39:57 -0700 From: "Luck, Tony" To: Ira Weiny Cc: "Gustavo A. R. Silva" , Doug Ledford , Jason Gunthorpe , Leon Romanovsky , Parav Pandit , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2] IB/core: Add mitigation for Spectre V1 Message-ID: <20190731043957.GA1600@agluck-desk2.amr.corp.intel.com> References: <20190730202407.31046-1-tony.luck@intel.com> <95f5cf70-1a1d-f48c-efac-f389360f585e@embeddedor.com> <20190731042801.GA2179@iweiny-DESK2.sc.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190731042801.GA2179@iweiny-DESK2.sc.intel.com> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- V2: Mask the index *AFTER* the bounds check. Issue pointed out by Gustavo. Fix suggested by Ira. drivers/infiniband/core/user_mad.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c index 9f8a48016b41..32cea5ed9ce1 100644 --- a/drivers/infiniband/core/user_mad.c +++ b/drivers/infiniband/core/user_mad.c @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -888,7 +889,12 @@ static int ib_umad_unreg_agent(struct ib_umad_file *file, u32 __user *arg) mutex_lock(&file->port->file_mutex); mutex_lock(&file->mutex); - if (id >= IB_UMAD_MAX_AGENTS || !__get_agent(file, id)) { + if (id >= IB_UMAD_MAX_AGENTS) { + ret = -EINVAL; + goto out; + } + id = array_index_nospec(id, IB_UMAD_MAX_AGENTS); + if (!__get_agent(file, id)) { ret = -EINVAL; goto out; } -- 2.20.1