Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2455190imd; Fri, 2 Nov 2018 11:41:46 -0700 (PDT) X-Google-Smtp-Source: AJdET5dKlpID9f8L3TxtdVU52q6XJId9Vis79Nn9W25R5SXzANg9hGP+oM0ilcSS5qEtdVo+y3St X-Received: by 2002:aa7:83c2:: with SMTP id j2-v6mr12789947pfn.91.1541184106280; Fri, 02 Nov 2018 11:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541184106; cv=none; d=google.com; s=arc-20160816; b=TKW62uihMQIwUMUuMuEJjvsU8JAg25Iof6/ydZ1kMbBSpCW37Su+Wynb+wfIaRIgxS 2+II67ZjAAaBIckbOtf9Of7sTBSf21yE3ZBjYSJjCgF1cclyCR9A4ECacte1nAWOT9Ii cn7G/Ag1HidYOAIwZdpzzMg6h3xxGglPpk9Q5FR6hxSxHC0iTPFB3GlcfQ/I77nhkj8g 2kIarjOGWFuCwAErHFYsgwW0HyMy/Qu4xfGe605MmbHnussKDdtQO9aUlAympRmkZt4X by/WtHJiGAnOba79qtFXXqxkx1H+JqZtb3x9h4Wd79f0LEBwg/F0DKXuqEWkNCIbAnox l1Uw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bP25r3uRaylpi7Iie2/12L0WEtPm429sDQyl7c3hp1c=; b=eI+1JeSqIkAuWtYBRiMj9S9rpu7bp6mvB0AcoBfwSLBoAOq2V5bsh8geaEpmtqdR5k y2nDQEjhfaLjGtCw5G7hpOTJtP2pDxClFl+Ov6w2A6JaWqeWBxxpFi/jRci+4v6c0iB+ lwBI91NquX36bWKnji52fDd7Pz5BNuKsQp7a2NKR2gncfKJOixC0D7FkeuT0x5mX31l2 abeQZyKYaSfgafbe7kj8sO4S5W5t/gD/EzaPy9G6X8p+0g5qOZshC+rJStYc45vz0aGG M1FyXzmlBABamj05jJVjtyFTa3iqS9HUTxZ4F2aJXh6TiA6lwnvwwZtm1lYOHNm/EEsF msSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CY6E15AG; 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 g5-v6si35068914pgi.596.2018.11.02.11.41.31; Fri, 02 Nov 2018 11:41:46 -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=CY6E15AG; 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 S1729093AbeKCDr3 (ORCPT + 99 others); Fri, 2 Nov 2018 23:47:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:41532 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728102AbeKCDr3 (ORCPT ); Fri, 2 Nov 2018 23:47:29 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 277C12082E; Fri, 2 Nov 2018 18:39:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541183957; bh=+5K6Jfh+Ocw4X/939WNa5ib60FJq5qrYGYKJsk3hJRQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CY6E15AG7jafrCOcULMNy4l8jP6+ze6Uh78r78U5YGWHAOfb4VXOptePVNaox+IH6 N9FMhsksZbzi+DnKU1NuB1sRMkymoz5zKFrFENfwmbUsktKpCiYQMlg0zTU5ORvGs2 Q7pOCUVfnx8Ui42XWOdUExcsANT/Bgh+fPMI8qNI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masashi Honma , Johannes Berg , Sasha Levin Subject: [PATCH 4.18 034/150] nl80211: Fix possible Spectre-v1 for CQM RSSI thresholds Date: Fri, 2 Nov 2018 19:33:16 +0100 Message-Id: <20181102182905.700962418@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182902.250560510@linuxfoundation.org> References: <20181102182902.250560510@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 1222a16014888ed9733c11e221730d4a8196222b ] Use array_index_nospec() to sanitize i with respect to speculation. Note that the user doesn't control i directly, but can make it out of bounds by not finding a threshold in the array. Signed-off-by: Masashi Honma [add note about user control, as explained by Masashi] Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- net/wireless/nl80211.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 3b80cf012438..214f9ef79a64 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -10125,7 +10125,7 @@ static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, struct wireless_dev *wdev = dev->ieee80211_ptr; s32 last, low, high; u32 hyst; - int i, n; + int i, n, low_index; int err; /* RSSI reporting disabled? */ @@ -10162,10 +10162,19 @@ static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, if (last < wdev->cqm_config->rssi_thresholds[i]) break; - low = i > 0 ? - (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN; - high = i < n ? - (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX; + low_index = i - 1; + if (low_index >= 0) { + low_index = array_index_nospec(low_index, n); + low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; + } else { + low = S32_MIN; + } + if (i < n) { + i = array_index_nospec(i, n); + high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; + } else { + high = S32_MAX; + } return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); } -- 2.17.1