Skip to content

Commit bdd90d5

Browse files
jmberg-intellinvjw
authored andcommitted
cfg80211: validate nl80211 station handling better
The nl80211 station handling code is a bit messy and doesn't do a lot of validation. It seems like this could be an issue for drivers that don't use mac80211 to validate everything. As cfg80211 doesn't keep station state, move the validation of allowing supported_rates to change for TDLS only in station mode to mac80211. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent d83023d commit bdd90d5

4 files changed

Lines changed: 131 additions & 89 deletions

File tree

‎include/linux/nl80211.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,11 @@ enum nl80211_iftype {
15361536
* @NL80211_STA_FLAG_WME: station is WME/QoS capable
15371537
* @NL80211_STA_FLAG_MFP: station uses management frame protection
15381538
* @NL80211_STA_FLAG_AUTHENTICATED: station is authenticated
1539-
* @NL80211_STA_FLAG_TDLS_PEER: station is a TDLS peer
1539+
* @NL80211_STA_FLAG_TDLS_PEER: station is a TDLS peer -- this flag should
1540+
* only be used in managed mode (even in the flags mask). Note that the
1541+
* flag can't be changed, it is only valid while adding a station, and
1542+
* attempts to change it will silently be ignored (rather than rejected
1543+
* as errors.)
15401544
* @NL80211_STA_FLAG_MAX: highest station flag number currently defined
15411545
* @__NL80211_STA_FLAG_AFTER_LAST: internal use
15421546
*/

‎include/net/cfg80211.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,12 @@ struct cfg80211_gtk_rekey_data {
13461346
*
13471347
* @add_station: Add a new station.
13481348
* @del_station: Remove a station; @mac may be NULL to remove all stations.
1349-
* @change_station: Modify a given station.
1349+
* @change_station: Modify a given station. Note that flags changes are not much
1350+
* validated in cfg80211, in particular the auth/assoc/authorized flags
1351+
* might come to the driver in invalid combinations -- make sure to check
1352+
* them, also against the existing state! Also, supported_rates changes are
1353+
* not checked in station mode -- drivers need to reject (or ignore) them
1354+
* for anything but TDLS peers.
13501355
* @get_station: get station information for the station identified by @mac
13511356
* @dump_station: dump station callback -- resume dump at index @idx
13521357
*

‎net/mac80211/cfg.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,14 @@ static int ieee80211_change_station(struct wiphy *wiphy,
976976
return -EINVAL;
977977
}
978978

979+
/* in station mode, supported rates are only valid with TDLS */
980+
if (sdata->vif.type == NL80211_IFTYPE_STATION &&
981+
params->supported_rates &&
982+
!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
983+
rcu_read_unlock();
984+
return -EINVAL;
985+
}
986+
979987
if (params->vlan && params->vlan != sta->sdata->dev) {
980988
vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
981989

‎net/wireless/nl80211.c‎

Lines changed: 112 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,6 +2579,9 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
25792579
params.ht_capa =
25802580
nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
25812581

2582+
if (!rdev->ops->change_station)
2583+
return -EOPNOTSUPP;
2584+
25822585
if (parse_station_flags(info, &params))
25832586
return -EINVAL;
25842587

@@ -2590,73 +2593,84 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
25902593
params.plink_state =
25912594
nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
25922595

2593-
params.vlan = get_vlan(info, rdev);
2594-
if (IS_ERR(params.vlan))
2595-
return PTR_ERR(params.vlan);
2596-
2597-
/* validate settings */
2598-
err = 0;
2599-
26002596
switch (dev->ieee80211_ptr->iftype) {
26012597
case NL80211_IFTYPE_AP:
26022598
case NL80211_IFTYPE_AP_VLAN:
26032599
case NL80211_IFTYPE_P2P_GO:
26042600
/* disallow mesh-specific things */
26052601
if (params.plink_action)
2606-
err = -EINVAL;
2602+
return -EINVAL;
2603+
2604+
/* TDLS can't be set, ... */
2605+
if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2606+
return -EINVAL;
2607+
/*
2608+
* ... but don't bother the driver with it. This works around
2609+
* a hostapd/wpa_supplicant issue -- it always includes the
2610+
* TLDS_PEER flag in the mask even for AP mode.
2611+
*/
2612+
params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2613+
2614+
/* accept only the listed bits */
2615+
if (params.sta_flags_mask &
2616+
~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2617+
BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2618+
BIT(NL80211_STA_FLAG_WME) |
2619+
BIT(NL80211_STA_FLAG_MFP)))
2620+
return -EINVAL;
2621+
2622+
/* must be last in here for error handling */
2623+
params.vlan = get_vlan(info, rdev);
2624+
if (IS_ERR(params.vlan))
2625+
return PTR_ERR(params.vlan);
26072626
break;
26082627
case NL80211_IFTYPE_P2P_CLIENT:
26092628
case NL80211_IFTYPE_STATION:
26102629
/* disallow things sta doesn't support */
26112630
if (params.plink_action)
2612-
err = -EINVAL;
2613-
if (params.vlan)
2614-
err = -EINVAL;
2615-
if (params.supported_rates &&
2616-
!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
2617-
err = -EINVAL;
2631+
return -EINVAL;
26182632
if (params.ht_capa)
2619-
err = -EINVAL;
2633+
return -EINVAL;
26202634
if (params.listen_interval >= 0)
2621-
err = -EINVAL;
2622-
if (params.sta_flags_mask &
2623-
~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2624-
BIT(NL80211_STA_FLAG_TDLS_PEER)))
2625-
err = -EINVAL;
2626-
/* can't change the TDLS bit */
2627-
if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
2628-
(params.sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)))
2629-
err = -EINVAL;
2635+
return -EINVAL;
2636+
/*
2637+
* Don't allow userspace to change the TDLS_PEER flag,
2638+
* but silently ignore attempts to change it since we
2639+
* don't have state here to verify that it doesn't try
2640+
* to change the flag.
2641+
*/
2642+
params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2643+
2644+
/* reject any changes other than AUTHORIZED */
2645+
if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2646+
return -EINVAL;
26302647
break;
26312648
case NL80211_IFTYPE_MESH_POINT:
26322649
/* disallow things mesh doesn't support */
26332650
if (params.vlan)
2634-
err = -EINVAL;
2651+
return -EINVAL;
26352652
if (params.ht_capa)
2636-
err = -EINVAL;
2653+
return -EINVAL;
26372654
if (params.listen_interval >= 0)
2638-
err = -EINVAL;
2655+
return -EINVAL;
2656+
/*
2657+
* No special handling for TDLS here -- the userspace
2658+
* mesh code doesn't have this bug.
2659+
*/
26392660
if (params.sta_flags_mask &
26402661
~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
26412662
BIT(NL80211_STA_FLAG_MFP) |
26422663
BIT(NL80211_STA_FLAG_AUTHORIZED)))
2643-
err = -EINVAL;
2664+
return -EINVAL;
26442665
break;
26452666
default:
2646-
err = -EINVAL;
2667+
return -EOPNOTSUPP;
26472668
}
26482669

2649-
if (err)
2650-
goto out;
2651-
2652-
if (!rdev->ops->change_station) {
2653-
err = -EOPNOTSUPP;
2654-
goto out;
2655-
}
2670+
/* be aware of params.vlan when changing code here */
26562671

26572672
err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
26582673

2659-
out:
26602674
if (params.vlan)
26612675
dev_put(params.vlan);
26622676

@@ -2711,70 +2725,81 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
27112725
params.plink_action =
27122726
nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
27132727

2728+
if (!rdev->ops->add_station)
2729+
return -EOPNOTSUPP;
2730+
27142731
if (parse_station_flags(info, &params))
27152732
return -EINVAL;
27162733

2717-
/* parse WME attributes if sta is WME capable */
2718-
if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
2719-
(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
2720-
info->attrs[NL80211_ATTR_STA_WME]) {
2721-
struct nlattr *tb[NL80211_STA_WME_MAX + 1];
2722-
struct nlattr *nla;
2734+
switch (dev->ieee80211_ptr->iftype) {
2735+
case NL80211_IFTYPE_AP:
2736+
case NL80211_IFTYPE_AP_VLAN:
2737+
case NL80211_IFTYPE_P2P_GO:
2738+
/* parse WME attributes if sta is WME capable */
2739+
if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
2740+
(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
2741+
info->attrs[NL80211_ATTR_STA_WME]) {
2742+
struct nlattr *tb[NL80211_STA_WME_MAX + 1];
2743+
struct nlattr *nla;
2744+
2745+
nla = info->attrs[NL80211_ATTR_STA_WME];
2746+
err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
2747+
nl80211_sta_wme_policy);
2748+
if (err)
2749+
return err;
27232750

2724-
nla = info->attrs[NL80211_ATTR_STA_WME];
2725-
err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
2726-
nl80211_sta_wme_policy);
2727-
if (err)
2728-
return err;
2751+
if (tb[NL80211_STA_WME_UAPSD_QUEUES])
2752+
params.uapsd_queues =
2753+
nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
2754+
if (params.uapsd_queues &
2755+
~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
2756+
return -EINVAL;
27292757

2730-
if (tb[NL80211_STA_WME_UAPSD_QUEUES])
2731-
params.uapsd_queues =
2732-
nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
2733-
if (params.uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
2734-
return -EINVAL;
2758+
if (tb[NL80211_STA_WME_MAX_SP])
2759+
params.max_sp =
2760+
nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
27352761

2736-
if (tb[NL80211_STA_WME_MAX_SP])
2737-
params.max_sp =
2738-
nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
2762+
if (params.max_sp &
2763+
~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
2764+
return -EINVAL;
27392765

2740-
if (params.max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
2766+
params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
2767+
}
2768+
/* TDLS peers cannot be added */
2769+
if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
27412770
return -EINVAL;
2771+
/* but don't bother the driver with it */
2772+
params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
27422773

2743-
params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
2774+
/* must be last in here for error handling */
2775+
params.vlan = get_vlan(info, rdev);
2776+
if (IS_ERR(params.vlan))
2777+
return PTR_ERR(params.vlan);
2778+
break;
2779+
case NL80211_IFTYPE_MESH_POINT:
2780+
/* TDLS peers cannot be added */
2781+
if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2782+
return -EINVAL;
2783+
break;
2784+
case NL80211_IFTYPE_STATION:
2785+
/* Only TDLS peers can be added */
2786+
if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
2787+
return -EINVAL;
2788+
/* Can only add if TDLS ... */
2789+
if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
2790+
return -EOPNOTSUPP;
2791+
/* ... with external setup is supported */
2792+
if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
2793+
return -EOPNOTSUPP;
2794+
break;
2795+
default:
2796+
return -EOPNOTSUPP;
27442797
}
27452798

2746-
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2747-
dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
2748-
dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
2749-
dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO &&
2750-
dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
2751-
return -EINVAL;
2752-
2753-
/*
2754-
* Only managed stations can add TDLS peers, and only when the
2755-
* wiphy supports external TDLS setup.
2756-
*/
2757-
if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION &&
2758-
!((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
2759-
(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
2760-
(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)))
2761-
return -EINVAL;
2762-
2763-
params.vlan = get_vlan(info, rdev);
2764-
if (IS_ERR(params.vlan))
2765-
return PTR_ERR(params.vlan);
2766-
2767-
/* validate settings */
2768-
err = 0;
2769-
2770-
if (!rdev->ops->add_station) {
2771-
err = -EOPNOTSUPP;
2772-
goto out;
2773-
}
2799+
/* be aware of params.vlan when changing code here */
27742800

27752801
err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
27762802

2777-
out:
27782803
if (params.vlan)
27792804
dev_put(params.vlan);
27802805
return err;

0 commit comments

Comments
 (0)