Skip to content

Commit 56be393

Browse files
Jouni Malinenjmberg-intel
authored andcommitted
cfg80211: Support key configuration for Beacon protection (BIGTK)
IEEE P802.11-REVmd/D3.0 adds support for protecting Beacon frames using a new set of keys (BIGTK; key index 6..7) similarly to the way group-addressed Robust Management frames are protected (IGTK; key index 4..5). Extend cfg80211 and nl80211 to allow the new BIGTK to be configured. Add an extended feature flag to indicate driver support for the new key index values to avoid array overflows in driver implementations and also to indicate to user space when this functionality is available. Signed-off-by: Jouni Malinen <jouni@codeaurora.org> Link: https://lore.kernel.org/r/20200222132548.20835-2-jouni@codeaurora.org Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent f8af764 commit 56be393

7 files changed

Lines changed: 101 additions & 14 deletions

File tree

‎include/net/cfg80211.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3369,6 +3369,8 @@ struct cfg80211_update_owe_info {
33693369
* @set_default_key: set the default key on an interface
33703370
*
33713371
* @set_default_mgmt_key: set the default management frame key on an interface
3372+
3373+
* @set_default_beacon_key: set the default Beacon frame key on an interface
33723374
*
33733375
* @set_rekey_data: give the data necessary for GTK rekeying to the driver
33743376
*
@@ -3702,6 +3704,9 @@ struct cfg80211_ops {
37023704
int (*set_default_mgmt_key)(struct wiphy *wiphy,
37033705
struct net_device *netdev,
37043706
u8 key_index);
3707+
int (*set_default_beacon_key)(struct wiphy *wiphy,
3708+
struct net_device *netdev,
3709+
u8 key_index);
37053710

37063711
int (*start_ap)(struct wiphy *wiphy, struct net_device *dev,
37073712
struct cfg80211_ap_settings *settings);

‎include/uapi/linux/nl80211.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4550,6 +4550,7 @@ enum nl80211_key_default_types {
45504550
* See &enum nl80211_key_default_types.
45514551
* @NL80211_KEY_MODE: the mode from enum nl80211_key_mode.
45524552
* Defaults to @NL80211_KEY_RX_TX.
4553+
* @NL80211_KEY_DEFAULT_BEACON: flag indicating default Beacon frame key
45534554
*
45544555
* @__NL80211_KEY_AFTER_LAST: internal
45554556
* @NL80211_KEY_MAX: highest key attribute
@@ -4565,6 +4566,7 @@ enum nl80211_key_attributes {
45654566
NL80211_KEY_TYPE,
45664567
NL80211_KEY_DEFAULT_TYPES,
45674568
NL80211_KEY_MODE,
4569+
NL80211_KEY_DEFAULT_BEACON,
45684570

45694571
/* keep last */
45704572
__NL80211_KEY_AFTER_LAST,
@@ -5539,6 +5541,9 @@ enum nl80211_feature_flags {
55395541
* feature, which prevents bufferbloat by using the expected transmission
55405542
* time to limit the amount of data buffered in the hardware.
55415543
*
5544+
* @NL80211_EXT_FEATURE_BEACON_PROTECTION: The driver supports Beacon protection
5545+
* and can receive key configuration for BIGTK using key indexes 6 and 7.
5546+
*
55425547
* @NUM_NL80211_EXT_FEATURES: number of extended features.
55435548
* @MAX_NL80211_EXT_FEATURES: highest extended feature index.
55445549
*/
@@ -5586,6 +5591,7 @@ enum nl80211_ext_feature_index {
55865591
NL80211_EXT_FEATURE_SAE_OFFLOAD,
55875592
NL80211_EXT_FEATURE_VLAN_OFFLOAD,
55885593
NL80211_EXT_FEATURE_AQL,
5594+
NL80211_EXT_FEATURE_BEACON_PROTECTION,
55895595

55905596
/* add new features before the definition below */
55915597
NUM_NL80211_EXT_FEATURES,

‎net/wireless/nl80211.c‎

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
368368
[NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
369369
[NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
370370
.len = WLAN_MAX_KEY_LEN },
371-
[NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 5),
371+
[NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7),
372372
[NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
373373
[NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
374374
[NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
@@ -1037,7 +1037,7 @@ struct key_parse {
10371037
struct key_params p;
10381038
int idx;
10391039
int type;
1040-
bool def, defmgmt;
1040+
bool def, defmgmt, defbeacon;
10411041
bool def_uni, def_multi;
10421042
};
10431043

@@ -1053,12 +1053,13 @@ static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
10531053

10541054
k->def = !!tb[NL80211_KEY_DEFAULT];
10551055
k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
1056+
k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON];
10561057

10571058
if (k->def) {
10581059
k->def_uni = true;
10591060
k->def_multi = true;
10601061
}
1061-
if (k->defmgmt)
1062+
if (k->defmgmt || k->defbeacon)
10621063
k->def_multi = true;
10631064

10641065
if (tb[NL80211_KEY_IDX])
@@ -1165,14 +1166,17 @@ static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
11651166
if (err)
11661167
return err;
11671168

1168-
if (k->def && k->defmgmt) {
1169-
GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid");
1169+
if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) +
1170+
(k->defbeacon ? 1 : 0) > 1) {
1171+
GENL_SET_ERR_MSG(info,
1172+
"key with multiple default flags is invalid");
11701173
return -EINVAL;
11711174
}
11721175

1173-
if (k->defmgmt) {
1176+
if (k->defmgmt || k->defbeacon) {
11741177
if (k->def_uni || !k->def_multi) {
1175-
GENL_SET_ERR_MSG(info, "defmgmt key must be mcast");
1178+
GENL_SET_ERR_MSG(info,
1179+
"defmgmt/defbeacon key must be mcast");
11761180
return -EINVAL;
11771181
}
11781182
}
@@ -1184,14 +1188,20 @@ static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
11841188
"defmgmt key idx not 4 or 5");
11851189
return -EINVAL;
11861190
}
1191+
} else if (k->defbeacon) {
1192+
if (k->idx < 6 || k->idx > 7) {
1193+
GENL_SET_ERR_MSG(info,
1194+
"defbeacon key idx not 6 or 7");
1195+
return -EINVAL;
1196+
}
11871197
} else if (k->def) {
11881198
if (k->idx < 0 || k->idx > 3) {
11891199
GENL_SET_ERR_MSG(info, "def key idx not 0-3");
11901200
return -EINVAL;
11911201
}
11921202
} else {
1193-
if (k->idx < 0 || k->idx > 5) {
1194-
GENL_SET_ERR_MSG(info, "key idx not 0-5");
1203+
if (k->idx < 0 || k->idx > 7) {
1204+
GENL_SET_ERR_MSG(info, "key idx not 0-7");
11951205
return -EINVAL;
11961206
}
11971207
}
@@ -3817,8 +3827,14 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
38173827
void *hdr;
38183828
struct sk_buff *msg;
38193829

3820-
if (info->attrs[NL80211_ATTR_KEY_IDX])
3830+
if (info->attrs[NL80211_ATTR_KEY_IDX]) {
38213831
key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3832+
if (key_idx > 5 &&
3833+
!wiphy_ext_feature_isset(
3834+
&rdev->wiphy,
3835+
NL80211_EXT_FEATURE_BEACON_PROTECTION))
3836+
return -EINVAL;
3837+
}
38223838

38233839
if (info->attrs[NL80211_ATTR_MAC])
38243840
mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
@@ -3894,7 +3910,7 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
38943910
/* Only support setting default key and
38953911
* Extended Key ID action NL80211_KEY_SET_TX.
38963912
*/
3897-
if (!key.def && !key.defmgmt &&
3913+
if (!key.def && !key.defmgmt && !key.defbeacon &&
38983914
!(key.p.mode == NL80211_KEY_SET_TX))
38993915
return -EINVAL;
39003916

@@ -3941,6 +3957,24 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
39413957
#ifdef CONFIG_CFG80211_WEXT
39423958
dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
39433959
#endif
3960+
} else if (key.defbeacon) {
3961+
if (key.def_uni || !key.def_multi) {
3962+
err = -EINVAL;
3963+
goto out;
3964+
}
3965+
3966+
if (!rdev->ops->set_default_beacon_key) {
3967+
err = -EOPNOTSUPP;
3968+
goto out;
3969+
}
3970+
3971+
err = nl80211_key_allowed(dev->ieee80211_ptr);
3972+
if (err)
3973+
goto out;
3974+
3975+
err = rdev_set_default_beacon_key(rdev, dev, key.idx);
3976+
if (err)
3977+
goto out;
39443978
} else if (key.p.mode == NL80211_KEY_SET_TX &&
39453979
wiphy_ext_feature_isset(&rdev->wiphy,
39463980
NL80211_EXT_FEATURE_EXT_KEY_ID)) {

‎net/wireless/rdev-ops.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ rdev_set_default_mgmt_key(struct cfg80211_registered_device *rdev,
136136
return ret;
137137
}
138138

139+
static inline int
140+
rdev_set_default_beacon_key(struct cfg80211_registered_device *rdev,
141+
struct net_device *netdev, u8 key_index)
142+
{
143+
int ret;
144+
145+
trace_rdev_set_default_beacon_key(&rdev->wiphy, netdev, key_index);
146+
ret = rdev->ops->set_default_beacon_key(&rdev->wiphy, netdev,
147+
key_index);
148+
trace_rdev_return_int(&rdev->wiphy, ret);
149+
return ret;
150+
}
151+
139152
static inline int rdev_start_ap(struct cfg80211_registered_device *rdev,
140153
struct net_device *dev,
141154
struct cfg80211_ap_settings *settings)

‎net/wireless/sme.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,9 +1111,16 @@ void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
11111111
* Delete all the keys ... pairwise keys can't really
11121112
* exist any more anyway, but default keys might.
11131113
*/
1114-
if (rdev->ops->del_key)
1115-
for (i = 0; i < 6; i++)
1114+
if (rdev->ops->del_key) {
1115+
int max_key_idx = 5;
1116+
1117+
if (wiphy_ext_feature_isset(
1118+
wdev->wiphy,
1119+
NL80211_EXT_FEATURE_BEACON_PROTECTION))
1120+
max_key_idx = 7;
1121+
for (i = 0; i <= max_key_idx; i++)
11161122
rdev_del_key(rdev, dev, i, false, NULL);
1123+
}
11171124

11181125
rdev_set_qos_map(rdev, dev, NULL);
11191126

‎net/wireless/trace.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,23 @@ TRACE_EVENT(rdev_set_default_mgmt_key,
510510
WIPHY_PR_ARG, NETDEV_PR_ARG, __entry->key_index)
511511
);
512512

513+
TRACE_EVENT(rdev_set_default_beacon_key,
514+
TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, u8 key_index),
515+
TP_ARGS(wiphy, netdev, key_index),
516+
TP_STRUCT__entry(
517+
WIPHY_ENTRY
518+
NETDEV_ENTRY
519+
__field(u8, key_index)
520+
),
521+
TP_fast_assign(
522+
WIPHY_ASSIGN;
523+
NETDEV_ASSIGN;
524+
__entry->key_index = key_index;
525+
),
526+
TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", key index: %u",
527+
WIPHY_PR_ARG, NETDEV_PR_ARG, __entry->key_index)
528+
);
529+
513530
TRACE_EVENT(rdev_start_ap,
514531
TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
515532
struct cfg80211_ap_settings *settings),

‎net/wireless/util.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,12 @@ int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
231231
struct key_params *params, int key_idx,
232232
bool pairwise, const u8 *mac_addr)
233233
{
234-
if (key_idx < 0 || key_idx > 5)
234+
int max_key_idx = 5;
235+
236+
if (wiphy_ext_feature_isset(&rdev->wiphy,
237+
NL80211_EXT_FEATURE_BEACON_PROTECTION))
238+
max_key_idx = 7;
239+
if (key_idx < 0 || key_idx > max_key_idx)
235240
return -EINVAL;
236241

237242
if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))

0 commit comments

Comments
 (0)