From: Vinay Gannevaram With an offloaded NAN Discovery Engine the device builds and transmits the Service Discovery Frames, so everything that goes into them has to be expressed with function attributes. NAN pairing, however, can be handled in user space: the PASN Authentication frames, the bootstrapping frames and the Follow-up messages with the Shared Key Descriptor attribute are built by user space and sent with NL80211_CMD_FRAME. For pairing verification, the NAN Identity Resolution attribute, which user space derives from its NAN Identity Key, must also be included in the Publish and Subscribe messages that the device transmits in the discovery windows. Add NL80211_NAN_FUNC_EXTRA_ATTRS to pass a list of complete NAN attributes that the device appends to the frames of the function. This keeps pairing, and the NAN Identity Key, in user space. Validate the attribute framing, bound the length like information elements, and only accept the attribute if the driver advertises NL80211_NAN_CAPA_FUNC_EXTRA_ATTRS. Signed-off-by: Vinay Gannevaram Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 14 ++++++++ include/uapi/linux/nl80211.h | 15 +++++++++ net/wireless/core.c | 4 +++ net/wireless/nl80211.c | 63 ++++++++++++++++++++++++++++++++++++ net/wireless/trace.h | 9 ++++-- net/wireless/util.c | 1 + 6 files changed, 103 insertions(+), 3 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 1216bc5a183e..75fa387f3a0c 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4641,6 +4641,14 @@ struct cfg80211_nan_func_filter { * @chandef: channel definition for FTM ranging. * @range_report: if true, a NAN Ranging Report is required after the FTM * session. + * @extra_attrs: additional NAN attributes to append to the Service Discovery + * Frames transmitted for this function. It must not contain attributes that + * the device adds itself, such as the Service Descriptor attribute or + * attributes derived from other function fields. Typical uses include the + * NAN Identity Resolution attribute for pairing verification in Publish and + * Subscribe messages. The driver is responsible for ensuring the resulting + * frame fits its supported limits. + * @extra_attrs_len: length of @extra_attrs. */ struct cfg80211_nan_func { enum nl80211_nan_function_type type; @@ -4684,6 +4692,8 @@ struct cfg80211_nan_func { bool chandef_valid; struct cfg80211_chan_def chandef; bool range_report; + const u8 *extra_attrs; + u16 extra_attrs_len; }; /** @@ -6682,6 +6692,9 @@ struct wiphy_radio { * cfg80211_nan_ndp_request(), cfg80211_nan_ndp_status(), and * cfg80211_nan_ndp_terminated(). Secure NDPs require * %NL80211_EXT_FEATURE_SECURE_NAN. + * @WIPHY_NAN_FLAGS_FUNC_EXTRA_ATTRS: Driver accepts additional per-function + * NAN attributes when the Discovery Engine is offloaded. This flag cannot + * be used with %WIPHY_NAN_FLAGS_USERSPACE_DE. */ enum wiphy_nan_flags { WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC = BIT(0), @@ -6689,6 +6702,7 @@ enum wiphy_nan_flags { WIPHY_NAN_FLAGS_INSTANT_COMM = BIT(2), WIPHY_NAN_FLAGS_OFFLOAD_RANGING = BIT(3), WIPHY_NAN_FLAGS_OFFLOAD_NDP = BIT(4), + WIPHY_NAN_FLAGS_FUNC_EXTRA_ATTRS = BIT(5), }; /** diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 9a149db238ec..66894f79148b 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -7879,6 +7879,15 @@ enum nl80211_nan_func_term_reason { * using top-level attributes like %NL80211_ATTR_WIPHY_FREQ etc. * @NL80211_NAN_FUNC_RANGE_REPORT: flag indicating that a NAN Ranging * Report is required after the FTM session. + * @NL80211_NAN_FUNC_EXTRA_ATTRS: binary attribute containing additional NAN + * attributes to append to Service Discovery Frames transmitted for this + * function. Each attribute is encoded as a one-octet ID, a two-octet + * little-endian length, and that many body octets. It must not contain + * attributes that the device adds itself, such as the Service Descriptor + * attribute or attributes derived from other function attributes. Typical + * uses include the NAN Identity Resolution attribute for pairing + * verification in Publish and Subscribe messages. Requires + * %NL80211_NAN_CAPA_FUNC_EXTRA_ATTRS. * * @NUM_NL80211_NAN_FUNC_ATTR: internal * @NL80211_NAN_FUNC_ATTR_MAX: highest NAN function attribute @@ -7915,6 +7924,7 @@ enum nl80211_nan_func_attributes { NL80211_NAN_FUNC_PREAMBLE, NL80211_NAN_FUNC_CHAN, NL80211_NAN_FUNC_RANGE_REPORT, + NL80211_NAN_FUNC_EXTRA_ATTRS, /* keep last */ NUM_NL80211_NAN_FUNC_ATTR, @@ -9458,6 +9468,10 @@ enum nl80211_s1g_short_beacon_attrs { * and termination with %NL80211_CMD_NAN_NDP_INITIATE, * %NL80211_CMD_NAN_NDP_STATUS, and %NL80211_CMD_NAN_NDP_TERMINATE. * Secure NDPs additionally require %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_CAPA_FUNC_EXTRA_ATTRS: flag attribute. The device accepts + * %NL80211_NAN_FUNC_EXTRA_ATTRS for NAN functions when the NAN Discovery + * Engine is offloaded. This capability is not available when + * %NL80211_NAN_CAPA_USERSPACE_DE is set. * @__NL80211_NAN_CAPABILITIES_LAST: Internal * @NL80211_NAN_CAPABILITIES_MAX: Highest NAN capability attribute. */ @@ -9474,6 +9488,7 @@ enum nl80211_nan_capabilities { NL80211_NAN_CAPA_INSTANT_COMM, NL80211_NAN_CAPA_OFFLOAD_RANGING, NL80211_NAN_CAPA_OFFLOAD_NDP, + NL80211_NAN_CAPA_FUNC_EXTRA_ATTRS, /* keep last */ __NL80211_NAN_CAPABILITIES_LAST, NL80211_NAN_CAPABILITIES_MAX = __NL80211_NAN_CAPABILITIES_LAST - 1, diff --git a/net/wireless/core.c b/net/wireless/core.c index f4153c249599..0d8f9505116e 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -934,6 +934,10 @@ int wiphy_register(struct wiphy *wiphy) !rdev->ops->add_nan_func || !rdev->ops->del_nan_func || !(wiphy->nan_supported_bands & BIT(NL80211_BAND_2GHZ))))) return -EINVAL; + if (WARN_ON((wiphy->nan_capa.flags & + WIPHY_NAN_FLAGS_FUNC_EXTRA_ATTRS) && + (wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_USERSPACE_DE))) + return -EINVAL; if (WARN_ON((wiphy->interface_modes & BIT(NL80211_IFTYPE_NAN_DATA)) && (!wiphy->nan_capa.phy.ht.ht_supported || wiphy->n_radio > 1))) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 15c2294d4be6..e1dac3d912ff 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -460,6 +460,42 @@ static int validate_nan_pmk(const struct nlattr *attr, return 0; } +static int validate_nan_func_extra_attrs(const struct nlattr *attr, + struct netlink_ext_ack *extack) +{ + const u8 *data = nla_data(attr); + unsigned int len = nla_len(attr); + unsigned int pos = 0; + + if (!len) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "NAN function extra attributes must not be empty"); + return -EINVAL; + } + + while (pos < len) { + u16 attr_len; + + if (len - pos < 3) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "NAN function extra attribute has a truncated header"); + return -EINVAL; + } + + attr_len = get_unaligned_le16(data + pos + 1); + pos += 3; + if (attr_len > len - pos) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "NAN function extra attribute length exceeds remaining data"); + return -EINVAL; + } + + pos += attr_len; + } + + return 0; +} + static int validate_nan_avail_blob(const struct nlattr *attr, struct netlink_ext_ack *extack) { @@ -1418,6 +1454,10 @@ nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { NL80211_PREAMBLE_HE), [NL80211_NAN_FUNC_CHAN] = NLA_POLICY_NESTED(nl80211_policy), [NL80211_NAN_FUNC_RANGE_REPORT] = { .type = NLA_FLAG }, + [NL80211_NAN_FUNC_EXTRA_ATTRS] = + NLA_POLICY_VALIDATE_FN(NLA_BINARY, + validate_nan_func_extra_attrs, + IEEE80211_MAX_DATA_LEN), }; /* policy for Service Response Filter attributes */ @@ -3235,6 +3275,10 @@ static int nl80211_put_nan_capa(struct wiphy *wiphy, struct sk_buff *msg) nla_put_flag(msg, NL80211_NAN_CAPA_OFFLOAD_NDP)) goto fail; + if ((wiphy->nan_capa.flags & WIPHY_NAN_FLAGS_FUNC_EXTRA_ATTRS) && + nla_put_flag(msg, NL80211_NAN_CAPA_FUNC_EXTRA_ATTRS)) + goto fail; + if (nla_put_u8(msg, NL80211_NAN_CAPA_OP_MODE, wiphy->nan_capa.op_mode) || nla_put_u8(msg, NL80211_NAN_CAPA_NUM_ANTENNAS, @@ -17721,6 +17765,25 @@ static int nl80211_nan_add_func(struct sk_buff *skb, goto out; } + if (tb[NL80211_NAN_FUNC_EXTRA_ATTRS]) { + if (!(wdev->wiphy->nan_capa.flags & + WIPHY_NAN_FLAGS_FUNC_EXTRA_ATTRS)) { + NL_SET_ERR_MSG(info->extack, + "Extra NAN function attributes are not supported"); + err = -EOPNOTSUPP; + goto out; + } + + func->extra_attrs_len = nla_len(tb[NL80211_NAN_FUNC_EXTRA_ATTRS]); + func->extra_attrs = + kmemdup(nla_data(tb[NL80211_NAN_FUNC_EXTRA_ATTRS]), + func->extra_attrs_len, GFP_KERNEL); + if (!func->extra_attrs) { + err = -ENOMEM; + goto out; + } + } + func->data_path_required = nla_get_flag(tb[NL80211_NAN_FUNC_DATA_PATH_REQUIRED]); func->security_required = diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 9ea561402b6c..e893dbbe66fe 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -2448,16 +2448,19 @@ TRACE_EVENT(rdev_add_nan_func, WDEV_ENTRY __field(u8, func_type) __field(u64, cookie) + __field(u16, extra_attrs_len) ), TP_fast_assign( WIPHY_ASSIGN; WDEV_ASSIGN; __entry->func_type = func->type; - __entry->cookie = func->cookie + __entry->cookie = func->cookie; + __entry->extra_attrs_len = func->extra_attrs_len; ), - TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT ", type=%u, cookie=%llu", + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT + ", type=%u, cookie=%llu, extra_attrs_len=%u", WIPHY_PR_ARG, WDEV_PR_ARG, __entry->func_type, - __entry->cookie) + __entry->cookie, __entry->extra_attrs_len) ); TRACE_EVENT(rdev_del_nan_func, diff --git a/net/wireless/util.c b/net/wireless/util.c index 980b16c72d4f..4e1cbe50af1e 100644 --- a/net/wireless/util.c +++ b/net/wireless/util.c @@ -2876,6 +2876,7 @@ void cfg80211_free_nan_func(struct cfg80211_nan_func *f) return; kfree(f->serv_spec_info); + kfree(f->extra_attrs); kfree(f->srf_bf); kfree(f->srf_macs); kfree(f->csids); -- 2.34.1