Allow userspace to provide the NAN service parameters needed by an offloaded Discovery Engine. Add flags for the SDEA Data Path Required, Security Required, and GTK Required bits, and attributes for pairing bootstrapping methods, supported NAN cipher suite IDs, and the ND-PMK. Require SECURE_NAN for security-related service parameters, and validate CSID arrays and ND-PMK lengths in the netlink policy. Pairing Setup and NPK/NIK Caching are device capabilities advertised in the Device Capability Extension attribute, so carry them in NAN config. Accept these flags only when the Discovery Engine is offloaded and SECURE_NAN is supported. Store ND-PMK material in dynamically sized memory, free it with kfree_sensitive(), and clear the ADD_NAN_FUNCTION request skb because it may contain key material. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 24 +++++++ include/uapi/linux/nl80211.h | 36 +++++++++++ net/wireless/nl80211.c | 118 ++++++++++++++++++++++++++++++++++- net/wireless/util.c | 2 + 4 files changed, 179 insertions(+), 1 deletion(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index c166f97dcf81..b6e4cec22652 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4249,6 +4249,8 @@ struct cfg80211_nan_band_config { * notifications. * @instant_comm: if true, start Instant Communication (IC) as defined in * Chapter 13 of the Wi-Fi Aware Specification v4.0. + * @pairing_setup: if true, enable NAN pairing setup. + * @pairing_npk_caching: if true, enable NPK/NIK caching. * @band_cfgs: array of band specific configurations, indexed by * &enum nl80211_band values. * @extra_nan_attrs: pointer to additional NAN attributes. @@ -4265,6 +4267,8 @@ struct cfg80211_nan_conf { u8 discovery_beacon_interval; bool enable_dw_notification; bool instant_comm; + bool pairing_setup; + bool pairing_npk_caching; struct cfg80211_nan_band_config band_cfgs[NUM_NL80211_BANDS]; const u8 *extra_nan_attrs; u16 extra_nan_attrs_len; @@ -4441,6 +4445,18 @@ struct cfg80211_nan_func_filter { * @num_tx_filters: length of &tx_filters. * @instance_id: driver allocated id of the function. * @cookie: unique NAN function identifier. + * @data_path_required: if true, the SDEA Data Path Required bit is set. + * @security_required: if true, the SDEA Security Required bit is set. Requires + * @data_path_required and %NL80211_EXT_FEATURE_SECURE_NAN. + * @gtk_required: if true, the SDEA GTK Required bit is set for GTK protection + * of group-addressed data frames. Requires %NL80211_EXT_FEATURE_SECURE_NAN. + * @pairing_bootstrap_methods: bitmap of supported NAN pairing + * bootstrapping methods per the Wi-Fi Aware Specification Table 9-321. + * @csids: array of u32 NAN Cipher Suite ID (CSID) selectors supported by + * this service. See the Wi-Fi Aware Specification for cipher suite values. + * @num_csids: number of entries in @csids. + * @nd_pmk: pointer to the pre-shared NAN Data Path PMK (ND-PMK). + * @nd_pmk_len: length of @nd_pmk in bytes; depends on the cipher suite. */ struct cfg80211_nan_func { enum nl80211_nan_function_type type; @@ -4467,6 +4483,14 @@ struct cfg80211_nan_func { u8 num_rx_filters; u8 instance_id; u64 cookie; + bool data_path_required; + bool security_required; + bool gtk_required; + u16 pairing_bootstrap_methods; + u32 *csids; + u8 num_csids; + const u8 *nd_pmk; + u8 nd_pmk_len; }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 97a9dd7588c3..55fc50519f8f 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -7849,6 +7849,24 @@ enum nl80211_nan_func_term_reason { * Its type is u8 and it cannot be 0. * @NL80211_NAN_FUNC_TERM_REASON: NAN function termination reason. * See &enum nl80211_nan_func_term_reason. + * @NL80211_NAN_FUNC_DATA_PATH_REQUIRED: flag attribute. Sets the SDEA "Data + * Path Required" bit. + * @NL80211_NAN_FUNC_SECURITY_REQUIRED: flag attribute. Sets the SDEA + * "Security Required" bit. Requires + * @NL80211_NAN_FUNC_DATA_PATH_REQUIRED and + * %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_FUNC_GTK_REQUIRED: flag attribute. Sets the SDEA "GTK + * Required" bit for GTK protection of group-addressed data frames. + * Requires %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS: u16 bitmap of supported + * NAN pairing bootstrapping methods as defined in Wi-Fi Aware + * specification Table 9-321. Each bit corresponds to one method. Requires + * %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_FUNC_CSIDS: a set of u32 NAN Cipher Suite ID (CSID) + * selectors supported by this service. Requires + * %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_FUNC_ND_PMK: pre-shared NAN Data Path PMK (ND-PMK); its length + * depends on the cipher suite. Requires %NL80211_EXT_FEATURE_SECURE_NAN. * * @NUM_NL80211_NAN_FUNC_ATTR: internal * @NL80211_NAN_FUNC_ATTR_MAX: highest NAN function attribute @@ -7871,6 +7889,12 @@ enum nl80211_nan_func_attributes { NL80211_NAN_FUNC_TX_MATCH_FILTER, NL80211_NAN_FUNC_INSTANCE_ID, NL80211_NAN_FUNC_TERM_REASON, + NL80211_NAN_FUNC_DATA_PATH_REQUIRED, + NL80211_NAN_FUNC_SECURITY_REQUIRED, + NL80211_NAN_FUNC_GTK_REQUIRED, + NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS, + NL80211_NAN_FUNC_CSIDS, + NL80211_NAN_FUNC_ND_PMK, /* keep last */ NUM_NL80211_NAN_FUNC_ATTR, @@ -8012,6 +8036,16 @@ enum nl80211_nan_band_conf_attributes { * Wi-Fi Aware Specification v4.0. * %NL80211_NAN_CONF_DISCOVERY_BEACON_INTERVAL must be set as well. * This is a flag attribute. + * @NL80211_NAN_CONF_PAIRING_SETUP: flag attribute. Enables NAN pairing setup + * and is advertised as "Pairing Setup Enabled" in the DCEA. Only valid for + * devices that offload the NAN Discovery Engine (i.e. without + * %NL80211_NAN_CAPA_USERSPACE_DE) and requires + * %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_CONF_PAIRING_NPK_CACHING: flag attribute. Enables NPK/NIK + * caching and is advertised as "NPK/NIK Caching Enabled" in the DCEA. Only + * valid for devices that offload the NAN Discovery Engine (i.e. without + * %NL80211_NAN_CAPA_USERSPACE_DE) and requires + * %NL80211_EXT_FEATURE_SECURE_NAN. * @NUM_NL80211_NAN_CONF_ATTR: Internal. * @NL80211_NAN_CONF_ATTR_MAX: Highest NAN configuration attribute. * @@ -8028,6 +8062,8 @@ enum nl80211_nan_conf_attributes { NL80211_NAN_CONF_DISCOVERY_BEACON_INTERVAL, NL80211_NAN_CONF_NOTIFY_DW, NL80211_NAN_CONF_INSTANT_COMM, + NL80211_NAN_CONF_PAIRING_SETUP, + NL80211_NAN_CONF_PAIRING_NPK_CACHING, /* keep last */ NUM_NL80211_NAN_CONF_ATTR, diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 5df058b835db..6847d1cfc4a5 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -451,6 +451,34 @@ static int validate_nan_cluster_id(const struct nlattr *attr, return 0; } +static int validate_nan_csids(const struct nlattr *attr, + struct netlink_ext_ack *extack) +{ + unsigned int len = nla_len(attr); + + if (!len || len % sizeof(u32)) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "CSIDs must be a non-empty array of u32 values"); + return -EINVAL; + } + + return 0; +} + +static int validate_nan_pmk(const struct nlattr *attr, + struct netlink_ext_ack *extack) +{ + unsigned int len = nla_len(attr); + + if (len != WLAN_PMK_LEN && len != WLAN_PMK_LEN_SUITE_B_192) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "ND-PMK length must be 32 or 48 octets"); + return -EINVAL; + } + + return 0; +} + static int validate_nan_avail_blob(const struct nlattr *attr, struct netlink_ext_ack *extack) { @@ -806,6 +834,8 @@ nl80211_nan_conf_policy[NL80211_NAN_CONF_ATTR_MAX + 1] = { NLA_POLICY_RANGE(NLA_U8, 50, 200), [NL80211_NAN_CONF_NOTIFY_DW] = { .type = NLA_FLAG }, [NL80211_NAN_CONF_INSTANT_COMM] = { .type = NLA_FLAG }, + [NL80211_NAN_CONF_PAIRING_SETUP] = { .type = NLA_FLAG }, + [NL80211_NAN_CONF_PAIRING_NPK_CACHING] = { .type = NLA_FLAG }, }; static const struct netlink_range_validation nl80211_punct_bitmap_range = { @@ -1353,6 +1383,16 @@ nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, + [NL80211_NAN_FUNC_DATA_PATH_REQUIRED] = { .type = NLA_FLAG }, + [NL80211_NAN_FUNC_SECURITY_REQUIRED] = { .type = NLA_FLAG }, + [NL80211_NAN_FUNC_GTK_REQUIRED] = { .type = NLA_FLAG }, + [NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS] = { .type = NLA_U16 }, + [NL80211_NAN_FUNC_CSIDS] = + NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_nan_csids, + U8_MAX * sizeof(u32)), + [NL80211_NAN_FUNC_ND_PMK] = + NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_nan_pmk, + WLAN_PMK_LEN_SUITE_B_192), }; /* policy for Service Response Filter attributes */ @@ -17262,6 +17302,27 @@ static int nl80211_parse_nan_conf(struct wiphy *wiphy, } } + if (attrs[NL80211_NAN_CONF_PAIRING_SETUP] || + attrs[NL80211_NAN_CONF_PAIRING_NPK_CACHING]) { + if (wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_USERSPACE_DE) { + NL_SET_ERR_MSG(info->extack, + "Pairing configuration requires an offloaded NAN Discovery Engine"); + return -EOPNOTSUPP; + } + + if (!wiphy_ext_feature_isset(wiphy, + NL80211_EXT_FEATURE_SECURE_NAN)) { + NL_SET_ERR_MSG(info->extack, + "Pairing configuration requires SECURE_NAN"); + return -EOPNOTSUPP; + } + } + + conf->pairing_setup = + nla_get_flag(attrs[NL80211_NAN_CONF_PAIRING_SETUP]); + conf->pairing_npk_caching = + nla_get_flag(attrs[NL80211_NAN_CONF_PAIRING_NPK_CACHING]); + out: if (!conf->band_cfgs[NL80211_BAND_5GHZ].chan && (!conf->bands || conf->bands & BIT(NL80211_BAND_5GHZ))) { @@ -17600,6 +17661,60 @@ static int nl80211_nan_add_func(struct sk_buff *skb, goto out; } + func->data_path_required = + nla_get_flag(tb[NL80211_NAN_FUNC_DATA_PATH_REQUIRED]); + func->security_required = + nla_get_flag(tb[NL80211_NAN_FUNC_SECURITY_REQUIRED]); + func->gtk_required = nla_get_flag(tb[NL80211_NAN_FUNC_GTK_REQUIRED]); + + if (func->security_required && !func->data_path_required) { + NL_SET_ERR_MSG(info->extack, + "SDEA Security Required requires Data Path Required"); + err = -EINVAL; + goto out; + } + + if (func->security_required || func->gtk_required || + tb[NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS] || + tb[NL80211_NAN_FUNC_CSIDS] || tb[NL80211_NAN_FUNC_ND_PMK]) { + if (!wiphy_ext_feature_isset(wdev->wiphy, + NL80211_EXT_FEATURE_SECURE_NAN)) { + NL_SET_ERR_MSG(info->extack, + "Security attributes require SECURE_NAN"); + err = -EOPNOTSUPP; + goto out; + } + + if (tb[NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS]) + func->pairing_bootstrap_methods = + nla_get_u16(tb[NL80211_NAN_FUNC_PAIRING_BOOTSTRAP_METHODS]); + + if (tb[NL80211_NAN_FUNC_CSIDS]) { + int len = nla_len(tb[NL80211_NAN_FUNC_CSIDS]); + int n = len / sizeof(u32); + + func->csids = kmemdup(nla_data(tb[NL80211_NAN_FUNC_CSIDS]), + len, GFP_KERNEL); + if (!func->csids) { + err = -ENOMEM; + goto out; + } + func->num_csids = n; + } + + if (tb[NL80211_NAN_FUNC_ND_PMK]) { + int len = nla_len(tb[NL80211_NAN_FUNC_ND_PMK]); + + func->nd_pmk = kmemdup(nla_data(tb[NL80211_NAN_FUNC_ND_PMK]), + len, GFP_KERNEL); + if (!func->nd_pmk) { + err = -ENOMEM; + goto out; + } + func->nd_pmk_len = len; + } + } + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) { err = -ENOMEM; @@ -21211,7 +21326,8 @@ static const struct genl_small_ops nl80211_small_ops[] = { .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = nl80211_nan_add_func, .flags = GENL_ADMIN_PERM, - .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), + .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | + NL80211_FLAG_CLEAR_SKB), }, { .cmd = NL80211_CMD_DEL_NAN_FUNCTION, diff --git a/net/wireless/util.c b/net/wireless/util.c index 24cf0a2ba721..980b16c72d4f 100644 --- a/net/wireless/util.c +++ b/net/wireless/util.c @@ -2878,6 +2878,8 @@ void cfg80211_free_nan_func(struct cfg80211_nan_func *f) kfree(f->serv_spec_info); kfree(f->srf_bf); kfree(f->srf_macs); + kfree(f->csids); + kfree_sensitive(f->nd_pmk); for (i = 0; i < f->num_rx_filters; i++) kfree(f->rx_filters[i].filter); -- 2.34.1