Skip to content

Commit dc92e54

Browse files
benzeajmberg-intel
authored andcommitted
wifi: cfg80211: use structs for TBTT information access
Make the data access a bit nicer overall by using structs. There is a small change here to also accept a TBTT information length of eight bytes as we do not require the 20 MHz PSD information. This also fixes a bug reading the short SSID on big endian machines. Signed-off-by: Benjamin Berg <[email protected]> Signed-off-by: Gregory Greenman <[email protected]> Link: https://lore.kernel.org/r/20230618214436.4c3f8901c1bc.Ic3e94fd6e1bccff7948a252ad3bb87e322690a17@changeid Signed-off-by: Johannes Berg <[email protected]>
1 parent 50181fe commit dc92e54

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

include/linux/ieee80211.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4483,9 +4483,6 @@ static inline bool for_each_element_completed(const struct element *element,
44834483
#define IEEE80211_AP_INFO_TBTT_HDR_COUNT 0xF0
44844484
#define IEEE80211_TBTT_INFO_TYPE_TBTT 0
44854485
#define IEEE80211_TBTT_INFO_TYPE_MLD 1
4486-
#define IEEE80211_TBTT_INFO_OFFSET_BSSID_BSS_PARAM 9
4487-
#define IEEE80211_TBTT_INFO_OFFSET_BSSID_SSSID_BSS_PARAM 13
4488-
#define IEEE80211_TBTT_INFO_OFFSET_BSSID_SSSID_BSS_PARAM_MLD_PARAM 16
44894486

44904487
#define IEEE80211_RNR_TBTT_PARAMS_OCT_RECOMMENDED 0x01
44914488
#define IEEE80211_RNR_TBTT_PARAMS_SAME_SSID 0x02

net/wireless/scan.c

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -574,39 +574,41 @@ static void cfg80211_free_coloc_ap_list(struct list_head *coloc_ap_list)
574574
static int cfg80211_parse_ap_info(struct cfg80211_colocated_ap *entry,
575575
const u8 *pos, u8 length,
576576
const struct element *ssid_elem,
577-
int s_ssid_tmp)
577+
u32 s_ssid_tmp)
578578
{
579-
/* skip the TBTT offset */
580-
pos++;
579+
u8 bss_params;
581580

582-
/* ignore entries with invalid BSSID */
583-
if (!is_valid_ether_addr(pos))
584-
return -EINVAL;
585-
586-
memcpy(entry->bssid, pos, ETH_ALEN);
587-
pos += ETH_ALEN;
581+
/* The length is already verified by the caller to contain bss_params */
582+
if (length > sizeof(struct ieee80211_tbtt_info_7_8_9)) {
583+
struct ieee80211_tbtt_info_ge_11 *tbtt_info = (void *)pos;
588584

589-
if (length >= IEEE80211_TBTT_INFO_OFFSET_BSSID_SSSID_BSS_PARAM) {
590-
memcpy(&entry->short_ssid, pos,
591-
sizeof(entry->short_ssid));
585+
memcpy(entry->bssid, tbtt_info->bssid, ETH_ALEN);
586+
entry->short_ssid = le32_to_cpu(tbtt_info->short_ssid);
592587
entry->short_ssid_valid = true;
593-
pos += 4;
588+
589+
bss_params = tbtt_info->bss_params;
590+
} else {
591+
struct ieee80211_tbtt_info_7_8_9 *tbtt_info = (void *)pos;
592+
593+
memcpy(entry->bssid, tbtt_info->bssid, ETH_ALEN);
594+
595+
bss_params = tbtt_info->bss_params;
594596
}
595597

598+
/* ignore entries with invalid BSSID */
599+
if (!is_valid_ether_addr(entry->bssid))
600+
return -EINVAL;
601+
596602
/* skip non colocated APs */
597-
if (!cfg80211_parse_bss_param(*pos, entry))
603+
if (!cfg80211_parse_bss_param(bss_params, entry))
598604
return -EINVAL;
599-
pos++;
600605

601-
if (length == IEEE80211_TBTT_INFO_OFFSET_BSSID_BSS_PARAM) {
602-
/*
603-
* no information about the short ssid. Consider the entry valid
604-
* for now. It would later be dropped in case there are explicit
605-
* SSIDs that need to be matched
606-
*/
607-
if (!entry->same_ssid)
608-
return 0;
609-
}
606+
/* no information about the short ssid. Consider the entry valid
607+
* for now. It would later be dropped in case there are explicit
608+
* SSIDs that need to be matched
609+
*/
610+
if (!entry->same_ssid && !entry->short_ssid_valid)
611+
return 0;
610612

611613
if (entry->same_ssid) {
612614
entry->short_ssid = s_ssid_tmp;
@@ -617,10 +619,10 @@ static int cfg80211_parse_ap_info(struct cfg80211_colocated_ap *entry,
617619
* cfg80211_parse_colocated_ap(), before calling this
618620
* function.
619621
*/
620-
memcpy(&entry->ssid, &ssid_elem->data,
621-
ssid_elem->datalen);
622+
memcpy(&entry->ssid, &ssid_elem->data, ssid_elem->datalen);
622623
entry->ssid_len = ssid_elem->datalen;
623624
}
625+
624626
return 0;
625627
}
626628

@@ -682,8 +684,11 @@ static int cfg80211_parse_colocated_ap(const struct cfg80211_bss_ies *ies,
682684
* next AP info
683685
*/
684686
if (band != NL80211_BAND_6GHZ ||
685-
(length != IEEE80211_TBTT_INFO_OFFSET_BSSID_BSS_PARAM &&
686-
length < IEEE80211_TBTT_INFO_OFFSET_BSSID_SSSID_BSS_PARAM)) {
687+
!(length == offsetofend(struct ieee80211_tbtt_info_7_8_9,
688+
bss_params) ||
689+
length == sizeof(struct ieee80211_tbtt_info_7_8_9) ||
690+
length >= offsetofend(struct ieee80211_tbtt_info_ge_11,
691+
bss_params))) {
687692
pos += count * length;
688693
continue;
689694
}

0 commit comments

Comments
 (0)