hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/net/wireless/core.c
....@@ -1,9 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * This is the linux wireless configuration interface.
34 *
45 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
56 * Copyright 2013-2014 Intel Mobile Communications GmbH
67 * Copyright 2015-2017 Intel Deutschland GmbH
8
+ * Copyright (C) 2018-2021 Intel Corporation
79 */
810
911 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -140,12 +142,10 @@
140142 if (result)
141143 return result;
142144
143
- if (rdev->wiphy.debugfsdir &&
144
- !debugfs_rename(rdev->wiphy.debugfsdir->d_parent,
145
- rdev->wiphy.debugfsdir,
146
- rdev->wiphy.debugfsdir->d_parent,
147
- newname))
148
- pr_err("failed to rename debugfs dir to %s!\n", newname);
145
+ if (!IS_ERR_OR_NULL(rdev->wiphy.debugfsdir))
146
+ debugfs_rename(rdev->wiphy.debugfsdir->d_parent,
147
+ rdev->wiphy.debugfsdir,
148
+ rdev->wiphy.debugfsdir->d_parent, newname);
149149
150150 nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY);
151151
....@@ -190,10 +190,24 @@
190190 return err;
191191 }
192192
193
+ list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
194
+ if (!wdev->netdev)
195
+ continue;
196
+ nl80211_notify_iface(rdev, wdev, NL80211_CMD_DEL_INTERFACE);
197
+ }
198
+ nl80211_notify_wiphy(rdev, NL80211_CMD_DEL_WIPHY);
199
+
193200 wiphy_net_set(&rdev->wiphy, net);
194201
195202 err = device_rename(&rdev->wiphy.dev, dev_name(&rdev->wiphy.dev));
196203 WARN_ON(err);
204
+
205
+ nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY);
206
+ list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
207
+ if (!wdev->netdev)
208
+ continue;
209
+ nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
210
+ }
197211
198212 return 0;
199213 }
....@@ -222,7 +236,9 @@
222236 rdev->opencount--;
223237
224238 if (rdev->scan_req && rdev->scan_req->wdev == wdev) {
225
- if (WARN_ON(!rdev->scan_req->notified))
239
+ if (WARN_ON(!rdev->scan_req->notified &&
240
+ (!rdev->int_scan_req ||
241
+ !rdev->int_scan_req->notified)))
226242 rdev->scan_req->info.aborted = true;
227243 ___cfg80211_scan_done(rdev, false);
228244 }
....@@ -286,12 +302,13 @@
286302 return 0;
287303 }
288304
289
-static void cfg80211_rfkill_sync_work(struct work_struct *work)
305
+static void cfg80211_rfkill_block_work(struct work_struct *work)
290306 {
291307 struct cfg80211_registered_device *rdev;
292308
293
- rdev = container_of(work, struct cfg80211_registered_device, rfkill_sync);
294
- cfg80211_rfkill_set_block(rdev, rfkill_blocked(rdev->rfkill));
309
+ rdev = container_of(work, struct cfg80211_registered_device,
310
+ rfkill_block);
311
+ cfg80211_rfkill_set_block(rdev, true);
295312 }
296313
297314 static void cfg80211_event_work(struct work_struct *work)
....@@ -465,9 +482,6 @@
465482 INIT_LIST_HEAD(&rdev->bss_list);
466483 INIT_LIST_HEAD(&rdev->sched_scan_req_list);
467484 INIT_WORK(&rdev->scan_done_wk, __cfg80211_scan_done);
468
- INIT_LIST_HEAD(&rdev->mlme_unreg);
469
- spin_lock_init(&rdev->mlme_unreg_lock);
470
- INIT_WORK(&rdev->mlme_unreg_wk, cfg80211_mlme_unreg_wk);
471485 INIT_DELAYED_WORK(&rdev->dfs_update_channels_wk,
472486 cfg80211_dfs_channels_update_work);
473487 #ifdef CONFIG_CFG80211_WEXT
....@@ -485,6 +499,9 @@
485499 INIT_WORK(&rdev->propagate_radar_detect_wk,
486500 cfg80211_propagate_radar_detect_wk);
487501 INIT_WORK(&rdev->propagate_cac_done_wk, cfg80211_propagate_cac_done_wk);
502
+ INIT_WORK(&rdev->mgmt_registrations_update_wk,
503
+ cfg80211_mgmt_registrations_update_wk);
504
+ spin_lock_init(&rdev->mgmt_registrations_lock);
488505
489506 #ifdef CONFIG_CFG80211_DEFAULT_PS
490507 rdev->wiphy.flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
....@@ -502,7 +519,7 @@
502519 return NULL;
503520 }
504521
505
- INIT_WORK(&rdev->rfkill_sync, cfg80211_rfkill_sync_work);
522
+ INIT_WORK(&rdev->rfkill_block, cfg80211_rfkill_block_work);
506523 INIT_WORK(&rdev->conn_work, cfg80211_conn_work);
507524 INIT_WORK(&rdev->event_work, cfg80211_event_work);
508525
....@@ -664,6 +681,40 @@
664681 return -EINVAL;
665682 #endif
666683
684
+ if (WARN_ON(wiphy->pmsr_capa && !wiphy->pmsr_capa->ftm.supported))
685
+ return -EINVAL;
686
+
687
+ if (wiphy->pmsr_capa && wiphy->pmsr_capa->ftm.supported) {
688
+ if (WARN_ON(!wiphy->pmsr_capa->ftm.asap &&
689
+ !wiphy->pmsr_capa->ftm.non_asap))
690
+ return -EINVAL;
691
+ if (WARN_ON(!wiphy->pmsr_capa->ftm.preambles ||
692
+ !wiphy->pmsr_capa->ftm.bandwidths))
693
+ return -EINVAL;
694
+ if (WARN_ON(wiphy->pmsr_capa->ftm.preambles &
695
+ ~(BIT(NL80211_PREAMBLE_LEGACY) |
696
+ BIT(NL80211_PREAMBLE_HT) |
697
+ BIT(NL80211_PREAMBLE_VHT) |
698
+ BIT(NL80211_PREAMBLE_HE) |
699
+ BIT(NL80211_PREAMBLE_DMG))))
700
+ return -EINVAL;
701
+ if (WARN_ON((wiphy->pmsr_capa->ftm.trigger_based ||
702
+ wiphy->pmsr_capa->ftm.non_trigger_based) &&
703
+ !(wiphy->pmsr_capa->ftm.preambles &
704
+ BIT(NL80211_PREAMBLE_HE))))
705
+ return -EINVAL;
706
+ if (WARN_ON(wiphy->pmsr_capa->ftm.bandwidths &
707
+ ~(BIT(NL80211_CHAN_WIDTH_20_NOHT) |
708
+ BIT(NL80211_CHAN_WIDTH_20) |
709
+ BIT(NL80211_CHAN_WIDTH_40) |
710
+ BIT(NL80211_CHAN_WIDTH_80) |
711
+ BIT(NL80211_CHAN_WIDTH_80P80) |
712
+ BIT(NL80211_CHAN_WIDTH_160) |
713
+ BIT(NL80211_CHAN_WIDTH_5) |
714
+ BIT(NL80211_CHAN_WIDTH_10))))
715
+ return -EINVAL;
716
+ }
717
+
667718 /*
668719 * if a wiphy has unsupported modes for regulatory channel enforcement,
669720 * opt-out of enforcement checking
....@@ -745,6 +796,7 @@
745796 /* sanity check supported bands/channels */
746797 for (band = 0; band < NUM_NL80211_BANDS; band++) {
747798 u16 types = 0;
799
+ bool have_he = false;
748800
749801 sband = wiphy->bands[band];
750802 if (!sband)
....@@ -754,11 +806,17 @@
754806 if (WARN_ON(!sband->n_channels))
755807 return -EINVAL;
756808 /*
757
- * on 60GHz band, there are no legacy rates, so
809
+ * on 60GHz or sub-1Ghz band, there are no legacy rates, so
758810 * n_bitrates is 0
759811 */
760
- if (WARN_ON(band != NL80211_BAND_60GHZ &&
812
+ if (WARN_ON((band != NL80211_BAND_60GHZ &&
813
+ band != NL80211_BAND_S1GHZ) &&
761814 !sband->n_bitrates))
815
+ return -EINVAL;
816
+
817
+ if (WARN_ON(band == NL80211_BAND_6GHZ &&
818
+ (sband->ht_cap.ht_supported ||
819
+ sband->vht_cap.vht_supported)))
762820 return -EINVAL;
763821
764822 /*
....@@ -788,6 +846,9 @@
788846 sband->channels[i].orig_mpwr =
789847 sband->channels[i].max_power;
790848 sband->channels[i].band = band;
849
+
850
+ if (WARN_ON(sband->channels[i].freq_offset >= 1000))
851
+ return -EINVAL;
791852 }
792853
793854 for (i = 0; i < sband->n_iftype_data; i++) {
....@@ -805,7 +866,16 @@
805866 return -EINVAL;
806867
807868 types |= iftd->types_mask;
869
+
870
+ if (i == 0)
871
+ have_he = iftd->he_cap.has_he;
872
+ else
873
+ have_he = have_he &&
874
+ iftd->he_cap.has_he;
808875 }
876
+
877
+ if (WARN_ON(!have_he && band == NL80211_BAND_6GHZ))
878
+ return -EINVAL;
809879
810880 have_band = true;
811881 }
....@@ -813,6 +883,19 @@
813883 if (!have_band) {
814884 WARN_ON(1);
815885 return -EINVAL;
886
+ }
887
+
888
+ for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
889
+ /*
890
+ * Validate we have a policy (can be explicitly set to
891
+ * VENDOR_CMD_RAW_DATA which is non-NULL) and also that
892
+ * we have at least one of doit/dumpit.
893
+ */
894
+ if (WARN_ON(!rdev->wiphy.vendor_commands[i].policy))
895
+ return -EINVAL;
896
+ if (WARN_ON(!rdev->wiphy.vendor_commands[i].doit &&
897
+ !rdev->wiphy.vendor_commands[i].dumpit))
898
+ return -EINVAL;
816899 }
817900
818901 #ifdef CONFIG_PM
....@@ -835,21 +918,18 @@
835918 return res;
836919 }
837920
838
- /* set up regulatory info */
839
- wiphy_regulatory_register(wiphy);
840
-
841921 list_add_rcu(&rdev->list, &cfg80211_rdev_list);
842922 cfg80211_rdev_list_generation++;
843923
844924 /* add to debugfs */
845
- rdev->wiphy.debugfsdir =
846
- debugfs_create_dir(wiphy_name(&rdev->wiphy),
847
- ieee80211_debugfs_dir);
848
- if (IS_ERR(rdev->wiphy.debugfsdir))
849
- rdev->wiphy.debugfsdir = NULL;
925
+ rdev->wiphy.debugfsdir = debugfs_create_dir(wiphy_name(&rdev->wiphy),
926
+ ieee80211_debugfs_dir);
850927
851928 cfg80211_debugfs_rdev_add(rdev);
852929 nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY);
930
+
931
+ /* set up regulatory info */
932
+ wiphy_regulatory_register(wiphy);
853933
854934 if (wiphy->regulatory_flags & REGULATORY_CUSTOM_REG) {
855935 struct regulatory_request request;
....@@ -971,9 +1051,9 @@
9711051 cancel_delayed_work_sync(&rdev->dfs_update_channels_wk);
9721052 flush_work(&rdev->destroy_work);
9731053 flush_work(&rdev->sched_scan_stop_wk);
974
- flush_work(&rdev->mlme_unreg_wk);
9751054 flush_work(&rdev->propagate_radar_detect_wk);
9761055 flush_work(&rdev->propagate_cac_done_wk);
1056
+ flush_work(&rdev->mgmt_registrations_update_wk);
9771057
9781058 #ifdef CONFIG_PM
9791059 if (rdev->wiphy.wowlan_config && rdev->ops->set_wakeup)
....@@ -1009,7 +1089,7 @@
10091089 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
10101090
10111091 if (rfkill_set_hw_state(rdev->rfkill, blocked))
1012
- schedule_work(&rdev->rfkill_sync);
1092
+ schedule_work(&rdev->rfkill_block);
10131093 }
10141094 EXPORT_SYMBOL(wiphy_rfkill_set_hw_state);
10151095
....@@ -1019,35 +1099,51 @@
10191099 wdev->cqm_config = NULL;
10201100 }
10211101
1022
-void cfg80211_unregister_wdev(struct wireless_dev *wdev)
1102
+static void __cfg80211_unregister_wdev(struct wireless_dev *wdev, bool sync)
10231103 {
10241104 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
10251105
10261106 ASSERT_RTNL();
10271107
1028
- if (WARN_ON(wdev->netdev))
1029
- return;
1108
+ flush_work(&wdev->pmsr_free_wk);
10301109
10311110 nl80211_notify_iface(rdev, wdev, NL80211_CMD_DEL_INTERFACE);
10321111
10331112 list_del_rcu(&wdev->list);
1034
- synchronize_rcu();
1113
+ if (sync)
1114
+ synchronize_rcu();
10351115 rdev->devlist_generation++;
1116
+
1117
+ cfg80211_mlme_purge_registrations(wdev);
10361118
10371119 switch (wdev->iftype) {
10381120 case NL80211_IFTYPE_P2P_DEVICE:
1039
- cfg80211_mlme_purge_registrations(wdev);
10401121 cfg80211_stop_p2p_device(rdev, wdev);
10411122 break;
10421123 case NL80211_IFTYPE_NAN:
10431124 cfg80211_stop_nan(rdev, wdev);
10441125 break;
10451126 default:
1046
- WARN_ON_ONCE(1);
10471127 break;
10481128 }
10491129
1130
+#ifdef CONFIG_CFG80211_WEXT
1131
+ kfree_sensitive(wdev->wext.keys);
1132
+ wdev->wext.keys = NULL;
1133
+#endif
1134
+ /* only initialized if we have a netdev */
1135
+ if (wdev->netdev)
1136
+ flush_work(&wdev->disconnect_wk);
1137
+
10501138 cfg80211_cqm_config_free(wdev);
1139
+}
1140
+
1141
+void cfg80211_unregister_wdev(struct wireless_dev *wdev)
1142
+{
1143
+ if (WARN_ON(wdev->netdev))
1144
+ return;
1145
+
1146
+ __cfg80211_unregister_wdev(wdev, true);
10511147 }
10521148 EXPORT_SYMBOL(cfg80211_unregister_wdev);
10531149
....@@ -1073,6 +1169,8 @@
10731169
10741170 ASSERT_RTNL();
10751171 ASSERT_WDEV_LOCK(wdev);
1172
+
1173
+ cfg80211_pmsr_wdev_down(wdev);
10761174
10771175 switch (wdev->iftype) {
10781176 case NL80211_IFTYPE_ADHOC:
....@@ -1153,6 +1251,55 @@
11531251 }
11541252 EXPORT_SYMBOL(cfg80211_stop_iface);
11551253
1254
+void cfg80211_init_wdev(struct wireless_dev *wdev)
1255
+{
1256
+ mutex_init(&wdev->mtx);
1257
+ INIT_LIST_HEAD(&wdev->event_list);
1258
+ spin_lock_init(&wdev->event_lock);
1259
+ INIT_LIST_HEAD(&wdev->mgmt_registrations);
1260
+ INIT_LIST_HEAD(&wdev->pmsr_list);
1261
+ spin_lock_init(&wdev->pmsr_lock);
1262
+ INIT_WORK(&wdev->pmsr_free_wk, cfg80211_pmsr_free_wk);
1263
+
1264
+#ifdef CONFIG_CFG80211_WEXT
1265
+ wdev->wext.default_key = -1;
1266
+ wdev->wext.default_mgmt_key = -1;
1267
+ wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
1268
+#endif
1269
+
1270
+ if (wdev->wiphy->flags & WIPHY_FLAG_PS_ON_BY_DEFAULT)
1271
+ wdev->ps = true;
1272
+ else
1273
+ wdev->ps = false;
1274
+ /* allow mac80211 to determine the timeout */
1275
+ wdev->ps_timeout = -1;
1276
+
1277
+ if ((wdev->iftype == NL80211_IFTYPE_STATION ||
1278
+ wdev->iftype == NL80211_IFTYPE_P2P_CLIENT ||
1279
+ wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr)
1280
+ wdev->netdev->priv_flags |= IFF_DONT_BRIDGE;
1281
+
1282
+ INIT_WORK(&wdev->disconnect_wk, cfg80211_autodisconnect_wk);
1283
+}
1284
+
1285
+void cfg80211_register_wdev(struct cfg80211_registered_device *rdev,
1286
+ struct wireless_dev *wdev)
1287
+{
1288
+ /*
1289
+ * We get here also when the interface changes network namespaces,
1290
+ * as it's registered into the new one, but we don't want it to
1291
+ * change ID in that case. Checking if the ID is already assigned
1292
+ * works, because 0 isn't considered a valid ID and the memory is
1293
+ * 0-initialized.
1294
+ */
1295
+ if (!wdev->identifier)
1296
+ wdev->identifier = ++rdev->wdev_id;
1297
+ list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
1298
+ rdev->devlist_generation++;
1299
+
1300
+ nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
1301
+}
1302
+
11561303 static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
11571304 unsigned long state, void *ptr)
11581305 {
....@@ -1171,6 +1318,11 @@
11711318 switch (state) {
11721319 case NETDEV_POST_INIT:
11731320 SET_NETDEV_DEVTYPE(dev, &wiphy_type);
1321
+ wdev->netdev = dev;
1322
+ /* can only change netns with wiphy */
1323
+ dev->features |= NETIF_F_NETNS_LOCAL;
1324
+
1325
+ cfg80211_init_wdev(wdev);
11741326 break;
11751327 case NETDEV_REGISTER:
11761328 /*
....@@ -1178,52 +1330,12 @@
11781330 * called within code protected by it when interfaces
11791331 * are added with nl80211.
11801332 */
1181
- mutex_init(&wdev->mtx);
1182
- INIT_LIST_HEAD(&wdev->event_list);
1183
- spin_lock_init(&wdev->event_lock);
1184
- INIT_LIST_HEAD(&wdev->mgmt_registrations);
1185
- spin_lock_init(&wdev->mgmt_registrations_lock);
1186
-
1187
- /*
1188
- * We get here also when the interface changes network namespaces,
1189
- * as it's registered into the new one, but we don't want it to
1190
- * change ID in that case. Checking if the ID is already assigned
1191
- * works, because 0 isn't considered a valid ID and the memory is
1192
- * 0-initialized.
1193
- */
1194
- if (!wdev->identifier)
1195
- wdev->identifier = ++rdev->wdev_id;
1196
- list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
1197
- rdev->devlist_generation++;
1198
- /* can only change netns with wiphy */
1199
- dev->features |= NETIF_F_NETNS_LOCAL;
1200
-
12011333 if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj,
12021334 "phy80211")) {
12031335 pr_err("failed to add phy80211 symlink to netdev!\n");
12041336 }
1205
- wdev->netdev = dev;
1206
-#ifdef CONFIG_CFG80211_WEXT
1207
- wdev->wext.default_key = -1;
1208
- wdev->wext.default_mgmt_key = -1;
1209
- wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
1210
-#endif
12111337
1212
- if (wdev->wiphy->flags & WIPHY_FLAG_PS_ON_BY_DEFAULT)
1213
- wdev->ps = true;
1214
- else
1215
- wdev->ps = false;
1216
- /* allow mac80211 to determine the timeout */
1217
- wdev->ps_timeout = -1;
1218
-
1219
- if ((wdev->iftype == NL80211_IFTYPE_STATION ||
1220
- wdev->iftype == NL80211_IFTYPE_P2P_CLIENT ||
1221
- wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr)
1222
- dev->priv_flags |= IFF_DONT_BRIDGE;
1223
-
1224
- INIT_WORK(&wdev->disconnect_wk, cfg80211_autodisconnect_wk);
1225
-
1226
- nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
1338
+ cfg80211_register_wdev(rdev, wdev);
12271339 break;
12281340 case NETDEV_GOING_DOWN:
12291341 cfg80211_leave(rdev, wdev);
....@@ -1231,14 +1343,16 @@
12311343 case NETDEV_DOWN:
12321344 cfg80211_update_iface_num(rdev, wdev->iftype, -1);
12331345 if (rdev->scan_req && rdev->scan_req->wdev == wdev) {
1234
- if (WARN_ON(!rdev->scan_req->notified))
1346
+ if (WARN_ON(!rdev->scan_req->notified &&
1347
+ (!rdev->int_scan_req ||
1348
+ !rdev->int_scan_req->notified)))
12351349 rdev->scan_req->info.aborted = true;
12361350 ___cfg80211_scan_done(rdev, false);
12371351 }
12381352
12391353 list_for_each_entry_safe(pos, tmp,
12401354 &rdev->sched_scan_req_list, list) {
1241
- if (WARN_ON(pos && pos->dev == wdev->netdev))
1355
+ if (WARN_ON(pos->dev == wdev->netdev))
12421356 cfg80211_stop_sched_scan_req(rdev, pos, false);
12431357 }
12441358
....@@ -1302,17 +1416,8 @@
13021416 * remove and clean it up.
13031417 */
13041418 if (!list_empty(&wdev->list)) {
1305
- nl80211_notify_iface(rdev, wdev,
1306
- NL80211_CMD_DEL_INTERFACE);
1419
+ __cfg80211_unregister_wdev(wdev, false);
13071420 sysfs_remove_link(&dev->dev.kobj, "phy80211");
1308
- list_del_rcu(&wdev->list);
1309
- rdev->devlist_generation++;
1310
- cfg80211_mlme_purge_registrations(wdev);
1311
-#ifdef CONFIG_CFG80211_WEXT
1312
- kzfree(wdev->wext.keys);
1313
-#endif
1314
- flush_work(&wdev->disconnect_wk);
1315
- cfg80211_cqm_config_free(wdev);
13161421 }
13171422 /*
13181423 * synchronise (so that we won't find this netdev