iwlwifi: pcie: validate RX descriptor length
authorJohannes Berg <johannes.berg@intel.com>
Wed, 9 Dec 2020 21:16:25 +0000 (23:16 +0200)
committerLuca Coelho <luciano.coelho@intel.com>
Wed, 9 Dec 2020 22:14:14 +0000 (00:14 +0200)
Validate the maximum RX descriptor length against the size
of the buffers we gave the device - if it doesn't fit then
the hardware messed up.

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.6378fb435cc0.Ib07485f3dc5999c74b03f21e7a808c50a05e353c@changeid
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
drivers/net/wireless/intel/iwlwifi/pcie/rx.c

index 94299f259518d417c0f52528588fdc54134b0b48..ed200f541bfcbefbefb4ce827d5e82f2a260e7d9 100644 (file)
@@ -1335,6 +1335,13 @@ static void iwl_pcie_rx_handle_rb(struct iwl_trans *trans,
 
                len = iwl_rx_packet_len(pkt);
                len += sizeof(u32); /* account for status word */
+
+               offset += ALIGN(len, FH_RSCSR_FRAME_ALIGN);
+
+               /* check that what the device tells us made sense */
+               if (offset > max_len)
+                       break;
+
                trace_iwlwifi_dev_rx(trans->dev, trans, pkt, len);
                trace_iwlwifi_dev_rx_data(trans->dev, trans, pkt, len);
 
@@ -1392,7 +1399,6 @@ static void iwl_pcie_rx_handle_rb(struct iwl_trans *trans,
                page_stolen |= rxcb._page_stolen;
                if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210)
                        break;
-               offset += ALIGN(len, FH_RSCSR_FRAME_ALIGN);
        }
 
        /* page was stolen from us -- free our reference */