The scan response handler indexes into TSF and channel-band TLV arrays using a loop counter derived from the number of BSS entries, but never checks whether the TLV data is large enough. A firmware response with fewer TLV entries than BSS entries leads to reads past the TLV buffer. Add bounds checks that verify each indexed access falls within the TLV data length before dereferencing. Initialize chan_band to NULL and fw_tsf to zero at the start of each iteration so that a short TLV does not leave stale values from the previous BSS entry. Gate the neighbor-discovery branch on chan_band being non-NULL to prevent dereferencing an uninitialized pointer when the bounds check rejects the current entry. Fixes: 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x") Cc: stable@vger.kernel.org Signed-off-by: Tristan Madani --- drivers/net/wireless/nxp/nxpwifi/scan.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/nxp/nxpwifi/scan.c b/drivers/net/wireless/nxp/nxpwifi/scan.c index 67d7ff2f10c59..304113b24e5cf 100644 --- a/drivers/net/wireless/nxp/nxpwifi/scan.c +++ b/drivers/net/wireless/nxp/nxpwifi/scan.c @@ -1993,23 +1993,36 @@ int nxpwifi_ret_802_11_scan(struct nxpwifi_private *priv, } for (idx = 0; idx < scan_rsp->number_of_sets && bytes_left; idx++) { + chan_band = NULL; + fw_tsf = 0; /* * If a TSF TLV is present, save its TSF value in fw_tsf. This * is the firmware TSF at the time the beacon or probe response * was received. */ if (tsf_tlv) - memcpy(&fw_tsf, &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE], - sizeof(fw_tsf)); + if ((idx + 1) * TSF_DATA_SIZE <= + le16_to_cpu(tsf_tlv->header.len)) + memcpy(&fw_tsf, + &tsf_tlv->tsf_data[idx * + TSF_DATA_SIZE], + sizeof(fw_tsf)); if (chan_band_tlv) { - chan_band = &chan_band_tlv->chan_band_param[idx]; - radio_type = &chan_band->radio_type; + if ((idx + 1) * sizeof(*chan_band) <= + le16_to_cpu(chan_band_tlv->header.len)) { + chan_band = + &chan_band_tlv->chan_band_param[idx]; + radio_type = &chan_band->radio_type; + } else { + chan_band = NULL; + radio_type = NULL; + } } else { radio_type = NULL; } - if (chan_band_tlv && adapter->nd_info) { + if (chan_band && chan_band_tlv && adapter->nd_info) { adapter->nd_info->matches[idx] = kzalloc(sizeof(*pmatch) + sizeof(u32), GFP_ATOMIC); -- 2.47.3