@@ -175,7 +175,8 @@ static void qtnf_cmd_tlv_ie_set_add(struct sk_buff *cmd_skb, u8 frame_type,
175175{
176176 struct qlink_tlv_ie_set * tlv ;
177177
178- tlv = (struct qlink_tlv_ie_set * )skb_put (cmd_skb , sizeof (* tlv ) + len );
178+ tlv = (struct qlink_tlv_ie_set * )skb_put (cmd_skb , sizeof (* tlv ) +
179+ round_up (len , QLINK_ALIGN ));
179180 tlv -> hdr .type = cpu_to_le16 (QTN_TLV_ID_IE_SET );
180181 tlv -> hdr .len = cpu_to_le16 (len + sizeof (* tlv ) - sizeof (tlv -> hdr ));
181182 tlv -> type = frame_type ;
@@ -190,20 +191,24 @@ static bool qtnf_cmd_start_ap_can_fit(const struct qtnf_vif *vif,
190191{
191192 unsigned int len = sizeof (struct qlink_cmd_start_ap );
192193
193- len += s -> ssid_len ;
194- len += s -> beacon .head_len ;
195- len += s -> beacon .tail_len ;
196- len += s -> beacon .beacon_ies_len ;
197- len += s -> beacon .proberesp_ies_len ;
198- len += s -> beacon .assocresp_ies_len ;
199- len += s -> beacon .probe_resp_len ;
194+ len += round_up ( s -> ssid_len , QLINK_ALIGN ) ;
195+ len += round_up ( s -> beacon .head_len , QLINK_ALIGN ) ;
196+ len += round_up ( s -> beacon .tail_len , QLINK_ALIGN ) ;
197+ len += round_up ( s -> beacon .beacon_ies_len , QLINK_ALIGN ) ;
198+ len += round_up ( s -> beacon .proberesp_ies_len , QLINK_ALIGN ) ;
199+ len += round_up ( s -> beacon .assocresp_ies_len , QLINK_ALIGN ) ;
200+ len += round_up ( s -> beacon .probe_resp_len , QLINK_ALIGN ) ;
200201
201202 if (cfg80211_chandef_valid (& s -> chandef ))
202203 len += sizeof (struct qlink_tlv_chandef );
203204
204- if (s -> acl )
205+ if (s -> acl ) {
206+ unsigned int acl_len = struct_size (s -> acl , mac_addrs ,
207+ s -> acl -> n_acl_entries );
208+
205209 len += sizeof (struct qlink_tlv_hdr ) +
206- struct_size (s -> acl , mac_addrs , s -> acl -> n_acl_entries );
210+ round_up (acl_len , QLINK_ALIGN );
211+ }
207212
208213 if (len > (sizeof (struct qlink_cmd ) + QTNF_MAX_CMD_BUF_SIZE )) {
209214 pr_err ("VIF%u.%u: can not fit AP settings: %u\n" ,
@@ -315,7 +320,8 @@ int qtnf_cmd_send_start_ap(struct qtnf_vif *vif,
315320
316321 if (s -> ht_cap ) {
317322 struct qlink_tlv_hdr * tlv = (struct qlink_tlv_hdr * )
318- skb_put (cmd_skb , sizeof (* tlv ) + sizeof (* s -> ht_cap ));
323+ skb_put (cmd_skb , sizeof (* tlv ) +
324+ round_up (sizeof (* s -> ht_cap ), QLINK_ALIGN ));
319325
320326 tlv -> type = cpu_to_le16 (WLAN_EID_HT_CAPABILITY );
321327 tlv -> len = cpu_to_le16 (sizeof (* s -> ht_cap ));
@@ -339,7 +345,8 @@ int qtnf_cmd_send_start_ap(struct qtnf_vif *vif,
339345 size_t acl_size = struct_size (s -> acl , mac_addrs ,
340346 s -> acl -> n_acl_entries );
341347 struct qlink_tlv_hdr * tlv =
342- skb_put (cmd_skb , sizeof (* tlv ) + acl_size );
348+ skb_put (cmd_skb ,
349+ sizeof (* tlv ) + round_up (acl_size , QLINK_ALIGN ));
343350
344351 tlv -> type = cpu_to_le16 (QTN_TLV_ID_ACL_DATA );
345352 tlv -> len = cpu_to_le16 (acl_size );
@@ -581,10 +588,10 @@ qtnf_sta_info_parse_flags(struct nl80211_sta_flag_update *dst,
581588}
582589
583590static void
584- qtnf_cmd_sta_info_parse (struct station_info * sinfo ,
585- const struct qlink_tlv_hdr * tlv ,
591+ qtnf_cmd_sta_info_parse (struct station_info * sinfo , const u8 * data ,
586592 size_t resp_size )
587593{
594+ const struct qlink_tlv_hdr * tlv ;
588595 const struct qlink_sta_stats * stats = NULL ;
589596 const u8 * map = NULL ;
590597 unsigned int map_len = 0 ;
@@ -595,7 +602,7 @@ qtnf_cmd_sta_info_parse(struct station_info *sinfo,
595602 (qtnf_utils_is_bit_set(map, bitn, map_len) && \
596603 (offsetofend(struct qlink_sta_stats, stat_name) <= stats_len))
597604
598- while ( resp_size >= sizeof ( * tlv ) ) {
605+ qlink_for_each_tlv ( tlv , data , resp_size ) {
599606 tlv_len = le16_to_cpu (tlv -> len );
600607
601608 switch (le16_to_cpu (tlv -> type )) {
@@ -610,9 +617,11 @@ qtnf_cmd_sta_info_parse(struct station_info *sinfo,
610617 default :
611618 break ;
612619 }
620+ }
613621
614- resp_size -= tlv_len + sizeof (* tlv );
615- tlv = (const struct qlink_tlv_hdr * )(tlv -> val + tlv_len );
622+ if (!qlink_tlv_parsing_ok (tlv , data , resp_size )) {
623+ pr_err ("Malformed TLV buffer\n" );
624+ return ;
616625 }
617626
618627 if (!map || !stats )
@@ -736,9 +745,7 @@ int qtnf_cmd_get_sta_info(struct qtnf_vif *vif, const u8 *sta_mac,
736745 goto out ;
737746 }
738747
739- qtnf_cmd_sta_info_parse (sinfo ,
740- (const struct qlink_tlv_hdr * )resp -> info ,
741- var_resp_len );
748+ qtnf_cmd_sta_info_parse (sinfo , resp -> info , var_resp_len );
742749
743750out :
744751 qtnf_bus_unlock (vif -> mac -> bus );
@@ -907,18 +914,10 @@ qtnf_cmd_resp_proc_hw_info(struct qtnf_bus *bus,
907914 plat_id = le32_to_cpu (resp -> plat_id );
908915 hw_ver = le32_to_cpu (resp -> hw_ver );
909916
910- tlv = (const struct qlink_tlv_hdr * )resp -> info ;
911-
912- while (info_len >= sizeof (* tlv )) {
917+ qlink_for_each_tlv (tlv , resp -> info , info_len ) {
913918 tlv_type = le16_to_cpu (tlv -> type );
914919 tlv_len = le16_to_cpu (tlv -> len );
915920
916- if (tlv_len + sizeof (* tlv ) > info_len ) {
917- pr_warn ("malformed TLV 0x%.2X; LEN: %u\n" ,
918- tlv_type , tlv_len );
919- return - EINVAL ;
920- }
921-
922921 switch (tlv_type ) {
923922 case QTN_TLV_ID_BUILD_NAME :
924923 bld_name = (const void * )tlv -> val ;
@@ -948,9 +947,11 @@ qtnf_cmd_resp_proc_hw_info(struct qtnf_bus *bus,
948947 default :
949948 break ;
950949 }
950+ }
951951
952- info_len -= tlv_len + sizeof (* tlv );
953- tlv = (struct qlink_tlv_hdr * )(tlv -> val + tlv_len );
952+ if (!qlink_tlv_parsing_ok (tlv , resp -> info , info_len )) {
953+ pr_err ("Malformed TLV buffer\n" );
954+ return - EINVAL ;
954955 }
955956
956957 pr_info ("\nBuild name: %s\n"
@@ -1019,7 +1020,6 @@ qtnf_parse_variable_mac_info(struct qtnf_wmac *mac,
10191020 const struct qlink_resp_get_mac_info * resp ,
10201021 size_t tlv_buf_size )
10211022{
1022- const u8 * tlv_buf = resp -> var_info ;
10231023 struct ieee80211_iface_combination * comb = mac -> macinfo .if_comb ;
10241024 size_t n_comb = 0 ;
10251025 struct ieee80211_iface_limit * limits ;
@@ -1029,7 +1029,6 @@ qtnf_parse_variable_mac_info(struct qtnf_wmac *mac,
10291029 u16 rec_len ;
10301030 u16 tlv_type ;
10311031 u16 tlv_value_len ;
1032- size_t tlv_full_len ;
10331032 const struct qlink_tlv_hdr * tlv ;
10341033 u8 * ext_capa = NULL ;
10351034 u8 * ext_capa_mask = NULL ;
@@ -1068,16 +1067,9 @@ qtnf_parse_variable_mac_info(struct qtnf_wmac *mac,
10681067 break ;
10691068 }
10701069
1071- tlv = (const struct qlink_tlv_hdr * )tlv_buf ;
1072- while (tlv_buf_size >= sizeof (struct qlink_tlv_hdr )) {
1070+ qlink_for_each_tlv (tlv , resp -> var_info , tlv_buf_size ) {
10731071 tlv_type = le16_to_cpu (tlv -> type );
10741072 tlv_value_len = le16_to_cpu (tlv -> len );
1075- tlv_full_len = tlv_value_len + sizeof (struct qlink_tlv_hdr );
1076- if (tlv_full_len > tlv_buf_size ) {
1077- pr_warn ("MAC%u: malformed TLV 0x%.2X; LEN: %u\n" ,
1078- mac -> macid , tlv_type , tlv_value_len );
1079- return - EINVAL ;
1080- }
10811073
10821074 switch (tlv_type ) {
10831075 case QTN_TLV_ID_IFACE_LIMIT :
@@ -1183,14 +1175,10 @@ qtnf_parse_variable_mac_info(struct qtnf_wmac *mac,
11831175 mac -> macid , tlv_type );
11841176 break ;
11851177 }
1186-
1187- tlv_buf_size -= tlv_full_len ;
1188- tlv = (struct qlink_tlv_hdr * )(tlv -> val + tlv_value_len );
11891178 }
11901179
1191- if (tlv_buf_size ) {
1192- pr_warn ("MAC%u: malformed TLV buf; bytes left: %zu\n" ,
1193- mac -> macid , tlv_buf_size );
1180+ if (!qlink_tlv_parsing_ok (tlv , resp -> var_info , tlv_buf_size )) {
1181+ pr_err ("Malformed TLV buffer\n" );
11941182 return - EINVAL ;
11951183 }
11961184
@@ -1383,7 +1371,6 @@ qtnf_cmd_resp_fill_band_info(struct ieee80211_supported_band *band,
13831371 size_t payload_len )
13841372{
13851373 u16 tlv_type ;
1386- size_t tlv_len ;
13871374 size_t tlv_dlen ;
13881375 const struct qlink_tlv_hdr * tlv ;
13891376 const struct qlink_channel * qchan ;
@@ -1418,24 +1405,15 @@ qtnf_cmd_resp_fill_band_info(struct ieee80211_supported_band *band,
14181405 return - ENOMEM ;
14191406 }
14201407
1421- tlv = (struct qlink_tlv_hdr * )resp -> info ;
1422-
1423- while (payload_len >= sizeof (* tlv )) {
1408+ qlink_for_each_tlv (tlv , resp -> info , payload_len ) {
14241409 tlv_type = le16_to_cpu (tlv -> type );
14251410 tlv_dlen = le16_to_cpu (tlv -> len );
1426- tlv_len = tlv_dlen + sizeof (* tlv );
1427-
1428- if (tlv_len > payload_len ) {
1429- pr_warn ("malformed TLV 0x%.2X; LEN: %zu\n" ,
1430- tlv_type , tlv_len );
1431- goto error_ret ;
1432- }
14331411
14341412 switch (tlv_type ) {
14351413 case QTN_TLV_ID_CHANNEL :
14361414 if (unlikely (tlv_dlen != sizeof (* qchan ))) {
14371415 pr_err ("invalid channel TLV len %zu\n" ,
1438- tlv_len );
1416+ tlv_dlen );
14391417 goto error_ret ;
14401418 }
14411419
@@ -1538,13 +1516,10 @@ qtnf_cmd_resp_fill_band_info(struct ieee80211_supported_band *band,
15381516 pr_warn ("unknown TLV type: %#x\n" , tlv_type );
15391517 break ;
15401518 }
1541-
1542- payload_len -= tlv_len ;
1543- tlv = (struct qlink_tlv_hdr * )(tlv -> val + tlv_dlen );
15441519 }
15451520
1546- if (payload_len ) {
1547- pr_err ("malformed TLV buf; bytes left: %zu \n" , payload_len );
1521+ if (! qlink_tlv_parsing_ok ( tlv , resp -> info , payload_len ) ) {
1522+ pr_err ("Malformed TLV buffer \n" );
15481523 goto error_ret ;
15491524 }
15501525
@@ -1689,16 +1664,16 @@ int qtnf_cmd_send_update_phy_params(struct qtnf_wmac *mac, u32 changed)
16891664 qtnf_cmd_skb_put_tlv_u32 (cmd_skb , QTN_TLV_ID_RTS_THRESH ,
16901665 wiphy -> rts_threshold );
16911666 if (changed & WIPHY_PARAM_COVERAGE_CLASS )
1692- qtnf_cmd_skb_put_tlv_u8 (cmd_skb , QTN_TLV_ID_COVERAGE_CLASS ,
1693- wiphy -> coverage_class );
1667+ qtnf_cmd_skb_put_tlv_u32 (cmd_skb , QTN_TLV_ID_COVERAGE_CLASS ,
1668+ wiphy -> coverage_class );
16941669
16951670 if (changed & WIPHY_PARAM_RETRY_LONG )
1696- qtnf_cmd_skb_put_tlv_u8 (cmd_skb , QTN_TLV_ID_LRETRY_LIMIT ,
1697- wiphy -> retry_long );
1671+ qtnf_cmd_skb_put_tlv_u32 (cmd_skb , QTN_TLV_ID_LRETRY_LIMIT ,
1672+ wiphy -> retry_long );
16981673
16991674 if (changed & WIPHY_PARAM_RETRY_SHORT )
1700- qtnf_cmd_skb_put_tlv_u8 (cmd_skb , QTN_TLV_ID_SRETRY_LIMIT ,
1701- wiphy -> retry_short );
1675+ qtnf_cmd_skb_put_tlv_u32 (cmd_skb , QTN_TLV_ID_SRETRY_LIMIT ,
1676+ wiphy -> retry_short );
17021677
17031678 ret = qtnf_cmd_send (mac -> bus , cmd_skb );
17041679 if (ret )
@@ -2054,13 +2029,13 @@ static void qtnf_cmd_scan_set_dwell(struct qtnf_wmac *mac,
20542029 scan_req -> duration_mandatory ? "mandatory" : "max" ,
20552030 dwell_active , dwell_passive , duration );
20562031
2057- qtnf_cmd_skb_put_tlv_u16 (cmd_skb ,
2032+ qtnf_cmd_skb_put_tlv_u32 (cmd_skb ,
20582033 QTN_TLV_ID_SCAN_DWELL_ACTIVE ,
20592034 dwell_active );
2060- qtnf_cmd_skb_put_tlv_u16 (cmd_skb ,
2035+ qtnf_cmd_skb_put_tlv_u32 (cmd_skb ,
20612036 QTN_TLV_ID_SCAN_DWELL_PASSIVE ,
20622037 dwell_passive );
2063- qtnf_cmd_skb_put_tlv_u16 (cmd_skb ,
2038+ qtnf_cmd_skb_put_tlv_u32 (cmd_skb ,
20642039 QTN_TLV_ID_SCAN_SAMPLE_DURATION ,
20652040 duration );
20662041}
@@ -2416,25 +2391,15 @@ qtnf_cmd_resp_proc_chan_stat_info(struct survey_info *survey,
24162391{
24172392 const struct qlink_chan_stats * stats = NULL ;
24182393 const struct qlink_tlv_hdr * tlv ;
2419- size_t tlv_full_len ;
24202394 u16 tlv_value_len ;
24212395 u16 tlv_type ;
24222396 const u8 * map = NULL ;
24232397 unsigned int map_len = 0 ;
24242398 unsigned int stats_len = 0 ;
24252399
2426- tlv = (struct qlink_tlv_hdr * )payload ;
2427-
2428- while (payload_len >= sizeof (* tlv )) {
2400+ qlink_for_each_tlv (tlv , payload , payload_len ) {
24292401 tlv_type = le16_to_cpu (tlv -> type );
24302402 tlv_value_len = le16_to_cpu (tlv -> len );
2431- tlv_full_len = tlv_value_len + sizeof (* tlv );
2432-
2433- if (tlv_full_len > payload_len ) {
2434- pr_warn ("malformed TLV 0x%.2X; LEN: %u\n" ,
2435- tlv_type , tlv_value_len );
2436- return - ENOSPC ;
2437- }
24382403
24392404 switch (tlv_type ) {
24402405 case QTN_TLV_ID_BITMAP :
@@ -2449,13 +2414,10 @@ qtnf_cmd_resp_proc_chan_stat_info(struct survey_info *survey,
24492414 pr_info ("Unknown TLV type: %#x\n" , tlv_type );
24502415 break ;
24512416 }
2452-
2453- payload_len -= tlv_full_len ;
2454- tlv = (struct qlink_tlv_hdr * )(tlv -> val + tlv_value_len );
24552417 }
24562418
2457- if (payload_len ) {
2458- pr_warn ( "malformed TLV buf; bytes left: %zu \n", payload_len );
2419+ if (! qlink_tlv_parsing_ok ( tlv , payload , payload_len ) ) {
2420+ pr_err ( "Malformed TLV buffer \n" );
24592421 return - EINVAL ;
24602422 }
24612423
@@ -2657,7 +2619,7 @@ int qtnf_cmd_set_mac_acl(const struct qtnf_vif *vif,
26572619 if (!cmd_skb )
26582620 return - ENOMEM ;
26592621
2660- tlv = skb_put (cmd_skb , sizeof (* tlv ) + acl_size );
2622+ tlv = skb_put (cmd_skb , sizeof (* tlv ) + round_up ( acl_size , QLINK_ALIGN ) );
26612623 tlv -> type = cpu_to_le16 (QTN_TLV_ID_ACL_DATA );
26622624 tlv -> len = cpu_to_le16 (acl_size );
26632625 qlink_acl_data_cfg2q (params , (struct qlink_acl_data * )tlv -> val );
0 commit comments