mac80211 syzbot fixes - part 2
Johannes Berg
maintainercover mac80211 syzbot fixes - part 2
Since I split the series badly, this didn't apply, so here's a resend for the bots.
johannes
Johannes Berg
maintainerPATCH RESEND 1/10 wifi: mac80211: don't allow injecting frames wider than the chanctx
From: Johannes Berg <[email protected]>
Frames injected on a monitor interface can carry a radiotap field requesting a bandwidth, which mac80211 passes down to the driver regardless of the the actual operational bandwidth.
If the bandwidth requested is too wide, that triggers a warning in hwsim:
WARN_ON(hwsim_get_chanwidth(bw) > hwsim_get_chanwidth(confbw))
Drop such frames entirely instead since they cannot be sent.
--- include/net/mac80211.h | 5 ++++- net/mac80211/iface.c | 2 +- net/mac80211/tx.c | 28 ++++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-)
include/net/mac80211.h +4 -1
@@ -7638,11 +7638,14 @@ bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw,* * @skb: packet injected by userspace * @dev: the &struct device of this 802.11 device +* @chandef: the channel definition the frame will be transmitted on, or +* %NULL to skip the bandwidth checks * * Return: %true if the radiotap header was parsed, %false otherwise */ bool ieee80211_parse_tx_radiotap (struct sk_buff *skb, -struct net_device *dev); +struct net_device *dev, +const struct cfg80211_chan_def *chandef);/** * struct ieee80211_noa_data - holds temporary data for tracking P2P NoA state
net/mac80211/iface.c +1 -1
@@ -991,7 +991,7 @@ static u16 ieee80211_monitor_select_queue(struct net_device *dev,/* reset flags and info before parsing radiotap header */ memset (info,0 ,sizeof (*info)); -if (!ieee80211_parse_tx_radiotap (skb, dev)) +if (!ieee80211_parse_tx_radiotap (skb, dev,NULL ))return 0 ;/* doesn't matter, frame will be dropped */ len_rthdr =ieee80211_get_radiotap_len (skb->data);
net/mac80211/tx.c +26 -2
@@ -2105,8 +2105,29 @@ static bool ieee80211_validate_radiotap_len(struct sk_buff *skb)return true; } +static bool ieee80211_rate_bw_usable (u16 rate_flags, +const struct cfg80211_chan_def *chandef) +{ +int width; + +if (!chandef) +return true; + +if (rate_flags &IEEE80211_TX_RC_160_MHZ_WIDTH ) + width =160 ; +else if (rate_flags &IEEE80211_TX_RC_80_MHZ_WIDTH ) + width =80 ; +else if (rate_flags &IEEE80211_TX_RC_40_MHZ_WIDTH ) + width =40 ; +else +return true; + +return width <=cfg80211_chandef_get_width (chandef); +} +bool ieee80211_parse_tx_radiotap (struct sk_buff *skb, -struct net_device *dev) +struct net_device *dev, +const struct cfg80211_chan_def *chandef) {struct ieee80211_local *local =wdev_priv (dev->ieee80211_ptr);struct ieee80211_radiotap_iterator iterator;
@@ -2280,6 +2301,9 @@ bool ieee80211_parse_tx_radiotap(struct sk_buff *skb,struct ieee80211_supported_band *sband = local->hw.wiphy->bands[info->band]; +if (!ieee80211_rate_bw_usable (rate_flags, chandef)) +return false; + info->control.flags |=IEEE80211_TX_CTRL_RATE_INJECT ;for (i =0 ; i <IEEE80211_TX_MAX_RATES ; i++) {
@@ -2479,7 +2503,7 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,* selected chandef above to accurately set injection rates and * retransmissions. */ -if (!ieee80211_parse_tx_radiotap (skb, dev)) +if (!ieee80211_parse_tx_radiotap (skb, dev, chandef)) goto fail_rcu;/* remove the injection radiotap header */
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH RESEND 2/10 wifi: mac80211: reset the AP_VLAN tailroom counter on ifdown
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
On ifup, AP_VLAN interfaces get crypto_tx_tailroom_needed_cnt from the AP interface, but it's never decremented again unless the AP is also brought down. Thus, bringing the same AP_VLAN up again will increment the counter again and eventually hit the sanity check:
WARN_ON_ONCE(sdata->crypto_tx_tailroom_needed_cnt !=
master->crypto_tx_tailroom_needed_cnt);
Reset it on ifdown to avoid that.
--- net/mac80211/iface.c | 2 ++ 1 file changed, 2 insertions(+)
net/mac80211/iface.c +2 -0
@@ -616,6 +616,8 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, bool going_doRCU_INIT_POINTER (sdata->vif.bss_conf.chanctx_conf,NULL );/* see comment in the default case below */ ieee80211_free_keys (sdata, true); +/* increased by AP value on ifup, so reset on ifdown */ + sdata->crypto_tx_tailroom_needed_cnt =0 ;/* no need to tell driver */ break ;case NL80211_IFTYPE_MONITOR :
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH RESEND 3/10 wifi: mac80211: require a peer station for TDLS setup confirm
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
It's nonsense for the setup confirm to go to station that doesn't even exist, and it hits a warning when building the frame:
WARN_ON_ONCE(!sta || !ap_sta)
Only accept WLAN_TDLS_SETUP_CONFIRM when the station is already there as a TDLS station. Need to copy the call to ieee80211_tdls_prep_mgmt_packet() since the existing WLAN_TDLS_DISCOVERY_REQUEST already falls through to it.
--- net/mac80211/tdls.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
net/mac80211/tdls.c +18 -1
@@ -1281,6 +1281,24 @@ int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev, peer_capability, initiator, extra_ies, extra_ies_len);break ; +case WLAN_TDLS_SETUP_CONFIRM : { +struct sta_info *sta; + + sta =sta_info_get (sdata, peer); +if (!sta || !sta->sta.tdls) { + ret = -ENOLINK ; +break ; + } + + ret =ieee80211_tdls_prep_mgmt_packet (wiphy, dev, peer, + link_id, action_code, + dialog_token, + status_code, + peer_capability, + initiator, extra_ies, + extra_ies_len,0 ,NULL ); +break ; + }case WLAN_TDLS_DISCOVERY_REQUEST :/* * Protect the discovery so we can hear the TDLS discovery
@@ -1289,7 +1307,6 @@ int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,*/ drv_mgd_protect_tdls_discover (sdata->local, sdata, link_id); fallthrough; -case WLAN_TDLS_SETUP_CONFIRM :case WLAN_PUB_ACTION_TDLS_DISCOVER_RES :/* no special handling */ ret = ieee80211_tdls_prep_mgmt_packet(wiphy, dev, peer,
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH RESEND 4/10 wifi: mac80211: don't allow link changes when iface is down
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
ieee80211_set_active_links() only checks that the interface is running in the inner __ieee80211_set_active_links(), after drv_can_activate_links() was already called, so using active_links on an interface that's down triggers the check-sdata-in-driver warning.
Add the missing check in the debugfs file.
--- net/mac80211/debugfs_netdev.c | 3 +++ 1 file changed, 3 insertions(+)
net/mac80211/debugfs_netdev.c +3 -0
@@ -729,6 +729,9 @@ static ssize_t ieee80211_if_parse_active_links(struct ieee80211_sub_if_data *sdaif (kstrtou16 (buf,0 , &active_links) || !active_links)return -EINVAL ; +if (!ieee80211_sdata_running (sdata)) +return -ENETDOWN ; +return ieee80211_set_active_links (&sdata->vif, active_links) ?: buflen; }IEEE80211_IF_FILE_RW (active_links);
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH RESEND 5/10 wifi: mac80211: don't RCU-dereference the mesh CSA settings we just set
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
In the error path of ieee80211_mesh_csa_beacon() the settings that were just assigned are read back with rcu_dereference(), which lockdep then complains about.
There's no need to read the pointer at all, tmp_csa_settings still is the right value anyway.
--- net/mac80211/mesh.c | 1 - 1 file changed, 1 deletion(-)
net/mac80211/mesh.c +0 -1
@@ -1559,7 +1559,6 @@ int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata, ret =ieee80211_mesh_rebuild_beacon (sdata);if (ret) { - tmp_csa_settings =rcu_dereference (ifmsh->csa);RCU_INIT_POINTER (ifmsh->csa,NULL );kfree_rcu (tmp_csa_settings, rcu_head);return ret;
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH RESEND 6/10 wifi: mac80211: don't access the TSF of a down interface
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
The tsf debugfs files call the driver even if the interface isn't up, tgriggering check-sdata-in-driver warnings.
Reject the access in that case.
--- net/mac80211/debugfs_netdev.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/mac80211/debugfs_netdev.c +6 -0
@@ -657,6 +657,9 @@ static ssize_t ieee80211_if_fmt_tsf(struct ieee80211_local *local = sdata->local;u64 tsf; +if (!ieee80211_sdata_running ((struct ieee80211_sub_if_data *)sdata)) +return -ENETDOWN ; + tsf =drv_get_tsf (local, (struct ieee80211_sub_if_data *)sdata);return scnprintf (buf, buflen,"0x%016llx\n" , (unsigned long long ) tsf);
@@ -670,6 +673,9 @@ static ssize_t ieee80211_if_parse_tsf(int ret;int tsf_is_delta =0 ; +if (!ieee80211_sdata_running (sdata)) +return -ENETDOWN ; +if (strncmp (buf,"reset" ,5 ) ==0 ) {if (local->ops->reset_tsf) {drv_reset_tsf (local, sdata);
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH RESEND 7/10 wifi: mac80211: add HE 6 GHz capability in the scan elems len
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
The HE 6 GHz Band Capability element is in the probe request for every band if 6 GHz is supported, so add the size to scan_ies_len.
Otherwise, building probe request elements can fail, triggering the WARN_ON in __ieee80211_start_scan().
--- net/mac80211/main.c | 4 ++++ 1 file changed, 4 insertions(+)
net/mac80211/main.c +4 -0
@@ -1453,6 +1453,10 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)sizeof (struct ieee80211_he_mcs_nss_supp ) +IEEE80211_HE_PPE_THRES_MAX_LEN ; +if (local->hw.wiphy->bands[NL80211_BAND_6GHZ ]) + local->scan_ies_len += +3 +sizeof (struct ieee80211_he_6ghz_capa ); +if (supp_eht) local->scan_ies_len += 3 + sizeof(struct ieee80211_eht_cap_elem) +
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH RESEND 8/10 wifi: mac80211: mesh: reset the CSA state when leaving
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
ifmsh->csa is allocated in ieee80211_mesh_csa_beacon() and only freed in ieee80211_mesh_finish_csa(), i.e. when the channel switch completes. Leaving the mesh while a switch is still pending therefore leaks it.
Additionally, ifmsh->csa_role and ifmsh->chsw_ttl have their state leak in this case, so things can get mixed up in addition to the memory leak.
Refactor the reset and call it in ieee80211_stop_mesh() to fix it all.
--- net/mac80211/mesh.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
net/mac80211/mesh.c +18 -11
@@ -1196,6 +1196,21 @@ int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)return 0 ; } +static void ieee80211_mesh_reset_csa (struct ieee80211_sub_if_data *sdata) +{ +struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; +struct mesh_csa_settings *csa; + +/* Reset the TTL value and Initiator flag */ + ifmsh->csa_role =IEEE80211_MESH_CSA_ROLE_NONE ; + ifmsh->chsw_ttl =0 ; + +/* Remove the CSA and MCSP elements from the beacon */ + csa =sdata_dereference (ifmsh->csa, sdata); +RCU_INIT_POINTER (ifmsh->csa,NULL ); +kfree_rcu (csa, rcu_head); +} +void ieee80211_stop_mesh (struct ieee80211_sub_if_data *sdata) {struct ieee80211_local *local = sdata->local;
@@ -1206,6 +1221,7 @@ void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)/* abort any running channel switch */ sdata->vif.bss_conf.csa_active = false; +ieee80211_mesh_reset_csa (sdata);ieee80211_vif_unblock_queues_csa (sdata);/* flush STAs and mpaths on this iface */
@@ -1514,19 +1530,10 @@ static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,int ieee80211_mesh_finish_csa (struct ieee80211_sub_if_data *sdata,u64 *changed) { -struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; -struct mesh_csa_settings *tmp_csa_settings; -int ret =0 ; +int ret; -/* Reset the TTL value and Initiator flag */ - ifmsh->csa_role =IEEE80211_MESH_CSA_ROLE_NONE ; - ifmsh->chsw_ttl =0 ; +ieee80211_mesh_reset_csa (sdata); -/* Remove the CSA and MCSP elements from the beacon */ - tmp_csa_settings =sdata_dereference (ifmsh->csa, sdata); -RCU_INIT_POINTER (ifmsh->csa,NULL ); -if (tmp_csa_settings) -kfree_rcu (tmp_csa_settings, rcu_head); ret =ieee80211_mesh_rebuild_beacon (sdata);if (ret)return -EINVAL ;
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH RESEND 9/10 wifi: mac80211: mesh: release the channel if start fails
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
ieee80211_join_mesh() acquires a channel context and then calls ieee80211_start_mesh(), which can fail. In that case, the chanctx isn't released then interface removal will attempt to unassign it after it's removed from the driver, hitting:
wlan0: Failed check-sdata-in-driver check, flags: 0x0
WARNING: net/mac80211/driver-ops.c:366 at drv_unassign_vif_chanctx ieee80211_assign_link_chanctx __ieee80211_link_release_channel ieee80211_link_release_channel ieee80211_teardown_sdata unregister_netdevice_many_notify _cfg80211_unregister_wdev ieee80211_remove_interfaces ieee80211_unregister_hw mac80211_hwsim_del_radio hwsim_exit_net
Correctly release the channel on start failures.
--- net/mac80211/cfg.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/mac80211/cfg.c +5 -1
@@ -3323,7 +3323,11 @@ static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,if (err)return err; -return ieee80211_start_mesh (sdata); + err =ieee80211_start_mesh (sdata); +if (err) +ieee80211_link_release_channel (&sdata->deflink); + +return err; }static int ieee80211_leave_mesh (struct wiphy *wiphy,struct net_device *dev)
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH RESEND 10/10 wifi: mac80211: set up the TX info early to fix failure paths
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
The previous commit 2c51457d930f ("wifi: mac80211: free ack status frame on TX header build failure") cleaned up the leak, but still left the code a bit messy and the failed SKB didn't get reported to userspace.
Fix this up by initialising skb->cb[] earlier, which allows using ieee80211_free_txskb() and therefore reports it for the failure in ieee80211_build_hdr(), and unifies the ieee80211_skb_resize() failure path with it.
--- net/mac80211/tx.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-)
net/mac80211/tx.c +20 -18
@@ -2981,10 +2981,23 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,*/ skb =skb_share_check (skb,GFP_ATOMIC );if (unlikely (!skb)) { - ret = -ENOMEM ; - goto free; +/* skb_share_check() already freed the skb */ +if (info_id) +ieee80211_remove_ack_skb (local, info_id); +return ERR_PTR (-ENOMEM ); } +/* set this up so failure paths can clean up ack skb */ + info =IEEE80211_SKB_CB (skb); +memset (info,0 ,sizeof (*info)); + + info->flags = info_flags; +if (info_id) { + info->status_data = info_id; + info->status_data_idr =1 ; + } + info->band = band; + hdr.frame_control = fc; hdr.duration_id =0 ; hdr.seq_ctrl =0 ;
@@ -3023,10 +3036,8 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, head_need += local->tx_headroom; head_need =max_t (int,0 , head_need);if (ieee80211_skb_resize (sdata, skb, head_need,ENCRYPT_DATA )) { -ieee80211_free_txskb (&local->hw, skb); - skb =NULL ; ret = -ENOMEM ; - goto free; + goto free_txskb; } }
@@ -3053,16 +3064,6 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,skb_reset_mac_header (skb); - info =IEEE80211_SKB_CB (skb); -memset (info,0 ,sizeof (*info)); - - info->flags = info_flags; -if (info_id) { - info->status_data = info_id; - info->status_data_idr =1 ; - } - info->band = band; -if (likely (!cookie)) { ctrl_flags |=u32_encode_bits (link_id,IEEE80211_TX_CTRL_MLO_LINK );
@@ -3086,16 +3087,17 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, pre_conf_link_id, link_id);#endif ret = -EINVAL ; - goto free; + goto free_txskb; } } info->control.flags = ctrl_flags;return skb; + free_txskb: +ieee80211_free_txskb (&local->hw, skb); +return ERR_PTR (ret); free: -if (info_id) -ieee80211_remove_ack_skb (local, info_id);kfree_skb (skb);return ERR_PTR (ret); }
Signature · 1 line
2.55.0