[PATCH 4.18 034/150] nl80211: Fix possible Spectre-v1 for CQM RSSI thresholds

2018-11-02 Thread Greg Kroah-Hartman
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





[PATCH 4.18 034/150] nl80211: Fix possible Spectre-v1 for CQM RSSI thresholds

2018-11-02 Thread Greg Kroah-Hartman
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