Skip to content

Commit b8aba27

Browse files
jmberg-intellucacoelho
authored andcommitted
iwlwifi: tighten RX MPDU bounds checks
Previously, we added checks that the contained MPDU size is long enough, but really we should also check that the notification itself fits into the data. Add some checks for that. Also add unlikely() annotations on the previously added checks. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Luca Coelho <luciano.coelho@intel.com> Link: https://lore.kernel.org/r/iwlwifi.20201209231352.51cc04cf1e3e.I7bfd6809f8f5feb75f79397646e6656e95688a0e@changeid Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
1 parent ac1a98e commit b8aba27

3 files changed

Lines changed: 33 additions & 10 deletions

File tree

‎drivers/net/wireless/intel/iwlwifi/dvm/rx.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,12 @@ static void iwlagn_rx_reply_rx(struct iwl_priv *priv,
794794
IWL_ERR(priv, "MPDU frame without cached PHY data\n");
795795
return;
796796
}
797+
798+
if (unlikely(pkt_len < sizeof(*amsdu))) {
799+
IWL_DEBUG_DROP(priv, "Bad REPLY_RX_MPDU_CMD size\n");
800+
return;
801+
}
802+
797803
phy_res = &priv->last_phy_res;
798804
amsdu = (struct iwl_rx_mpdu_res_start *)pkt->data;
799805
header = (struct ieee80211_hdr *)(pkt->data + sizeof(*amsdu));

‎drivers/net/wireless/intel/iwlwifi/mvm/rx.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ void iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct napi_struct *napi,
298298
u32 rx_pkt_status;
299299
u8 crypt_len = 0;
300300

301+
if (unlikely(pkt_len < sizeof(*rx_res))) {
302+
IWL_DEBUG_DROP(mvm, "Bad REPLY_RX_MPDU_CMD size\n");
303+
return;
304+
}
305+
301306
phy_info = &mvm->last_phy_info;
302307
rx_res = (struct iwl_rx_mpdu_res_start *)pkt->data;
303308
hdr = (struct ieee80211_hdr *)(pkt->data + sizeof(*rx_res));

‎drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,30 +1574,38 @@ void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi,
15741574
struct iwl_rx_packet *pkt = rxb_addr(rxb);
15751575
struct iwl_rx_mpdu_desc *desc = (void *)pkt->data;
15761576
struct ieee80211_hdr *hdr;
1577-
u32 len = le16_to_cpu(desc->mpdu_len);
1577+
u32 len;
15781578
u32 pkt_len = iwl_rx_packet_payload_len(pkt);
15791579
u32 rate_n_flags, gp2_on_air_rise;
1580-
u16 phy_info = le16_to_cpu(desc->phy_info);
1580+
u16 phy_info;
15811581
struct ieee80211_sta *sta = NULL;
15821582
struct sk_buff *skb;
15831583
u8 crypt_len = 0, channel, energy_a, energy_b;
15841584
size_t desc_size;
15851585
struct iwl_mvm_rx_phy_data phy_data = {
1586-
.d4 = desc->phy_data4,
15871586
.info_type = IWL_RX_PHY_INFO_TYPE_NONE,
15881587
};
15891588
bool csi = false;
15901589

15911590
if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
15921591
return;
15931592

1593+
if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210)
1594+
desc_size = sizeof(*desc);
1595+
else
1596+
desc_size = IWL_RX_DESC_SIZE_V1;
1597+
1598+
if (unlikely(pkt_len < desc_size)) {
1599+
IWL_DEBUG_DROP(mvm, "Bad REPLY_RX_MPDU_CMD size\n");
1600+
return;
1601+
}
1602+
15941603
if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) {
15951604
rate_n_flags = le32_to_cpu(desc->v3.rate_n_flags);
15961605
channel = desc->v3.channel;
15971606
gp2_on_air_rise = le32_to_cpu(desc->v3.gp2_on_air_rise);
15981607
energy_a = desc->v3.energy_a;
15991608
energy_b = desc->v3.energy_b;
1600-
desc_size = sizeof(*desc);
16011609

16021610
phy_data.d0 = desc->v3.phy_data0;
16031611
phy_data.d1 = desc->v3.phy_data1;
@@ -1609,24 +1617,28 @@ void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi,
16091617
gp2_on_air_rise = le32_to_cpu(desc->v1.gp2_on_air_rise);
16101618
energy_a = desc->v1.energy_a;
16111619
energy_b = desc->v1.energy_b;
1612-
desc_size = IWL_RX_DESC_SIZE_V1;
16131620

16141621
phy_data.d0 = desc->v1.phy_data0;
16151622
phy_data.d1 = desc->v1.phy_data1;
16161623
phy_data.d2 = desc->v1.phy_data2;
16171624
phy_data.d3 = desc->v1.phy_data3;
16181625
}
16191626

1620-
if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD)
1621-
phy_data.info_type =
1622-
le32_get_bits(phy_data.d1,
1623-
IWL_RX_PHY_DATA1_INFO_TYPE_MASK);
1627+
len = le16_to_cpu(desc->mpdu_len);
16241628

1625-
if (len + desc_size > pkt_len) {
1629+
if (unlikely(len + desc_size > pkt_len)) {
16261630
IWL_DEBUG_DROP(mvm, "FW lied about packet len\n");
16271631
return;
16281632
}
16291633

1634+
phy_info = le16_to_cpu(desc->phy_info);
1635+
phy_data.d4 = desc->phy_data4;
1636+
1637+
if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD)
1638+
phy_data.info_type =
1639+
le32_get_bits(phy_data.d1,
1640+
IWL_RX_PHY_DATA1_INFO_TYPE_MASK);
1641+
16301642
hdr = (void *)(pkt->data + desc_size);
16311643
/* Dont use dev_alloc_skb(), we'll have enough headroom once
16321644
* ieee80211_hdr pulled.

0 commit comments

Comments
 (0)