Commit e4a29bdd authored by Ahmad Masri's avatar Ahmad Masri Committed by Kalle Valo

wil6210: check mid is valid

Check that the mid is valid and that it does not exceed the memory
size allocated to vifs array.
Signed-off-by: default avatarAhmad Masri <amasri@codeaurora.org>
Signed-off-by: default avatarMaya Erez <merez@codeaurora.org>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent 044974fb
...@@ -465,7 +465,7 @@ static int wil_cfg80211_validate_add_iface(struct wil6210_priv *wil, ...@@ -465,7 +465,7 @@ static int wil_cfg80211_validate_add_iface(struct wil6210_priv *wil,
.num_different_channels = 1, .num_different_channels = 1,
}; };
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
if (wil->vifs[i]) { if (wil->vifs[i]) {
wdev = vif_to_wdev(wil->vifs[i]); wdev = vif_to_wdev(wil->vifs[i]);
params.iftype_num[wdev->iftype]++; params.iftype_num[wdev->iftype]++;
...@@ -486,7 +486,7 @@ static int wil_cfg80211_validate_change_iface(struct wil6210_priv *wil, ...@@ -486,7 +486,7 @@ static int wil_cfg80211_validate_change_iface(struct wil6210_priv *wil,
}; };
bool check_combos = false; bool check_combos = false;
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
struct wil6210_vif *vif_pos = wil->vifs[i]; struct wil6210_vif *vif_pos = wil->vifs[i];
if (vif_pos && vif != vif_pos) { if (vif_pos && vif != vif_pos) {
...@@ -1806,7 +1806,7 @@ void wil_cfg80211_ap_recovery(struct wil6210_priv *wil) ...@@ -1806,7 +1806,7 @@ void wil_cfg80211_ap_recovery(struct wil6210_priv *wil)
int rc, i; int rc, i;
struct wiphy *wiphy = wil_to_wiphy(wil); struct wiphy *wiphy = wil_to_wiphy(wil);
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
struct wil6210_vif *vif = wil->vifs[i]; struct wil6210_vif *vif = wil->vifs[i];
struct net_device *ndev; struct net_device *ndev;
struct cfg80211_beacon_data bcon = {}; struct cfg80211_beacon_data bcon = {};
......
...@@ -1381,7 +1381,7 @@ static int link_show(struct seq_file *s, void *data) ...@@ -1381,7 +1381,7 @@ static int link_show(struct seq_file *s, void *data)
if (p->status != wil_sta_connected) if (p->status != wil_sta_connected)
continue; continue;
vif = (mid < wil->max_vifs) ? wil->vifs[mid] : NULL; vif = (mid < GET_MAX_VIFS(wil)) ? wil->vifs[mid] : NULL;
if (vif) { if (vif) {
rc = wil_cid_fill_sinfo(vif, i, sinfo); rc = wil_cid_fill_sinfo(vif, i, sinfo);
if (rc) if (rc)
...@@ -1579,7 +1579,7 @@ __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) ...@@ -1579,7 +1579,7 @@ __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
break; break;
} }
mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
if (mid < wil->max_vifs) { if (mid < GET_MAX_VIFS(wil)) {
struct wil6210_vif *vif = wil->vifs[mid]; struct wil6210_vif *vif = wil->vifs[mid];
if (vif->wdev.iftype == NL80211_IFTYPE_STATION && if (vif->wdev.iftype == NL80211_IFTYPE_STATION &&
...@@ -1645,7 +1645,7 @@ static int mids_show(struct seq_file *s, void *data) ...@@ -1645,7 +1645,7 @@ static int mids_show(struct seq_file *s, void *data)
int i; int i;
mutex_lock(&wil->vif_mutex); mutex_lock(&wil->vif_mutex);
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
vif = wil->vifs[i]; vif = wil->vifs[i];
if (vif) { if (vif) {
...@@ -1866,7 +1866,7 @@ static int wil_link_stats_debugfs_show(struct seq_file *s, void *data) ...@@ -1866,7 +1866,7 @@ static int wil_link_stats_debugfs_show(struct seq_file *s, void *data)
/* iterate over all MIDs and show per-cid statistics. Then show the /* iterate over all MIDs and show per-cid statistics. Then show the
* global statistics * global statistics
*/ */
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
vif = wil->vifs[i]; vif = wil->vifs[i];
seq_printf(s, "MID %d ", i); seq_printf(s, "MID %d ", i);
...@@ -1922,7 +1922,7 @@ static ssize_t wil_link_stats_write(struct file *file, const char __user *buf, ...@@ -1922,7 +1922,7 @@ static ssize_t wil_link_stats_write(struct file *file, const char __user *buf,
if (rc) if (rc)
return rc; return rc;
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
vif = wil->vifs[i]; vif = wil->vifs[i];
if (!vif) if (!vif)
continue; continue;
......
...@@ -685,7 +685,7 @@ void wil_bcast_fini_all(struct wil6210_priv *wil) ...@@ -685,7 +685,7 @@ void wil_bcast_fini_all(struct wil6210_priv *wil)
int i; int i;
struct wil6210_vif *vif; struct wil6210_vif *vif;
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
vif = wil->vifs[i]; vif = wil->vifs[i];
if (vif) if (vif)
wil_bcast_fini(vif); wil_bcast_fini(vif);
...@@ -1483,7 +1483,7 @@ void wil_abort_scan_all_vifs(struct wil6210_priv *wil, bool sync) ...@@ -1483,7 +1483,7 @@ void wil_abort_scan_all_vifs(struct wil6210_priv *wil, bool sync)
lockdep_assert_held(&wil->vif_mutex); lockdep_assert_held(&wil->vif_mutex);
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
struct wil6210_vif *vif = wil->vifs[i]; struct wil6210_vif *vif = wil->vifs[i];
if (vif) if (vif)
...@@ -1551,7 +1551,7 @@ static int wil_restore_vifs(struct wil6210_priv *wil) ...@@ -1551,7 +1551,7 @@ static int wil_restore_vifs(struct wil6210_priv *wil)
struct wireless_dev *wdev; struct wireless_dev *wdev;
int i, rc; int i, rc;
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
vif = wil->vifs[i]; vif = wil->vifs[i];
if (!vif) if (!vif)
continue; continue;
...@@ -1627,7 +1627,7 @@ int wil_reset(struct wil6210_priv *wil, bool load_fw) ...@@ -1627,7 +1627,7 @@ int wil_reset(struct wil6210_priv *wil, bool load_fw)
wil_abort_scan_all_vifs(wil, false); wil_abort_scan_all_vifs(wil, false);
mutex_unlock(&wil->vif_mutex); mutex_unlock(&wil->vif_mutex);
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
vif = wil->vifs[i]; vif = wil->vifs[i];
if (vif) { if (vif) {
cancel_work_sync(&vif->disconnect_worker); cancel_work_sync(&vif->disconnect_worker);
......
/* /*
* Copyright (c) 2012-2017 Qualcomm Atheros, Inc. * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
* Copyright (c) 2018, The Linux Foundation. All rights reserved. * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
...@@ -27,7 +27,7 @@ bool wil_has_other_active_ifaces(struct wil6210_priv *wil, ...@@ -27,7 +27,7 @@ bool wil_has_other_active_ifaces(struct wil6210_priv *wil,
struct wil6210_vif *vif; struct wil6210_vif *vif;
struct net_device *ndev_i; struct net_device *ndev_i;
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
vif = wil->vifs[i]; vif = wil->vifs[i];
if (vif) { if (vif) {
ndev_i = vif_to_ndev(vif); ndev_i = vif_to_ndev(vif);
...@@ -155,7 +155,7 @@ static int wil6210_netdev_poll_tx(struct napi_struct *napi, int budget) ...@@ -155,7 +155,7 @@ static int wil6210_netdev_poll_tx(struct napi_struct *napi, int budget)
struct wil6210_vif *vif; struct wil6210_vif *vif;
if (!ring->va || !txdata->enabled || if (!ring->va || !txdata->enabled ||
txdata->mid >= wil->max_vifs) txdata->mid >= GET_MAX_VIFS(wil))
continue; continue;
vif = wil->vifs[txdata->mid]; vif = wil->vifs[txdata->mid];
...@@ -294,7 +294,7 @@ static u8 wil_vif_find_free_mid(struct wil6210_priv *wil) ...@@ -294,7 +294,7 @@ static u8 wil_vif_find_free_mid(struct wil6210_priv *wil)
{ {
u8 i; u8 i;
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
if (!wil->vifs[i]) if (!wil->vifs[i])
return i; return i;
} }
...@@ -500,7 +500,7 @@ void wil_vif_remove(struct wil6210_priv *wil, u8 mid) ...@@ -500,7 +500,7 @@ void wil_vif_remove(struct wil6210_priv *wil, u8 mid)
bool any_active = wil_has_active_ifaces(wil, true, false); bool any_active = wil_has_active_ifaces(wil, true, false);
ASSERT_RTNL(); ASSERT_RTNL();
if (mid >= wil->max_vifs) { if (mid >= GET_MAX_VIFS(wil)) {
wil_err(wil, "invalid MID: %d\n", mid); wil_err(wil, "invalid MID: %d\n", mid);
return; return;
} }
......
/* /*
* Copyright (c) 2012-2017 Qualcomm Atheros, Inc. * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
* Copyright (c) 2018, The Linux Foundation. All rights reserved. * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
...@@ -176,7 +176,7 @@ static void wil_remove_all_additional_vifs(struct wil6210_priv *wil) ...@@ -176,7 +176,7 @@ static void wil_remove_all_additional_vifs(struct wil6210_priv *wil)
struct wil6210_vif *vif; struct wil6210_vif *vif;
int i; int i;
for (i = 1; i < wil->max_vifs; i++) { for (i = 1; i < GET_MAX_VIFS(wil); i++) {
vif = wil->vifs[i]; vif = wil->vifs[i];
if (vif) { if (vif) {
wil_vif_prepare_stop(vif); wil_vif_prepare_stop(vif);
......
...@@ -26,7 +26,7 @@ static void wil_pm_wake_connected_net_queues(struct wil6210_priv *wil) ...@@ -26,7 +26,7 @@ static void wil_pm_wake_connected_net_queues(struct wil6210_priv *wil)
int i; int i;
mutex_lock(&wil->vif_mutex); mutex_lock(&wil->vif_mutex);
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
struct wil6210_vif *vif = wil->vifs[i]; struct wil6210_vif *vif = wil->vifs[i];
if (vif && test_bit(wil_vif_fwconnected, vif->status)) if (vif && test_bit(wil_vif_fwconnected, vif->status))
...@@ -40,7 +40,7 @@ static void wil_pm_stop_all_net_queues(struct wil6210_priv *wil) ...@@ -40,7 +40,7 @@ static void wil_pm_stop_all_net_queues(struct wil6210_priv *wil)
int i; int i;
mutex_lock(&wil->vif_mutex); mutex_lock(&wil->vif_mutex);
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
struct wil6210_vif *vif = wil->vifs[i]; struct wil6210_vif *vif = wil->vifs[i];
if (vif) if (vif)
...@@ -123,7 +123,7 @@ int wil_can_suspend(struct wil6210_priv *wil, bool is_runtime) ...@@ -123,7 +123,7 @@ int wil_can_suspend(struct wil6210_priv *wil, bool is_runtime)
/* interface is running */ /* interface is running */
mutex_lock(&wil->vif_mutex); mutex_lock(&wil->vif_mutex);
for (i = 0; i < wil->max_vifs; i++) { for (i = 0; i < GET_MAX_VIFS(wil); i++) {
struct wil6210_vif *vif = wil->vifs[i]; struct wil6210_vif *vif = wil->vifs[i];
if (!vif) if (!vif)
......
...@@ -1061,6 +1061,7 @@ struct wil6210_priv { ...@@ -1061,6 +1061,7 @@ struct wil6210_priv {
#define vif_to_wil(v) (v->wil) #define vif_to_wil(v) (v->wil)
#define vif_to_ndev(v) (v->ndev) #define vif_to_ndev(v) (v->ndev)
#define vif_to_wdev(v) (&v->wdev) #define vif_to_wdev(v) (&v->wdev)
#define GET_MAX_VIFS(wil) min_t(int, (wil)->max_vifs, WIL_MAX_VIFS)
static inline struct wil6210_vif *wdev_to_vif(struct wil6210_priv *wil, static inline struct wil6210_vif *wdev_to_vif(struct wil6210_priv *wil,
struct wireless_dev *wdev) struct wireless_dev *wdev)
......
...@@ -3205,7 +3205,7 @@ static void wmi_event_handle(struct wil6210_priv *wil, ...@@ -3205,7 +3205,7 @@ static void wmi_event_handle(struct wil6210_priv *wil,
if (mid == MID_BROADCAST) if (mid == MID_BROADCAST)
mid = 0; mid = 0;
if (mid >= ARRAY_SIZE(wil->vifs) || mid >= wil->max_vifs) { if (mid >= GET_MAX_VIFS(wil)) {
wil_dbg_wmi(wil, "invalid mid %d, event skipped\n", wil_dbg_wmi(wil, "invalid mid %d, event skipped\n",
mid); mid);
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment