Skip to content

Commit ff05d4b

Browse files
committed
wifi: mac80211: fix MBSSID parsing use-after-free
When we parse a multi-BSSID element, we might point some element pointers into the allocated nontransmitted_profile. However, we free this before returning, causing UAF when the relevant pointers in the parsed elements are accessed. Fix this by not allocating the scratch buffer separately but as part of the returned structure instead, that way, there are no lifetime issues with it. The scratch buffer introduction as part of the returned data here is taken from MLO feature work done by Ilan. This fixes CVE-2022-42719. Fixes: 5023b14 ("mac80211: support profile split between elements") Co-developed-by: Ilan Peer <[email protected]> Signed-off-by: Ilan Peer <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Johannes Berg <[email protected]>
1 parent 8f033d2 commit ff05d4b

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

net/mac80211/ieee80211_i.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,14 @@ struct ieee802_11_elems {
17091709

17101710
/* whether a parse error occurred while retrieving these elements */
17111711
bool parse_error;
1712+
1713+
/*
1714+
* scratch buffer that can be used for various element parsing related
1715+
* tasks, e.g., element de-fragmentation etc.
1716+
*/
1717+
size_t scratch_len;
1718+
u8 *scratch_pos;
1719+
u8 scratch[];
17121720
};
17131721

17141722
static inline struct ieee80211_local *hw_to_local(

net/mac80211/util.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,24 +1506,26 @@ ieee802_11_parse_elems_full(struct ieee80211_elems_parse_params *params)
15061506
const struct element *non_inherit = NULL;
15071507
u8 *nontransmitted_profile;
15081508
int nontransmitted_profile_len = 0;
1509+
size_t scratch_len = params->len;
15091510

1510-
elems = kzalloc(sizeof(*elems), GFP_ATOMIC);
1511+
elems = kzalloc(sizeof(*elems) + scratch_len, GFP_ATOMIC);
15111512
if (!elems)
15121513
return NULL;
15131514
elems->ie_start = params->start;
15141515
elems->total_len = params->len;
1515-
1516-
nontransmitted_profile = kmalloc(params->len, GFP_ATOMIC);
1517-
if (nontransmitted_profile) {
1518-
nontransmitted_profile_len =
1519-
ieee802_11_find_bssid_profile(params->start, params->len,
1520-
elems, params->bss,
1521-
nontransmitted_profile);
1522-
non_inherit =
1523-
cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
1524-
nontransmitted_profile,
1525-
nontransmitted_profile_len);
1526-
}
1516+
elems->scratch_len = scratch_len;
1517+
elems->scratch_pos = elems->scratch;
1518+
1519+
nontransmitted_profile = elems->scratch_pos;
1520+
nontransmitted_profile_len =
1521+
ieee802_11_find_bssid_profile(params->start, params->len,
1522+
elems, params->bss,
1523+
nontransmitted_profile);
1524+
elems->scratch_pos += nontransmitted_profile_len;
1525+
elems->scratch_len -= nontransmitted_profile_len;
1526+
non_inherit = cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
1527+
nontransmitted_profile,
1528+
nontransmitted_profile_len);
15271529

15281530
elems->crc = _ieee802_11_parse_elems_full(params, elems, non_inherit);
15291531

@@ -1557,8 +1559,6 @@ ieee802_11_parse_elems_full(struct ieee80211_elems_parse_params *params)
15571559
offsetofend(struct ieee80211_bssid_index, dtim_count))
15581560
elems->dtim_count = elems->bssid_index->dtim_count;
15591561

1560-
kfree(nontransmitted_profile);
1561-
15621562
return elems;
15631563
}
15641564

0 commit comments

Comments
 (0)