Skip to contentSkip to conversation

marvell/mwifiex: replace one-element array with flexible-array member.

PATCH In review Jiapeng Zhong 2 participants 3 messages Jan 15, 2021 – Jan 19, 2021 Marvell mwifiex wireless driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 marvell/mwifiex: replace one-element array with flexible-array member.

Fix the follow coccicheck warnings:

./drivers/net/wireless/marvell/mwifiex/fw.h: WARNING use flexible-array member instead(https://www.kernel.org/doc/html/latest/process/ deprecated.html#zero-length-and-one-element-arrays)

---
 drivers/net/wireless/marvell/mwifiex/fw.h | 40 +++++++++++++++----------------
 1 file changed, 20 insertions(+), 20 deletions(-)
drivers/net/wireless/marvell/mwifiex/fw.h +20 -20
index 470d669..a9cb209 100644
@@ -53,7 +53,7 @@ struct mwifiex_fw_header {
 struct mwifiex_fw_data {
 	struct mwifiex_fw_header header;
 	__le32 seq_num;
-	u8 data[1];
+	u8 data[];
 } __packed;
 
 struct mwifiex_fw_dump_header {
@@ -653,7 +653,7 @@ struct mwifiex_ie_types_header {
 
 struct mwifiex_ie_types_data {
 	struct mwifiex_ie_types_header header;
-	u8 data[1];
+	u8 data[];
 } __packed;
 
 #define MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET 0x01
@@ -781,7 +781,7 @@ struct mwifiex_chan_scan_param_set {
 
 struct mwifiex_ie_types_chan_list_param_set {
 	struct mwifiex_ie_types_header header;
-	struct mwifiex_chan_scan_param_set chan_scan_param[1];
+	struct mwifiex_chan_scan_param_set chan_scan_param[];
 } __packed;
 
 struct mwifiex_ie_types_rxba_sync {
@@ -791,7 +791,7 @@ struct mwifiex_ie_types_rxba_sync {
 	u8 reserved;
 	__le16 seq_num;
 	__le16 bitmap_len;
-	u8 bitmap[1];
+	u8 bitmap[];
 } __packed;
 
 struct chan_band_param_set {
@@ -801,17 +801,17 @@ struct chan_band_param_set {
 
 struct mwifiex_ie_types_chan_band_list_param_set {
 	struct mwifiex_ie_types_header header;
-	struct chan_band_param_set chan_band_param[1];
+	struct chan_band_param_set chan_band_param[];
 } __packed;
 
 struct mwifiex_ie_types_rates_param_set {
 	struct mwifiex_ie_types_header header;
-	u8 rates[1];
+	u8 rates[];
 } __packed;
 
 struct mwifiex_ie_types_ssid_param_set {
 	struct mwifiex_ie_types_header header;
-	u8 ssid[1];
+	u8 ssid[];
 } __packed;
 
 struct mwifiex_ie_types_num_probes {
@@ -853,13 +853,13 @@ struct mwifiex_ietypes_chanstats {
 struct mwifiex_ie_types_wildcard_ssid_params {
 	struct mwifiex_ie_types_header header;
 	u8 max_ssid_length;
-	u8 ssid[1];
+	u8 ssid[];
 } __packed;
 
 #define TSF_DATA_SIZE            8
 struct mwifiex_ie_types_tsf_timestamp {
 	struct mwifiex_ie_types_header header;
-	u8 tsf_data[1];
+	u8 tsf_data[];
 } __packed;
 
 struct mwifiex_cf_param_set {
@@ -919,7 +919,7 @@ struct mwifiex_ie_types_tdls_idle_timeout {
 
 struct mwifiex_ie_types_rsn_param_set {
 	struct mwifiex_ie_types_header header;
-	u8 rsn_ie[1];
+	u8 rsn_ie[];
 } __packed;
 
 #define KEYPARAMSET_FIXED_LEN 6
@@ -1343,7 +1343,7 @@ struct host_cmd_ds_802_11_snmp_mib {
 	__le16 query_type;
 	__le16 oid;
 	__le16 buf_size;
-	u8 value[1];
+	u8 value[];
 } __packed;
 
 struct mwifiex_rate_scope {
@@ -1440,7 +1440,7 @@ struct mwifiex_tdls_stop_cs_params {
 
 struct host_cmd_ds_tdls_config {
 	__le16 tdls_action;
-	u8 tdls_data[1];
+	u8 tdls_data[];
 } __packed;
 
 struct mwifiex_chan_desc {
@@ -1511,7 +1511,7 @@ struct mwifiex_scan_cmd_config {
 	 *  TLV_TYPE_CHANLIST, mwifiex_ie_types_chan_list_param_set
 	 *  WLAN_EID_SSID, mwifiex_ie_types_ssid_param_set
 	 */
-	u8 tlv_buf[1];	/* SSID TLV(s) and ChanList TLVs are stored
+	u8 tlv_buf[];	/* SSID TLV(s) and ChanList TLVs are stored
 				   here */
 } __packed;
 
@@ -1581,18 +1581,18 @@ struct ie_body {
 struct host_cmd_ds_802_11_scan {
 	u8 bss_mode;
 	u8 bssid[ETH_ALEN];
-	u8 tlv_buffer[1];
+	u8 tlv_buffer[];
 } __packed;
 
 struct host_cmd_ds_802_11_scan_rsp {
 	__le16 bss_descript_size;
 	u8 number_of_sets;
-	u8 bss_desc_and_tlv_buffer[1];
+	u8 bss_desc_and_tlv_buffer[];
 } __packed;
 
 struct host_cmd_ds_802_11_scan_ext {
 	u32   reserved;
-	u8    tlv_buffer[1];
+	u8    tlv_buffer[];
 } __packed;
 
 struct mwifiex_ie_types_bss_mode {
@@ -1603,7 +1603,7 @@ struct mwifiex_ie_types_bss_mode {
 struct mwifiex_ie_types_bss_scan_rsp {
 	struct mwifiex_ie_types_header header;
 	u8 bssid[ETH_ALEN];
-	u8 frame_body[1];
+	u8 frame_body[];
 } __packed;
 
 struct mwifiex_ie_types_bss_scan_info {
@@ -1643,7 +1643,7 @@ struct host_cmd_ds_802_11_bg_scan_query_rsp {
 struct mwifiex_ietypes_domain_param_set {
 	struct mwifiex_ie_types_header header;
 	u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
-	struct ieee80211_country_ie_triplet triplet[1];
+	struct ieee80211_country_ie_triplet triplet[];
 } __packed;
 
 struct host_cmd_ds_802_11d_domain_info {
@@ -1740,7 +1740,7 @@ struct mwifiex_ie_types_local_pwr_constraint {
 
 struct mwifiex_ie_types_wmm_param_set {
 	struct mwifiex_ie_types_header header;
-	u8 wmm_ie[1];
+	u8 wmm_ie[];
 } __packed;
 
 struct mwifiex_ie_types_mgmt_frame {
@@ -1966,7 +1966,7 @@ struct host_cmd_tlv_wep_key {
 	struct mwifiex_ie_types_header header;
 	u8 key_index;
 	u8 is_default;
-	u8 key[1];
+	u8 key[];
 };
 
 struct host_cmd_tlv_auth_type {
Signature · 1 line
1.8.3.1
maintainer
#2 lore raw
In reply to Brian Norris

One more thing, for context:

Quoted 21 lines · Brian Norris
Quoted 9 lines · Jiapeng Zhong

Fix the follow coccicheck warnings:

./drivers/net/wireless/marvell/mwifiex/fw.h: WARNING use flexible-array member instead(https://www.kernel.org/doc/html/latest/process/ deprecated.html#zero-length-and-one-element-arrays)

Past experience unfortunately requires me to ask: did you test your changes? I understand that's a mostly legit warning, and a good deprecation notice, but that doesn't mean this is the right fix. One probably should instead audit the usage sites to see if they *are* already making proper sizeof (or other) comparisons, and if not, fix those first. And if any sites *are* doing correct sizeof computations using the existing struct layouts, then you are probably breaking them.

Quoted 3 lines

Or if you have audited the usage of these structs, it's nice to make a small explanation of why this is correct, so I (and other readers) don't have to ask these questions :)

FYI, there are others who I believe are making similar blind changes to this code:

[PATCH 1/1] mwifiex: Fix possible buffer overflows in mwifiex_config_scan
https://lore.kernel.org/linux-wireless/CA+ASDXPkLg2GGFJTt25YO7wae==YAHftf8JXu520pL_vZaT3ug@mail.gmail.com/

For that particular case (the 'ssid' field in mwifiex_ie_types_wildcard_ssid_params), the previous patch-er was incorrect, and I believe your change is a better one. But neither of you provided useful analysis.

Brian

maintainer
#1 lore raw
In reply to Jiapeng Zhong

Hi,

Quoted 9 lines · Jiapeng Zhong

Fix the follow coccicheck warnings:

./drivers/net/wireless/marvell/mwifiex/fw.h: WARNING use flexible-array member instead(https://www.kernel.org/doc/html/latest/process/ deprecated.html#zero-length-and-one-element-arrays)

Past experience unfortunately requires me to ask: did you test your changes? I understand that's a mostly legit warning, and a good deprecation notice, but that doesn't mean this is the right fix. One probably should instead audit the usage sites to see if they *are* already making proper sizeof (or other) comparisons, and if not, fix those first. And if any sites *are* doing correct sizeof computations using the existing struct layouts, then you are probably breaking them.

Or if you have audited the usage of these structs, it's nice to make a small explanation of why this is correct, so I (and other readers) don't have to ask these questions :)

Regards,
Brian