realtek: consistently flood RMA frames
[openwrt/staging/noltari.git] / package / kernel / mac80211 / patches / subsys / 353-wifi-mac80211-fix-MBSSID-parsing-use-after-free.patch
1 From: Johannes Berg <johannes.berg@intel.com>
2 Date: Wed, 28 Sep 2022 22:07:15 +0200
3 Subject: [PATCH] wifi: mac80211: fix MBSSID parsing use-after-free
4
5 commit ff05d4b45dd89b922578dac497dcabf57cf771c6
6
7 When we parse a multi-BSSID element, we might point some
8 element pointers into the allocated nontransmitted_profile.
9 However, we free this before returning, causing UAF when the
10 relevant pointers in the parsed elements are accessed.
11
12 Fix this by not allocating the scratch buffer separately but
13 as part of the returned structure instead, that way, there
14 are no lifetime issues with it.
15
16 The scratch buffer introduction as part of the returned data
17 here is taken from MLO feature work done by Ilan.
18
19 This fixes CVE-2022-42719.
20
21 Fixes: 5023b14cf4df ("mac80211: support profile split between elements")
22 Co-developed-by: Ilan Peer <ilan.peer@intel.com>
23 Signed-off-by: Ilan Peer <ilan.peer@intel.com>
24 Reviewed-by: Kees Cook <keescook@chromium.org>
25 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
26 ---
27
28 --- a/net/mac80211/ieee80211_i.h
29 +++ b/net/mac80211/ieee80211_i.h
30 @@ -1611,6 +1611,14 @@ struct ieee802_11_elems {
31
32 /* whether a parse error occurred while retrieving these elements */
33 bool parse_error;
34 +
35 + /*
36 + * scratch buffer that can be used for various element parsing related
37 + * tasks, e.g., element de-fragmentation etc.
38 + */
39 + size_t scratch_len;
40 + u8 *scratch_pos;
41 + u8 scratch[];
42 };
43
44 static inline struct ieee80211_local *hw_to_local(
45 --- a/net/mac80211/util.c
46 +++ b/net/mac80211/util.c
47 @@ -1478,24 +1478,25 @@ struct ieee802_11_elems *ieee802_11_pars
48 u8 *nontransmitted_profile;
49 int nontransmitted_profile_len = 0;
50
51 - elems = kzalloc(sizeof(*elems), GFP_ATOMIC);
52 + elems = kzalloc(sizeof(*elems) + len, GFP_ATOMIC);
53 if (!elems)
54 return NULL;
55 elems->ie_start = start;
56 elems->total_len = len;
57
58 - nontransmitted_profile = kmalloc(len, GFP_ATOMIC);
59 - if (nontransmitted_profile) {
60 - nontransmitted_profile_len =
61 - ieee802_11_find_bssid_profile(start, len, elems,
62 - transmitter_bssid,
63 - bss_bssid,
64 - nontransmitted_profile);
65 - non_inherit =
66 - cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
67 - nontransmitted_profile,
68 - nontransmitted_profile_len);
69 - }
70 + elems->scratch_len = len;
71 + elems->scratch_pos = elems->scratch;
72 +
73 + nontransmitted_profile = elems->scratch_pos;
74 + nontransmitted_profile_len =
75 + ieee802_11_find_bssid_profile(start, len, elems,
76 + transmitter_bssid,
77 + bss_bssid,
78 + nontransmitted_profile);
79 + non_inherit =
80 + cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
81 + nontransmitted_profile,
82 + nontransmitted_profile_len);
83
84 crc = _ieee802_11_parse_elems_crc(start, len, action, elems, filter,
85 crc, non_inherit);
86 @@ -1524,8 +1525,6 @@ struct ieee802_11_elems *ieee802_11_pars
87 offsetofend(struct ieee80211_bssid_index, dtim_count))
88 elems->dtim_count = elems->bssid_index->dtim_count;
89
90 - kfree(nontransmitted_profile);
91 -
92 elems->crc = crc;
93
94 return elems;