mac80211: mesh: clean up rx_bcn_presp API
PATCH 1/6 mac80211: mesh: clean up rx_bcn_presp API
From: Johannes Berg <[email protected]>
commit a5b983c6073140b624f64e79fea6d33c3e4315a0 upstream.
We currently pass the entire elements to the rx_bcn_presp() method, but only need mesh_config. Additionally, we use the length of the elements to calculate back the entire frame's length, but that's confusing - just pass the length of the frame instead.
--- net/mac80211/ieee80211_i.h | 7 +++---- net/mac80211/mesh.c | 4 ++-- net/mac80211/mesh_sync.c | 26 ++++++++++++-------------- 3 files changed, 17 insertions(+), 20 deletions(-)
net/mac80211/ieee80211_i.h +3 -4
@@ -631,10 +631,9 @@ struct ieee80211_if_ocb {*/ struct ieee802_11_elems ;struct ieee80211_mesh_sync_ops { -void (*rx_bcn_presp)(struct ieee80211_sub_if_data *sdata, -u16 stype, -struct ieee80211_mgmt *mgmt, -struct ieee802_11_elems *elems, +void (*rx_bcn_presp)(struct ieee80211_sub_if_data *sdata,u16 stype, +struct ieee80211_mgmt *mgmt,unsigned int len, +const struct ieee80211_meshconf_ie *mesh_cfg,struct ieee80211_rx_status *rx_status);/* should be called with beacon_data under RCU read lock */
net/mac80211/mesh.c +2 -2
@@ -1354,8 +1354,8 @@ static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata, }if (ifmsh->sync_ops) - ifmsh->sync_ops->rx_bcn_presp (sdata, - stype, mgmt, &elems, rx_status); + ifmsh->sync_ops->rx_bcn_presp (sdata, stype, mgmt, len, + elems.mesh_config, rx_status); }int ieee80211_mesh_finish_csa (struct ieee80211_sub_if_data *sdata)
net/mac80211/mesh_sync.c +12 -14
@@ -3,6 +3,7 @@* Copyright 2011-2012, Pavel Zubarev <[email protected]> * Copyright 2011-2012, Marco Porsch <[email protected]> * Copyright 2011-2012, cozybit Inc. +* Copyright (C) 2021 Intel Corporation */ #include "ieee80211_i.h"
@@ -35,12 +36,12 @@ struct sync_method {/** * mesh_peer_tbtt_adjusting - check if an mp is currently adjusting its TBTT * -* @ie: information elements of a management frame from the mesh peer +* @cfg: mesh config element from the mesh peer (or %NULL) */ -static bool mesh_peer_tbtt_adjusting (struct ieee802_11_elems *ie) +static bool mesh_peer_tbtt_adjusting (const struct ieee80211_meshconf_ie *cfg) { -return (ie->mesh_config->meshconf_cap & -IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING ) !=0 ; +return cfg && + (cfg->meshconf_cap &IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING ); }void mesh_sync_adjust_tsf (struct ieee80211_sub_if_data *sdata)
@@ -76,11 +77,11 @@ void mesh_sync_adjust_tsf(struct ieee80211_sub_if_data *sdata) } } -static void mesh_sync_offset_rx_bcn_presp (struct ieee80211_sub_if_data *sdata, -u16 stype, -struct ieee80211_mgmt *mgmt, -struct ieee802_11_elems *elems, -struct ieee80211_rx_status *rx_status) +static void +mesh_sync_offset_rx_bcn_presp (struct ieee80211_sub_if_data *sdata,u16 stype, +struct ieee80211_mgmt *mgmt,unsigned int len, +const struct ieee80211_meshconf_ie *mesh_cfg, +struct ieee80211_rx_status *rx_status) {struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;struct ieee80211_local *local = sdata->local;
@@ -101,10 +102,7 @@ static void mesh_sync_offset_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,*/ if (ieee80211_have_rx_timestamp (rx_status)) t_r =ieee80211_calculate_rx_timestamp (local, rx_status, -24 +12 + - elems->total_len + -FCS_LEN , -24 ); + len +FCS_LEN ,24 );else t_r =drv_get_tsf (local, sdata);
@@ -119,7 +117,7 @@ static void mesh_sync_offset_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,* dot11MeshNbrOffsetMaxNeighbor non-peer non-MBSS neighbors */ -if (elems->mesh_config &&mesh_peer_tbtt_adjusting (elems)) { +if (mesh_peer_tbtt_adjusting (mesh_cfg)) {msync_dbg (sdata,"STA %pM : is adjusting TBTT\n" , sta->sta.addr); goto no_sync;
Signature · 1 line
2.36.1
PATCH 2/6 mac80211: move CRC into struct ieee802_11_elems
From: Johannes Berg <[email protected]>
commit c6e37ed498f958254b5459253199e816b6bfc52f upstream.
We're currently returning this value, but to prepare for returning the allocated structure, move it into there.
--- net/mac80211/ieee80211_i.h | 9 +++++---- net/mac80211/mlme.c | 9 +++++---- net/mac80211/util.c | 10 +++++----- 3 files changed, 15 insertions(+), 13 deletions(-)
net/mac80211/ieee80211_i.h +5 -4
@@ -1532,6 +1532,7 @@ struct ieee80211_csa_ie {struct ieee802_11_elems {const u8 *ie_start;size_t total_len; +u32 crc;/* pointers to IEs */ const struct ieee80211_tdls_lnkie *lnk_id;
@@ -2218,10 +2219,10 @@ static inline void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata,ieee80211_tx_skb_tid (sdata, skb,7 ); } -u32 ieee802_11_parse_elems_crc (const u8 *start,size_t len,bool action, -struct ieee802_11_elems *elems, -u64 filter,u32 crc,u8 *transmitter_bssid, -u8 *bss_bssid); +void ieee802_11_parse_elems_crc (const u8 *start,size_t len,bool action, +struct ieee802_11_elems *elems, +u64 filter,u32 crc,u8 *transmitter_bssid, +u8 *bss_bssid); static inline void ieee802_11_parse_elems(const u8 *start, size_t len, bool action, struct ieee802_11_elems *elems,
net/mac80211/mlme.c +5 -4
@@ -4102,10 +4102,11 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,*/ if (!ieee80211_is_s1g_beacon (hdr->frame_control)) ncrc =crc32_be (0 , (void *)&mgmt->u.beacon.beacon_int,4 ); - ncrc =ieee802_11_parse_elems_crc (variable, - len - baselen, false, &elems, - care_about_ies, ncrc, - mgmt->bssid, bssid); +ieee802_11_parse_elems_crc (variable, + len - baselen, false, &elems, + care_about_ies, ncrc, + mgmt->bssid, bssid); + ncrc = elems.crc;if (ieee80211_hw_check (&local->hw,PS_NULLFUNC_STACK ) &&ieee80211_check_tim (elems.tim, elems.tim_len, bss_conf->aid)) {
net/mac80211/util.c +5 -5
@@ -1468,10 +1468,10 @@ static size_t ieee802_11_find_bssid_profile(const u8 *start, size_t len,return found ? profile_len :0 ; } -u32 ieee802_11_parse_elems_crc (const u8 *start,size_t len,bool action, -struct ieee802_11_elems *elems, -u64 filter,u32 crc,u8 *transmitter_bssid, -u8 *bss_bssid) +void ieee802_11_parse_elems_crc (const u8 *start,size_t len,bool action, +struct ieee802_11_elems *elems, +u64 filter,u32 crc,u8 *transmitter_bssid, +u8 *bss_bssid) {const struct element *non_inherit =NULL ;u8 *nontransmitted_profile;
@@ -1523,7 +1523,7 @@ u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,kfree (nontransmitted_profile); -return crc; + elems->crc = crc; } void ieee80211_regulatory_limit_wmm_params(struct ieee80211_sub_if_data *sdata,
Signature · 1 line
2.36.1
PATCH 3/6 mac80211: mlme: find auth challenge directly
In reply to Felix FietkauFrom: Johannes Berg <[email protected]>
commit 49a765d6785e99157ff5091cc37485732496864e upstream.
There's no need to parse all elements etc. just to find the authentication challenge - use cfg80211_find_elem() instead. This also allows us to remove WLAN_EID_CHALLENGE handling from the element parsing entirely.
--- net/mac80211/ieee80211_i.h | 2 -- net/mac80211/mlme.c | 11 ++++++----- net/mac80211/util.c | 4 ---- 3 files changed, 6 insertions(+), 11 deletions(-)
net/mac80211/ieee80211_i.h +0 -2
@@ -1542,7 +1542,6 @@ struct ieee802_11_elems {const u8 *supp_rates;const u8 *ds_params;const struct ieee80211_tim_ie *tim; -const u8 *challenge;const u8 *rsn;const u8 *rsnx;const u8 *erp_info;
@@ -1596,7 +1595,6 @@ struct ieee802_11_elems {u8 ssid_len;u8 supp_rates_len;u8 tim_len; -u8 challenge_len;u8 rsn_len;u8 rsnx_len;u8 ext_supp_rates_len;
net/mac80211/mlme.c +6 -5
@@ -2889,17 +2889,17 @@ static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, {struct ieee80211_local *local = sdata->local;struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; +const struct element *challenge;u8 *pos; -struct ieee802_11_elems elems;u32 tx_flags =0 ;struct ieee80211_prep_tx_info info = { .subtype =IEEE80211_STYPE_AUTH , }; pos = mgmt->u.auth.variable; -ieee802_11_parse_elems (pos, len - (pos - (u8 *)mgmt), false, &elems, - mgmt->bssid, auth_data->bss->bssid); -if (!elems.challenge) + challenge =cfg80211_find_elem (WLAN_EID_CHALLENGE , pos, + len - (pos - (u8 *)mgmt)); +if (!challenge)return ; auth_data->expected_transaction =4 ;drv_mgd_prepare_tx (sdata->local, sdata, &info);
@@ -2907,7 +2907,8 @@ static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, tx_flags =IEEE80211_TX_CTL_REQ_TX_STATUS |IEEE80211_TX_INTFL_MLME_CONN_TX ;ieee80211_send_auth (sdata,3 , auth_data->algorithm,0 , - elems.challenge -2 , elems.challenge_len +2 , + (void *)challenge, + challenge->datalen +sizeof (*challenge), auth_data->bss->bssid, auth_data->bss->bssid, auth_data->key, auth_data->key_len, auth_data->key_idx, tx_flags);
net/mac80211/util.c +0 -4
@@ -1117,10 +1117,6 @@ _ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action, }else elem_parse_failed = true;break ; -case WLAN_EID_CHALLENGE : - elems->challenge = pos; - elems->challenge_len = elen; -break ;case WLAN_EID_VENDOR_SPECIFIC :if (elen >=4 && pos[0 ] ==0x00 && pos[1 ] ==0x50 && pos[2 ] ==0xf2 ) {
Signature · 1 line
2.36.1
PATCH 4/6 mac80211: always allocate struct ieee802_11_elems
In reply to Felix FietkauFrom: Johannes Berg <[email protected]>
As the 802.11 spec evolves, we need to parse more and more elements. This is causing the struct to grow, and we can no longer get away with putting it on the stack.
Change the API to always dynamically allocate and return an allocated pointer that must be kfree()d later.
As an alternative, I contemplated a scheme whereby we'd say in the code which elements we needed, e.g.
DECLARE_ELEMENT_PARSER(elems,
SUPPORTED_CHANNELS,
CHANNEL_SWITCH,
EXT(KEY_DELIVERY));
ieee802_11_parse_elems(..., &elems, ...);and while I think this is possible and will save us a lot since most individual places only care about a small subset of the elements, it ended up being a bit more work since a lot of places do the parsing and then pass the struct to other functions, sometimes with multiple levels.
--- net/mac80211/agg-rx.c | 11 +-- net/mac80211/ibss.c | 25 +++--- net/mac80211/ieee80211_i.h | 22 ++--- net/mac80211/mesh.c | 85 ++++++++++-------- net/mac80211/mesh_hwmp.c | 44 +++++----- net/mac80211/mesh_plink.c | 11 +-- net/mac80211/mlme.c | 176 +++++++++++++++++++++---------------- net/mac80211/scan.c | 16 ++-- net/mac80211/tdls.c | 63 +++++++------ net/mac80211/util.c | 20 +++-- 10 files changed, 272 insertions(+), 201 deletions(-)
net/mac80211/agg-rx.c +6 -5
@@ -478,7 +478,7 @@ void ieee80211_process_addba_request(struct ieee80211_local *local, size_t len) {u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num; -struct ieee802_11_elems elems = { }; +struct ieee802_11_elems *elems =NULL ;u8 dialog_token;int ies_len;
@@ -496,16 +496,17 @@ void ieee80211_process_addba_request(struct ieee80211_local *local, ies_len = len - offsetof(struct ieee80211_mgmt , u.action.u.addba_req.variable);if (ies_len) { -ieee802_11_parse_elems (mgmt->u.action.u.addba_req.variable, - ies_len, true, &elems, mgmt->bssid,NULL ); -if (elems.parse_error) + elems =ieee802_11_parse_elems (mgmt->u.action.u.addba_req.variable, + ies_len, true, mgmt->bssid,NULL ); +if (!elems || elems->parse_error)return ; }__ieee80211_start_rx_ba_session (sta, dialog_token, timeout, start_seq_num, ba_policy, tid, buf_size, true, false, - elems.addba_ext_ie); + elems ? elems->addba_ext_ie :NULL ); +kfree (elems); } void ieee80211_manage_rx_ba_offl(struct ieee80211_vif *vif,
net/mac80211/ibss.c +15 -10
@@ -9,7 +9,7 @@* Copyright 2009, Johannes Berg <[email protected]> * Copyright 2013-2014 Intel Mobile Communications GmbH * Copyright(c) 2016 Intel Deutschland GmbH -* Copyright(c) 2018-2020 Intel Corporation +* Copyright(c) 2018-2021 Intel Corporation */ #include <linux/delay.h>
@@ -1593,7 +1593,7 @@ void ieee80211_rx_mgmt_probe_beacon(struct ieee80211_sub_if_data *sdata, struct ieee80211_rx_status *rx_status) {size_t baselen; -struct ieee802_11_elems elems; +struct ieee802_11_elems *elems; BUILD_BUG_ON(offsetof(typeof(mgmt->u.probe_resp), variable) != offsetof(typeof(mgmt->u.beacon), variable));
@@ -1606,10 +1606,14 @@ void ieee80211_rx_mgmt_probe_beacon(struct ieee80211_sub_if_data *sdata,if (baselen > len)return ; -ieee802_11_parse_elems (mgmt->u.probe_resp.variable, len - baselen, - false, &elems, mgmt->bssid,NULL ); + elems =ieee802_11_parse_elems (mgmt->u.probe_resp.variable, + len - baselen, false, + mgmt->bssid,NULL ); -ieee80211_rx_bss_info (sdata, mgmt, len, rx_status, &elems); +if (elems) { +ieee80211_rx_bss_info (sdata, mgmt, len, rx_status, elems); +kfree (elems); + } } void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
@@ -1618,7 +1622,7 @@ void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,struct ieee80211_rx_status *rx_status;struct ieee80211_mgmt *mgmt;u16 fc; -struct ieee802_11_elems elems; +struct ieee802_11_elems *elems;int ies_len; rx_status =IEEE80211_SKB_RXCB (skb);
@@ -1655,15 +1659,16 @@ void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,if (ies_len <0 )break ; -ieee802_11_parse_elems ( + elems =ieee802_11_parse_elems ( mgmt->u.action.u.chan_switch.variable, - ies_len, true, &elems, mgmt->bssid,NULL ); + ies_len, true, mgmt->bssid,NULL ); -if (elems.parse_error) +if (!elems || elems->parse_error)break ;ieee80211_rx_mgmt_spectrum_mgmt (sdata, mgmt, skb->len, - rx_status, &elems); + rx_status, elems); +kfree (elems);break ; } }
net/mac80211/ieee80211_i.h +11 -11
@@ -2217,18 +2217,18 @@ static inline void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata,ieee80211_tx_skb_tid (sdata, skb,7 ); } -void ieee802_11_parse_elems_crc (const u8 *start,size_t len,bool action, -struct ieee802_11_elems *elems, -u64 filter,u32 crc,u8 *transmitter_bssid, -u8 *bss_bssid); -static inline void ieee802_11_parse_elems (const u8 *start,size_t len, -bool action, -struct ieee802_11_elems *elems, -u8 *transmitter_bssid, -u8 *bss_bssid) +struct ieee802_11_elems *ieee802_11_parse_elems_crc (const u8 *start,size_t len, +bool action, +u64 filter,u32 crc, +const u8 *transmitter_bssid, +const u8 *bss_bssid); +static inline struct ieee802_11_elems * +ieee802_11_parse_elems (const u8 *start,size_t len,bool action, +const u8 *transmitter_bssid, +const u8 *bss_bssid) { -ieee802_11_parse_elems_crc (start, len, action, elems,0 ,0 , - transmitter_bssid, bss_bssid); +return ieee802_11_parse_elems_crc (start, len, action,0 ,0 , + transmitter_bssid, bss_bssid); }
net/mac80211/mesh.c +49 -36
173 lines not on this page · raw message
net/mac80211/mesh_hwmp.c +24 -20
75 lines not on this page · raw message
net/mac80211/mesh_plink.c +6 -5
@@ -1,7 +1,7 @@// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2008, 2009 open80211s Ltd. -* Copyright (C) 2019 Intel Corporation +* Copyright (C) 2019, 2021 Intel Corporation * Author: Luis Carlos Cobo <[email protected]> */ #include <linux/gfp.h>
@@ -1200,7 +1200,7 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt, size_t len, struct ieee80211_rx_status *rx_status) { - struct ieee802_11_elems elems; + struct ieee802_11_elems *elems;size_t baselen;u8 *baseaddr;
@@ -1228,7 +1228,8 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,if (baselen > len)return ; } -ieee802_11_parse_elems (baseaddr, len - baselen, true, &elems, - mgmt->bssid,NULL ); -mesh_process_plink_frame (sdata, mgmt, &elems, rx_status); + elems =ieee802_11_parse_elems (baseaddr, len - baselen, true, + mgmt->bssid,NULL ); +mesh_process_plink_frame (sdata, mgmt, elems, rx_status); +kfree (elems); }
net/mac80211/mlme.c +100 -76
389 lines not on this page · raw message
net/mac80211/scan.c +10 -6
@@ -9,7 +9,7 @@* Copyright 2007, Michael Wu <[email protected]> * Copyright 2013-2015 Intel Mobile Communications GmbH * Copyright 2016-2017 Intel Deutschland GmbH -* Copyright (C) 2018-2020 Intel Corporation +* Copyright (C) 2018-2021 Intel Corporation */ #include <linux/if_arp.h>
@@ -155,7 +155,7 @@ ieee80211_bss_info_update(struct ieee80211_local *local, };bool signal_valid;struct ieee80211_sub_if_data *scan_sdata; -struct ieee802_11_elems elems; +struct ieee802_11_elems *elems;size_t baselen;u8 *elements;
@@ -209,8 +209,10 @@ ieee80211_bss_info_update(struct ieee80211_local *local,if (baselen > len)return NULL ; -ieee802_11_parse_elems (elements, len - baselen, false, &elems, - mgmt->bssid, cbss->bssid); + elems =ieee802_11_parse_elems (elements, len - baselen, false, + mgmt->bssid, cbss->bssid); +if (!elems) +return NULL ;/* In case the signal is invalid update the status */ signal_valid = channel == cbss->channel;
@@ -218,15 +220,17 @@ ieee80211_bss_info_update(struct ieee80211_local *local, rx_status->flag |=RX_FLAG_NO_SIGNAL_VAL ; bss = (void *)cbss->priv; -ieee80211_update_bss_from_elems (local, bss, &elems, rx_status, beacon); +ieee80211_update_bss_from_elems (local, bss, elems, rx_status, beacon);list_for_each_entry (non_tx_cbss, &cbss->nontrans_list, nontrans_list) { non_tx_bss = (void *)non_tx_cbss->priv; -ieee80211_update_bss_from_elems (local, non_tx_bss, &elems, +ieee80211_update_bss_from_elems (local, non_tx_bss, elems, rx_status, beacon); } +kfree (elems); +return bss; }
net/mac80211/tdls.c +38 -25
154 lines not on this page · raw message
net/mac80211/util.c +13 -7
@@ -1396,8 +1396,8 @@ _ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,static size_t ieee802_11_find_bssid_profile (const u8 *start,size_t len,struct ieee802_11_elems *elems, -u8 *transmitter_bssid, -u8 *bss_bssid, +const u8 *transmitter_bssid, +const u8 *bss_bssid,u8 *nontransmitted_profile) {const struct element *elem, *sub;
@@ -1464,16 +1464,20 @@ static size_t ieee802_11_find_bssid_profile(const u8 *start, size_t len,return found ? profile_len :0 ; } -void ieee802_11_parse_elems_crc (const u8 *start,size_t len,bool action, -struct ieee802_11_elems *elems, -u64 filter,u32 crc,u8 *transmitter_bssid, -u8 *bss_bssid) +struct ieee802_11_elems *ieee802_11_parse_elems_crc (const u8 *start,size_t len, +bool action,u64 filter, +u32 crc, +const u8 *transmitter_bssid, +const u8 *bss_bssid) { +struct ieee802_11_elems *elems;const struct element *non_inherit =NULL ;u8 *nontransmitted_profile;int nontransmitted_profile_len =0 ; -memset (elems,0 ,sizeof (*elems)); + elems =kzalloc (sizeof (*elems),GFP_ATOMIC ); +if (!elems) +return NULL ; elems->ie_start = start; elems->total_len = len;
@@ -1520,6 +1524,8 @@ void ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,kfree (nontransmitted_profile); elems->crc = crc; + +return elems; } void ieee80211_regulatory_limit_wmm_params(struct ieee80211_sub_if_data *sdata,
Signature · 1 line
2.36.1
PATCH 5/6 mac80211: fix memory leaks with element parsing
In reply to Felix FietkauFrom: Johannes Berg <[email protected]>
commit 8223ac199a3849257e86ec27865dc63f034b1cf1 upstream.
My previous commit 5d24828d05f3 ("mac80211: always allocate struct ieee802_11_elems") had a few bugs and leaked the new allocated struct in a few error cases, fix that.
--- net/mac80211/agg-rx.c | 3 ++- net/mac80211/ibss.c | 10 +++++----- net/mac80211/mlme.c | 36 ++++++++++++++++++------------------ 3 files changed, 25 insertions(+), 24 deletions(-)
net/mac80211/agg-rx.c +2 -1
@@ -499,13 +499,14 @@ void ieee80211_process_addba_request(struct ieee80211_local *local, elems =ieee802_11_parse_elems (mgmt->u.action.u.addba_req.variable, ies_len, true, mgmt->bssid,NULL );if (!elems || elems->parse_error) -return ; + goto free; }__ieee80211_start_rx_ba_session (sta, dialog_token, timeout, start_seq_num, ba_policy, tid, buf_size, true, false, elems ? elems->addba_ext_ie :NULL ); +free:kfree (elems); }
net/mac80211/ibss.c +5 -5
@@ -1663,11 +1663,11 @@ void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, mgmt->u.action.u.chan_switch.variable, ies_len, true, mgmt->bssid, NULL); -if (!elems || elems->parse_error) -break ; - -ieee80211_rx_mgmt_spectrum_mgmt (sdata, mgmt, skb->len, - rx_status, elems); +if (elems && !elems->parse_error) +ieee80211_rx_mgmt_spectrum_mgmt (sdata, mgmt, + skb->len, + rx_status, + elems);kfree (elems);break ; }
net/mac80211/mlme.c +18 -18
@@ -3374,8 +3374,10 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, bss_ies =kmemdup (ies,sizeof (*ies) + ies->len,GFP_ATOMIC );rcu_read_unlock (); -if (!bss_ies) -return false; +if (!bss_ies) { + ret = false; + goto out; + } bss_elems = ieee802_11_parse_elems(bss_ies->data, bss_ies->len, false, mgmt->bssid,
@@ -4358,13 +4360,11 @@ void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, mgmt->u.action.u.chan_switch.variable, ies_len, true, mgmt->bssid, NULL); -if (!elems || elems->parse_error) -break ; - -ieee80211_sta_process_chanswitch (sdata, - rx_status->mactime, - rx_status->device_timestamp, - elems, false); +if (elems && !elems->parse_error) +ieee80211_sta_process_chanswitch (sdata, + rx_status->mactime, + rx_status->device_timestamp, + elems, false);kfree (elems); }else if (mgmt->u.action.category ==WLAN_CATEGORY_PUBLIC ) {struct ieee802_11_elems *elems;
@@ -4384,17 +4384,17 @@ void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, mgmt->u.action.u.ext_chan_switch.variable, ies_len, true, mgmt->bssid, NULL); -if (!elems || elems->parse_error) -break ; +if (elems && !elems->parse_error) { +/* for the handling code pretend it was an IE */ + elems->ext_chansw_ie = + &mgmt->u.action.u.ext_chan_switch.data; -/* for the handling code pretend this was also an IE */ - elems->ext_chansw_ie = - &mgmt->u.action.u.ext_chan_switch.data; +ieee80211_sta_process_chanswitch (sdata, + rx_status->mactime, + rx_status->device_timestamp, + elems, false); + } -ieee80211_sta_process_chanswitch (sdata, - rx_status->mactime, - rx_status->device_timestamp, - elems, false);kfree (elems); }break ;
Signature · 1 line
2.36.1
PATCH 6/6 wifi: mac80211: fix MBSSID parsing use-after-free
In reply to Felix FietkauFrom: Johannes Berg <[email protected]>
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.
--- net/mac80211/ieee80211_i.h | 8 ++++++++ net/mac80211/util.c | 29 ++++++++++++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-)
net/mac80211/ieee80211_i.h +8 -0
@@ -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(
net/mac80211/util.c +14 -15
@@ -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;
Signature · 1 line
2.36.1
Greg KH
maintainerQuoted 10 lines · Felix Fietkau
From: Johannes Berg <[email protected]>
commit
a5b983c6073140b624f64e79fea6d33c3e4315a0upstream.We currently pass the entire elements to the
rx_bcn_presp()method, but only needmesh_config. Additionally, we use the length of the elements to calculate back the entire frame's length, but that's confusing - just pass the length of the frame instead.
Quoted 7 lines
Link https://lore.kernel.org/r/20210920154009.a18ed3d2da6c.I1824b773a0fbae4453e1433c184678ca14e8df45@changeid open hereSigned-off-by Johannes Berg <[email protected]>--- net/mac80211/ieee80211_i.h | 7 +++---- net/mac80211/mesh.c | 4 ++-- net/mac80211/mesh_sync.c | 26 ++++++++++++-------------- 3 files changed, 17 insertions(+), 20 deletions(-)
Many thanks for this series. Will this also work in 5.4.y and 5.10.y?
greg k-h
Greg KH
maintainerQuoted 19 lines · Greg KH
Quoted 10 lines · Felix Fietkau
From: Johannes Berg <[email protected]>
commit
a5b983c6073140b624f64e79fea6d33c3e4315a0upstream.We currently pass the entire elements to the
rx_bcn_presp()method, but only needmesh_config. Additionally, we use the length of the elements to calculate back the entire frame's length, but that's confusing - just pass the length of the frame instead.Quoted 7 lines
Link https://lore.kernel.org/r/20210920154009.a18ed3d2da6c.I1824b773a0fbae4453e1433c184678ca14e8df45@changeid open hereSigned-off-by Johannes Berg <[email protected]>--- net/mac80211/ieee80211_i.h | 7 +++---- net/mac80211/mesh.c | 4 ++-- net/mac80211/mesh_sync.c | 26 ++++++++++++-------------- 3 files changed, 17 insertions(+), 20 deletions(-)
Quoted 1 line
Many thanks for this series. Will this also work in 5.4.y and 5.10.y?
Also, in the future, you forgot to sign-off on these patches as you did forward them on yourself. Next time remember to add that, thanks.
All now queued up.
greg k-h
Quoted 19 lines · Greg KH
Quoted 10 lines · Felix Fietkau
From: Johannes Berg <[email protected]>
commit
a5b983c6073140b624f64e79fea6d33c3e4315a0upstream.We currently pass the entire elements to the
rx_bcn_presp()method, but only needmesh_config. Additionally, we use the length of the elements to calculate back the entire frame's length, but that's confusing - just pass the length of the frame instead.Quoted 7 lines
Link https://lore.kernel.org/r/20210920154009.a18ed3d2da6c.I1824b773a0fbae4453e1433c184678ca14e8df45@changeid open hereSigned-off-by Johannes Berg <[email protected]>--- net/mac80211/ieee80211_i.h | 7 +++---- net/mac80211/mesh.c | 4 ++-- net/mac80211/mesh_sync.c | 26 ++++++++++++-------------- 3 files changed, 17 insertions(+), 20 deletions(-)
Quoted 1 line
Many thanks for this series. Will this also work in 5.4.y and 5.10.y?
No idea. I don't have an environment to test that at the moment.
- Felix
Quoted 19 lines · Greg KH
Quoted 10 lines · Felix Fietkau
From: Johannes Berg <[email protected]>
commit
a5b983c6073140b624f64e79fea6d33c3e4315a0upstream.We currently pass the entire elements to the
rx_bcn_presp()method, but only needmesh_config. Additionally, we use the length of the elements to calculate back the entire frame's length, but that's confusing - just pass the length of the frame instead.Quoted 7 lines
Link https://lore.kernel.org/r/20210920154009.a18ed3d2da6c.I1824b773a0fbae4453e1433c184678ca14e8df45@changeid open hereSigned-off-by Johannes Berg <[email protected]>--- net/mac80211/ieee80211_i.h | 7 +++---- net/mac80211/mesh.c | 4 ++-- net/mac80211/mesh_sync.c | 26 ++++++++++++-------------- 3 files changed, 17 insertions(+), 20 deletions(-)
Quoted 2 lines
Many thanks for this series. Will this also work in 5.4.y and 5.10.y?
Not sure about 5.10, but that won't work as is on 5.4. We are considering some other approach for 5.4, but not sure yet. But simply taking dozens of clean cherry picks did not strike as a good option to me.
Cascardo.
Quoted 1 line
greg k-h
Quoted 20 lines · Thadeu Lima de Souza Cascardo
Quoted 19 lines · Greg KH
Quoted 17 lines · Felix Fietkau
From: Johannes Berg <[email protected]>
commit
a5b983c6073140b624f64e79fea6d33c3e4315a0upstream.We currently pass the entire elements to the
rx_bcn_presp()method, but only needmesh_config. Additionally, we use the length of the elements to calculate back the entire frame's length, but that's confusing - just pass the length of the frame instead.Link https://lore.kernel.org/r/20210920154009.a18ed3d2da6c.I1824b773a0fbae4453e1433c184678ca14e8df45@changeid open hereSigned-off-by Johannes Berg <[email protected]>--- net/mac80211/ieee80211_i.h | 7 +++---- net/mac80211/mesh.c | 4 ++-- net/mac80211/mesh_sync.c | 26 ++++++++++++-------------- 3 files changed, 17 insertions(+), 20 deletions(-)
Quoted 7 lines
Quoted 2 lines
Many thanks for this series. Will this also work in 5.4.y and 5.10.y?
Not sure about 5.10, but that won't work as is on 5.4. We are considering some other approach for 5.4, but not sure yet. But simply taking dozens of clean cherry picks did not strike as a good option to me.
I'm thinking of just disabling multi-BSSID, it's not really used anyway as far as I can tell.
johannes
Greg KH
maintainerQuoted 21 lines · Johannes Berg
Quoted 20 lines · Thadeu Lima de Souza Cascardo
Quoted 19 lines · Greg KH
Quoted 17 lines · Felix Fietkau
From: Johannes Berg <[email protected]>
commit
a5b983c6073140b624f64e79fea6d33c3e4315a0upstream.We currently pass the entire elements to the
rx_bcn_presp()method, but only needmesh_config. Additionally, we use the length of the elements to calculate back the entire frame's length, but that's confusing - just pass the length of the frame instead.Link https://lore.kernel.org/r/20210920154009.a18ed3d2da6c.I1824b773a0fbae4453e1433c184678ca14e8df45@changeid open hereSigned-off-by Johannes Berg <[email protected]>--- net/mac80211/ieee80211_i.h | 7 +++---- net/mac80211/mesh.c | 4 ++-- net/mac80211/mesh_sync.c | 26 ++++++++++++-------------- 3 files changed, 17 insertions(+), 20 deletions(-)
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Many thanks for this series. Will this also work in 5.4.y and 5.10.y?
Not sure about 5.10, but that won't work as is on 5.4. We are considering some other approach for 5.4, but not sure yet. But simply taking dozens of clean cherry picks did not strike as a good option to me.
Taking lots of clean cherrypicks _is_ normally the best way, I have no objection to that at all as it keeps things in sync properly. Doing out-of-tree changes is the hard way and we almost always get that wrong.
Quoted 2 lines
I'm thinking of just disabling multi-BSSID, it's not really used anyway as far as I can tell.
That's fine with me too if it's an easy change and no one complains or notices :)
thanks,
greg k-h