]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
wifi: iwlwifi: add a few rate index validity checks
authorAnjaneyulu <pagadala.yesu.anjaneyulu@intel.com>
Wed, 14 Jun 2023 09:41:37 +0000 (12:41 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 1 Feb 2025 17:24:01 +0000 (18:24 +0100)
commit efbe8f81952fe469d38655744627d860879dcde8 upstream.

Validate index before access iwl_rate_mcs to keep rate->index
inside the valid boundaries. Use MCS_0_INDEX if index is less
than MCS_0_INDEX and MCS_9_INDEX if index is greater then
MCS_9_INDEX.

Signed-off-by: Anjaneyulu <pagadala.yesu.anjaneyulu@intel.com>
Signed-off-by: Gregory Greenman <gregory.greenman@intel.com>
Link: https://lore.kernel.org/r/20230614123447.79f16b3aef32.If1137f894775d6d07b78cbf3a6163ffce6399507@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/wireless/intel/iwlwifi/dvm/rs.c
drivers/net/wireless/intel/iwlwifi/mvm/rs.c

index 548540dd0c0f75581fce237b2390e9157102bd65..958bfc38d39006e9549475bd3f46c28531d3aea3 100644 (file)
@@ -130,7 +130,7 @@ static int iwl_hwrate_to_plcp_idx(u32 rate_n_flags)
                                return idx;
        }
 
-       return -1;
+       return IWL_RATE_INVALID;
 }
 
 static void rs_rate_scale_perform(struct iwl_priv *priv,
@@ -3151,7 +3151,10 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
        for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
                index = iwl_hwrate_to_plcp_idx(
                        le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags));
-               if (is_legacy(tbl->lq_type)) {
+               if (index == IWL_RATE_INVALID) {
+                       desc += sprintf(buff + desc, " rate[%d] 0x%X invalid rate\n",
+                               i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags));
+               } else if (is_legacy(tbl->lq_type)) {
                        desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n",
                                i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
                                iwl_rate_mcs[index].mbps);
index b97708cb869d56e1fa3f9656b304fe1c81e169b2..9f4422e155d90b363f035d8bf7868f4876fe3127 100644 (file)
@@ -1119,10 +1119,13 @@ static void rs_get_lower_rate_down_column(struct iwl_lq_sta *lq_sta,
 
                rate->bw = RATE_MCS_CHAN_WIDTH_20;
 
-               WARN_ON_ONCE(rate->index < IWL_RATE_MCS_0_INDEX ||
-                            rate->index > IWL_RATE_MCS_9_INDEX);
+               if (WARN_ON_ONCE(rate->index < IWL_RATE_MCS_0_INDEX))
+                       rate->index = rs_ht_to_legacy[IWL_RATE_MCS_0_INDEX];
+               else if (WARN_ON_ONCE(rate->index > IWL_RATE_MCS_9_INDEX))
+                       rate->index = rs_ht_to_legacy[IWL_RATE_MCS_9_INDEX];
+               else
+                       rate->index = rs_ht_to_legacy[rate->index];
 
-               rate->index = rs_ht_to_legacy[rate->index];
                rate->ldpc = false;
        } else {
                /* Downgrade to SISO with same MCS if in MIMO  */