wifi: mac80211: fix MBSSID parsing use-after-free
authorJohannes Berg <johannes.berg@intel.com>
Thu, 13 Oct 2022 18:16:01 +0000 (20:16 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 15 Oct 2022 05:59:05 +0000 (07:59 +0200)
commit ff05d4b45dd89b922578dac497dcabf57cf771c6

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: 5023b14cf4df ("mac80211: support profile split between elements")
Co-developed-by: Ilan Peer <ilan.peer@intel.com>
Signed-off-by: Ilan Peer <ilan.peer@intel.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Cc: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/mac80211/ieee80211_i.h
net/mac80211/util.c

index 3633e49239c7864099c19b81b4addc3490abd81c..21549a440b38c1f1169277dc1506d93098a4bd47 100644 (file)
@@ -1613,6 +1613,14 @@ struct ieee802_11_elems {
 
        /* whether a parse error occurred while retrieving these elements */
        bool parse_error;
+
+       /*
+        * scratch buffer that can be used for various element parsing related
+        * tasks, e.g., element de-fragmentation etc.
+        */
+       size_t scratch_len;
+       u8 *scratch_pos;
+       u8 scratch[];
 };
 
 static inline struct ieee80211_local *hw_to_local(
index 2ac61e68b6b48c4f358d078a24268df0e3672270..354badd32793ad1a25ff9a60c0247328a7c97dd1 100644 (file)
@@ -1475,24 +1475,25 @@ struct ieee802_11_elems *ieee802_11_parse_elems_crc(const u8 *start, size_t len,
        u8 *nontransmitted_profile;
        int nontransmitted_profile_len = 0;
 
-       elems = kzalloc(sizeof(*elems), GFP_ATOMIC);
+       elems = kzalloc(sizeof(*elems) + len, GFP_ATOMIC);
        if (!elems)
                return NULL;
        elems->ie_start = start;
        elems->total_len = len;
 
-       nontransmitted_profile = kmalloc(len, GFP_ATOMIC);
-       if (nontransmitted_profile) {
-               nontransmitted_profile_len =
-                       ieee802_11_find_bssid_profile(start, len, elems,
-                                                     transmitter_bssid,
-                                                     bss_bssid,
-                                                     nontransmitted_profile);
-               non_inherit =
-                       cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
-                                              nontransmitted_profile,
-                                              nontransmitted_profile_len);
-       }
+       elems->scratch_len = len;
+       elems->scratch_pos = elems->scratch;
+
+       nontransmitted_profile = elems->scratch_pos;
+       nontransmitted_profile_len =
+               ieee802_11_find_bssid_profile(start, len, elems,
+                                             transmitter_bssid,
+                                             bss_bssid,
+                                             nontransmitted_profile);
+       non_inherit =
+               cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
+                                      nontransmitted_profile,
+                                      nontransmitted_profile_len);
 
        crc = _ieee802_11_parse_elems_crc(start, len, action, elems, filter,
                                          crc, non_inherit);
@@ -1521,8 +1522,6 @@ struct ieee802_11_elems *ieee802_11_parse_elems_crc(const u8 *start, size_t len,
            offsetofend(struct ieee80211_bssid_index, dtim_count))
                elems->dtim_count = elems->bssid_index->dtim_count;
 
-       kfree(nontransmitted_profile);
-
        elems->crc = crc;
 
        return elems;