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. Accept only the NAN Identity Resolution attribute and Vendor Specific attributes. The device builds all other attributes of these frames from the function and NAN configuration, so restricting the list keeps user space from adding duplicate or conflicting attributes and makes the accepted content explicit. Add the two attribute IDs to ieee80211-nan.h. Validate the attribute framing and types, 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/linux/ieee80211-nan.h | 2 + include/net/cfg80211.h | 12 ++++++ include/uapi/linux/nl80211.h | 13 +++++++ net/wireless/core.c | 4 ++ net/wireless/nl80211.c | 73 +++++++++++++++++++++++++++++++++++ net/wireless/trace.h | 9 +++-- net/wireless/util.c | 1 + 7 files changed, 111 insertions(+), 3 deletions(-) diff --git a/include/linux/ieee80211-nan.h b/include/linux/ieee80211-nan.h index 7815a6cf8160..b338f34833a1 100644 --- a/include/linux/ieee80211-nan.h +++ b/include/linux/ieee80211-nan.h @@ -42,6 +42,8 @@ #define NAN_ATTR_CLUSTER_INFO 0x01 #define NAN_ATTR_SERVICE_ID_LIST 0x02 #define NAN_ATTR_SUBSCRIBE_SERVICE_ID_LIST 0x28 +#define NAN_ATTR_NAN_IDENTITY_RESOLUTION 0x2b +#define NAN_ATTR_VENDOR_SPECIFIC 0xdd struct ieee80211_nan_attr { u8 attr; diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 15ed85a32cb7..b539266d0256 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4691,6 +4691,13 @@ 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. cfg80211 accepts only the NAN + * Identity Resolution attribute, used for pairing verification in Publish + * and Subscribe messages, and Vendor Specific attributes. The driver + * appends them unmodified and 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; @@ -4734,6 +4741,8 @@ struct cfg80211_nan_func { bool chandef_valid; struct cfg80211_chan_def chandef; bool range_report; + const u8 *extra_attrs; + u16 extra_attrs_len; }; /** @@ -6783,6 +6792,8 @@ struct wiphy_radio { * and termination with 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. */ enum wiphy_nan_flags { WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC = BIT(0), @@ -6790,6 +6801,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 ce40f018faf8..e0d81820204c 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -7972,6 +7972,14 @@ 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. Only the NAN Identity + * Resolution attribute, used for pairing verification in Publish and + * Subscribe messages, and Vendor Specific attributes are accepted; any + * other attribute is rejected. The device appends the attributes + * unmodified. Requires %NL80211_NAN_CAPA_FUNC_EXTRA_ATTRS. * * @NUM_NL80211_NAN_FUNC_ATTR: internal * @NL80211_NAN_FUNC_ATTR_MAX: highest NAN function attribute @@ -8008,6 +8016,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, @@ -9559,6 +9568,9 @@ enum nl80211_s1g_short_beacon_attrs { * %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. * @__NL80211_NAN_CAPABILITIES_LAST: Internal * @NL80211_NAN_CAPABILITIES_MAX: Highest NAN capability attribute. */ @@ -9575,6 +9587,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 96cd601cf0e0..555e8029c424 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 b98847413a2f..537bd6cb934f 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -479,6 +479,51 @@ 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; + u8 attr_id; + + if (len - pos < 3) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "NAN function extra attribute has a truncated header"); + return -EINVAL; + } + + attr_id = data[pos]; + if (attr_id != NAN_ATTR_NAN_IDENTITY_RESOLUTION && + attr_id != NAN_ATTR_VENDOR_SPECIFIC) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "NAN function extra attribute type is not allowed"); + 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) { @@ -1437,6 +1482,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 */ @@ -3259,6 +3308,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, @@ -17719,6 +17772,26 @@ 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 3d803948962e..a1e6af3d77ba 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_nan_update_publish, diff --git a/net/wireless/util.c b/net/wireless/util.c index d9d35f465785..64f4d39c54dc 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