mac80211 syzbot fixes - part 1
Johannes Berg
maintainercover mac80211 syzbot fixes - part 1
First set for mac80211.
johannes
Johannes Berg
maintainerPATCH 1/10 wifi: mac80211: don't apply peer rates to off-channel frames
From: Johannes Berg <[email protected]>
All the off-channel frames (including scan) aren't really part of the connection, so don't apply the station rates even if they're being sent to the station in question (e.g. by accident). They don't use the rate mask via IEEE80211_TX_CTRL_DONT_USE_RATE_MASK, but the station might not have rates of them either, hitting the warning found by syzbot.
--- net/mac80211/rate.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/mac80211/rate.c +8 -0
@@ -372,6 +372,14 @@ static void __rate_control_send_low(struct ieee80211_hw *hw,u32 rate_flags =0 ;int i; +/* +* Frames that shouldn't use the rate mask could be anything, +* even on a different band, so don't take the sta into account +* to avoid ending up without rates. +*/ +if (info->control.flags &IEEE80211_TX_CTRL_DONT_USE_RATE_MASK ) + sta =NULL ; +if (sband->band ==NL80211_BAND_S1GHZ ) { info->control.rates[0 ].flags |=IEEE80211_TX_RC_S1G_MCS ; info->control.rates[0 ].idx =0 ;
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH 2/10 wifi: mac80211: don't drop scan probe requests for lack of peer rates
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
While software scanning, ieee80211_tx_h_rate_ctrl() warns and drops the frame if the target station has no usable bitrate on the band that's currently being scanned.
But that's really meant for data frames, not if we happen to scan for the BSSID on the wrong band, which can be constructed easily.
Skip the check for IEEE80211_TX_CTRL_DONT_USE_RATE_MASK, the previous commit also ignored the station rate mask for such frames as well.
--- net/mac80211/tx.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/mac80211/tx.c +5 -3
@@ -744,10 +744,12 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx) assoc =test_sta_flag (tx->sta,WLAN_STA_ASSOC );/* -* Lets not bother rate control if we're associated and cannot -* talk to the sta. This should not happen. +* Lets not bother rate control if we're associated and cannot talk to +* the sta. This should not happen - except for frames that aren't +* really for the peer to start with and already ignore rates. */ - if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc && +if (!(info->control.flags &IEEE80211_TX_CTRL_DONT_USE_RATE_MASK ) && + WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc && !rate_usable_index_exists(sband, &tx->sta->sta), "%s: Dropped data frame as no usable bitrate found while " "scanning and associated. Target station: "
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH 3/10 wifi: mac80211: don't start a ROC while scanning
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
The ROC work can be pending when a scan starts (which requires ROC list to be empty, but that's possible), and then a new ROC can be added to the list and the work will pick it up.
Avoid starting that ROC if a scan made it between things, as otherwise we'll hit a warning later:
WARNING: net/mac80211/offchannel.c:404 at ieee80211_start_next_roc+0x256/0x2d0 Workqueue: events_unbound cfg80211_wiphy_work Call Trace: __ieee80211_scan_completed+0x4fd/0xe40 net/mac80211/scan.c:537 ieee80211_scan_work+0x472/0x1ff0 net/mac80211/scan.c:1193 cfg80211_wiphy_work+0x410/0x570 net/wireless/core.c:513
--- net/mac80211/offchannel.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/mac80211/offchannel.c +7 -0
@@ -460,6 +460,13 @@ static void __ieee80211_roc_work(struct ieee80211_local *local)return ;if (!roc->started) { +/* +* The work can be started by a previous ROC work, but a scan +* can get between things; scan finish will retrigger us. +*/ +if (local->scanning) +return ; +WARN_ON (!local->emulate_chanctx);_ieee80211_start_next_roc (local); }else {
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH 4/10 wifi: mac80211: don't warn when an IBSS has no channel to scan
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
ieee80211_request_ibss_scan() warns when regulatory leaves no allowed channel, but that can happen as the regdomain can change while IBSS is operating, and it can continue to operate briefly during the 60s grace period until it's shut down.
Just remove the warning in this case.
--- net/mac80211/scan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac80211/scan.c +1 -1
@@ -1242,7 +1242,7 @@ int ieee80211_request_ibss_scan(struct ieee80211_sub_if_data *sdata, } } -if (WARN_ON_ONCE (n_ch ==0 )) +if (n_ch ==0 )return -EINVAL ; local->int_scan_req->n_channels = n_ch;
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH 5/10 wifi: mac80211: don't offload TC setup on AP_VLAN interfaces
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
AP_VLAN interfaces are purely virtual, so don't try to offload TC setup to drivers. We can't really use the AP interface either since we may not know it all the time, and it could technically even change.
Just reject the TC offload so things get done in software.
--- net/mac80211/iface.c | 3 +++ 1 file changed, 3 insertions(+)
net/mac80211/iface.c +3 -0
@@ -935,6 +935,9 @@ static int ieee80211_netdev_setup_tc(struct net_device *dev,struct ieee80211_sub_if_data *sdata =IEEE80211_DEV_TO_SUB_IF (dev);struct ieee80211_local *local = sdata->local; +if (sdata->vif.type ==NL80211_IFTYPE_AP_VLAN ) +return -EOPNOTSUPP ; +return drv_net_setup_tc (local, sdata, dev, type, type_data); }
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH 6/10 wifi: mac80211: suppress chanctx warning for debugfs reset
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
Before suspend all the channel contexts should removed, so the warning makes sense and should be there, but during reset the same code is called without first removing. Limit the check to the real suspend case.
--- net/mac80211/cfg.c | 2 +- net/mac80211/debugfs.c | 2 +- net/mac80211/ieee80211_i.h | 2 +- net/mac80211/pm.c | 8 +++++--- 4 files changed, 8 insertions(+), 6 deletions(-)
net/mac80211/cfg.c +1 -1
@@ -3475,7 +3475,7 @@ static int ieee80211_set_txq_params(struct wiphy *wiphy,static int ieee80211_suspend (struct wiphy *wiphy,struct cfg80211_wowlan *wowlan) { -return __ieee80211_suspend (wiphy_priv (wiphy), wowlan); +return __ieee80211_suspend (wiphy_priv (wiphy), wowlan, false); }static int ieee80211_resume (struct wiphy *wiphy)
net/mac80211/debugfs.c +1 -1
@@ -384,7 +384,7 @@ static ssize_t reset_write(struct file *file, const char __user *user_buf,rtnl_lock ();wiphy_lock (local->hw.wiphy); -__ieee80211_suspend (&local->hw,NULL ); +__ieee80211_suspend (&local->hw,NULL , true); ret =__ieee80211_resume (&local->hw);wiphy_unlock (local->hw.wiphy);
net/mac80211/ieee80211_i.h +1 -1
@@ -2432,7 +2432,7 @@ int ieee80211_reconfig(struct ieee80211_local *local);void ieee80211_stop_device (struct ieee80211_local *local,bool suspend);int __ieee80211_suspend (struct ieee80211_hw *hw, -struct cfg80211_wowlan *wowlan); +struct cfg80211_wowlan *wowlan,bool reset);static inline int __ieee80211_resume (struct ieee80211_hw *hw) {
net/mac80211/pm.c +5 -3
@@ -18,7 +18,8 @@ static void ieee80211_sched_scan_cancel(struct ieee80211_local *local)cfg80211_sched_scan_stopped_locked (local->hw.wiphy,0 ); } -int __ieee80211_suspend (struct ieee80211_hw *hw,struct cfg80211_wowlan *wowlan) +int __ieee80211_suspend (struct ieee80211_hw *hw,struct cfg80211_wowlan *wowlan, +bool reset) {struct ieee80211_local *local =hw_to_local (hw);struct ieee80211_sub_if_data *sdata;
@@ -166,9 +167,10 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)/* * We disconnected on all interfaces before suspend, all channel -* contexts should be released. +* contexts should be released, but on 'reset' debugfs that's +* not true so don't check there. */ -WARN_ON (!list_empty (&local->chanctx_list)); +WARN_ON (!reset && !list_empty (&local->chanctx_list));/* stop hardware - this must stop RX */ ieee80211_stop_device (local, true);
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH 7/10 wifi: mac80211: abort chanswitch when leaving a mesh
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
The code in ieee80211_stop_mesh() leaves CSA active, but leaving the mesh released the channel context, so the CSA finalize work crashes:
Oops: general protection fault, probably for non-canonical address
0xdffffc0000000003
KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f]
RIP: 0010:ieee80211_put_srates_elem+0x42/0x640 net/mac80211/util.c:3272
Call Trace:
ieee80211_mesh_build_beacon+0xa83/0x1b50 net/mac80211/mesh.c:1093
ieee80211_mesh_rebuild_beacon+0xc7/0x170 net/mac80211/mesh.c:1147
ieee80211_mesh_finish_csa+0x131/0x210 net/mac80211/mesh.c:1542
ieee80211_set_after_csa_beacon net/mac80211/cfg.c:4085 [inline]
__ieee80211_csa_finalize net/mac80211/cfg.c:4133 [inline]
ieee80211_csa_finalize+0x633/0x1150 net/mac80211/cfg.c:4155
cfg80211_wiphy_work+0x2ab/0x450 net/wireless/core.c:438Abort the channel switch properly.
--- net/mac80211/mesh.c | 4 ++++ 1 file changed, 4 insertions(+)
net/mac80211/mesh.c +4 -0
@@ -1204,6 +1204,10 @@ void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)netif_carrier_off (sdata->dev); +/* abort any running channel switch */ + sdata->vif.bss_conf.csa_active = false; +ieee80211_vif_unblock_queues_csa (sdata); +/* flush STAs and mpaths on this iface */ sta_info_flush (sdata,-1 );ieee80211_free_keys (sdata, true);
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH 8/10 wifi: mac80211: reset state when starting AP fails
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
ieee80211_start_ap() can set enable_beacon (and beacon_int) and fail later, leaving it set forever. Scanning can then attempt to restore beaconing on such an interface, leading to:
Oops: divide error: 0000 [#1] SMP KASAN NOPTI RIP: 0010:mac80211_hwsim_link_info_changed+0xca7/0xf00 Call Trace: drv_link_info_changed+0x413/0x860 net/mac80211/driver-ops.c:495 ieee80211_link_info_change_notify+0x24b/0x3c0 net/mac80211/main.c:427 ieee80211_offchannel_return+0x381/0x580 net/mac80211/offchannel.c:160 __ieee80211_scan_completed+0x993/0xe30 net/mac80211/scan.c:519 ieee80211_scan_work+0x472/0x2010 net/mac80211/scan.c:1193 cfg80211_wiphy_work+0x2b7/0x550 net/wireless/core.c:538
in hwsim. Also, cfg80211 then allows changing the interface type, and the off-channel path getgs confused about beaconing as well, leading to another warning:
WARNING: net/mac80211/driver-ops.c:468 at drv_link_info_changed+0x583/0x880 ieee80211_link_info_change_notify+0x24b/0x3c0 net/mac80211/main.c:427 ieee80211_offchannel_stop_vifs+0x328/0x5c0 net/mac80211/offchannel.c:122 ieee80211_start_sw_scan net/mac80211/scan.c:583 [inline] __ieee80211_start_scan+0xfb6/0x1af0 net/mac80211/scan.c:882
Reset the state on failures to always have it correct.
--- net/mac80211/cfg.c | 3 +++ 1 file changed, 3 insertions(+)
net/mac80211/cfg.c +3 -0
@@ -1929,6 +1929,9 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,return 0 ; error: + link_conf->enable_beacon = false; + link_conf->beacon_int = prev_beacon_int; + sdata->vif.cfg.ssid_len =0 ;ieee80211_link_release_channel (link);return err;
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH 9/10 wifi: mac80211: reset the LED state when ifup fails
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
When the first interface comes up, the radio LED is turned on. This can start the TPT trigger timer, which continues running.
But if bringing up the interface fails then the timer keeps running and won't be stopped by anything, eventually it can be freed:
ODEBUG: free active (active state 0) object: ffff888127e12130 object type: timer_list hint: tpt_trig_timer+0x0/0x300 net/mac80211/led.c:145
WARNING: CPU: 0 PID: 5923 at lib/debugobjects.c:612 debug_print_object+0x1a2/0x2b0 debug_check_no_obj_freed+0x4b7/0x600 lib/debugobjects.c:1129 kfree+0x436/0x670 mm/slub.c:6818 ieee80211_led_exit+0x162/0x1c0 net/mac80211/led.c:210 ieee80211_unregister_hw+0x27e/0x3a0 net/mac80211/main.c:1706 rt2x00lib_remove_dev+0x55b/0x670
Undo the LED state in the error path.
--- net/mac80211/iface.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/mac80211/iface.c +5 -1
@@ -1606,8 +1606,12 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up) err_del_interface:drv_remove_interface (local, sdata); err_stop: -if (!local->open_count) +if (!local->open_count) { +ieee80211_led_radio (local, false); +ieee80211_mod_tpt_led_trig (local,0 , +IEEE80211_TPT_LEDTRIG_FL_RADIO );drv_stop (local, false); + }if (sdata->vif.type ==NL80211_IFTYPE_NAN_DATA )RCU_INIT_POINTER (sdata->u.nan_data.nmi,NULL );if (sdata->vif.type ==NL80211_IFTYPE_AP_VLAN )
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH 10/10 wifi: mac80211: only operate on TDLS peers in the TDLS code
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
ieee80211_tdls_oper() can operate on the AP station, which then yields various warnings when the AP station is removed then or at a later point in time after being confused for a TDLS peer.
Always check that the station is a TDLS peer.
--- net/mac80211/tdls.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
net/mac80211/tdls.c +9 -12
@@ -1142,6 +1142,7 @@ ieee80211_tdls_mgmt_setup(struct wiphy *wiphy, struct net_device *dev,struct ieee80211_local *local = sdata->local;enum ieee80211_smps_mode smps_mode = sdata->deflink.u.mgd.driver_smps_mode; +struct sta_info *sta;int ret;/* don't support setup with forced SMPS mode that's not off */
@@ -1168,14 +1169,10 @@ ieee80211_tdls_mgmt_setup(struct wiphy *wiphy, struct net_device *dev,* Allow error packets to be sent - sometimes we don't even add a STA * before failing the setup. */ -if (status_code ==0 ) { -rcu_read_lock (); -if (!sta_info_get (sdata, peer)) { -rcu_read_unlock (); - ret = -ENOLINK ; - goto out_unlock; - } -rcu_read_unlock (); + sta =sta_info_get (sdata, peer); +if ((status_code ==0 && !sta) || (sta && !sta->sta.tdls)) { + ret = -ENOLINK ; + goto out_unlock; }ieee80211_flush_queues (local, sdata, false);
@@ -1442,6 +1439,10 @@ int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,*/ tdls_dbg (sdata,"TDLS oper %d peer %pM\n" , oper, peer); + sta =sta_info_get (sdata, peer); +if (!sta || !sta->sta.tdls) +return -ENOLINK ; +switch (oper) {case NL80211_TDLS_ENABLE_LINK :if (sdata->vif.bss_conf.csa_active) {
@@ -1449,10 +1450,6 @@ int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,return -EBUSY ; } - sta =sta_info_get (sdata, peer); -if (!sta || !sta->sta.tdls) -return -ENOLINK ; -iee80211_tdls_recalc_chanctx (sdata, sta);iee80211_tdls_recalc_ht_protection (sdata, sta);
Signature · 1 line
2.55.0