Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2474789imd; Fri, 2 Nov 2018 12:03:24 -0700 (PDT) X-Google-Smtp-Source: AJdET5equPiT9lEdOWc6BxA+RONO8/c4hXDE+QCX6kp0U+msBY1FZkuztolTFt4eaOs8yKFK3paK X-Received: by 2002:a17:902:bd8d:: with SMTP id q13-v6mr12806006pls.167.1541185404734; Fri, 02 Nov 2018 12:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541185404; cv=none; d=google.com; s=arc-20160816; b=CaGTW3gpJNw6BIFeeXyrlRFeKBeOYZkZHBoIsJorxknth7k+HRr6HiCQCIy0Qttf1W +rPXIU3LcaOkp6xaB1Zru0C1PZlLSBE/U0HGa60i4SvkdGa3zXPqSnQtLVun4rf5i0VJ Rr76ynF+CissuWth0+Tfa2LUn3RHan1cFrWVo0pE9/C3BvjNbp6twsoqyuFndosAErQM Y6ktA+fQtUdJq692QXrhmuuQ/3BoB4TrPhH/yxi28NqkzEya9wv66M+Nl/VUWC6V+JEI Px4yMqNSyikNWjwnrQv2fLBAKmY3BGNFDVfXRhz2wSgknT79XE4OG73962ERWqfp+iA4 Dahw== 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=BW+KpPZe8ngcrwEdROui1ZpkCuzTEI23Zpnvp8SBPNs=; b=zoe/PmQoE9dvN1HWn4uSV/aVS3gtYOUjLsTIAEiZOYzNdmq1EgQMc5lisFl6JopL5i t6dMvORaeIPv/X3kdG/Oo0CyuTr929vDFk/rRALMSc2GIVqmoN6tkQ6uN3L3j5JNXJc9 +2R9RzVjV4KMZFN2cgW85k0GDemcOYbzm+W1wbY3pX1KjmX6inMZgq9HZL3BajneM7jl C9wQcOSP+eHiZTqz6En5d+NnFbuVlD04ysNx9rFo+xDzrfagZalVlEczwwPOY2tpe15K d7FOc3w9p+6wT+MnkQ6Y4dA9up7jzSvThDIjb095oRQisP3Ff0cEMrPkeqQ9Xoxgu27w oLQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YejsDxFo; 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 a31-v6si33027496pgl.280.2018.11.02.12.03.09; Fri, 02 Nov 2018 12:03:24 -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=YejsDxFo; 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 S1729970AbeKCEK4 (ORCPT + 99 others); Sat, 3 Nov 2018 00:10:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:52678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729513AbeKCD5K (ORCPT ); Fri, 2 Nov 2018 23:57:10 -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 661932082D; Fri, 2 Nov 2018 18:48:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184536; bh=yCDOP+Rjo4THYIJKu6BxR86Qr8NBUf8fTLmI8RLlVyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YejsDxFouisIR2gnJKPnKKay5zKzSRSwgofvFn5LbsZnzZ2zdnBr03T9wf6UoRWQx S5okEoa7QS/KDMbxlSTCMc0fUk8pbJtKdr4gcG0tBPShiuJqIlozRUJst0NBC9L7DC qncaROEcQDKXIyD9mqUABn14tljisBILFri85Sww= 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.14 029/143] nl80211: Fix possible Spectre-v1 for CQM RSSI thresholds Date: Fri, 2 Nov 2018 19:33:34 +0100 Message-Id: <20181102182859.412533830@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182857.064326086@linuxfoundation.org> References: <20181102182857.064326086@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.14-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 5e7c9b361e8a..46e9812d13c0 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -9720,7 +9720,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? */ @@ -9757,10 +9757,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