ath6kl: wmi: Replace one-element arrays with flexible-array members
Subsystems (3)
v2 cover ath6kl: wmi: Replace one-element arrays with flexible-array members
This series aims to replace one-element arrays with flexible-array members in multiple structures in drivers/net/wireless/ath/ath6kl/wmi.h
There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].
This helps with the ongoing efforts to globally enable -Warray-bounds and get us closer to being able to tighten the FORTIFY_SOURCE routines on memcpy().
These issues were found with the help of Coccinelle and audited and fixed, manually.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays
Changes in v2:
- Revert changes in if-statement logic for all the affected patches:
if (len < sizeof(struct foo))
- Update changelog texts.
- Add Reviewed-by: Jeff Johnson <[email protected]> tag.
Gustavo A. R. Silva (6):
ath6kl: wmi: Replace one-element array with flexible-array member in
struct wmi_begin_scan_cmd
ath6kl: wmi: Replace one-element array with flexible-array member in
struct wmi_start_scan_cmd
ath6kl: wmi: Replace one-element array with flexible-array member in
struct wmi_channel_list_reply
ath6kl: wmi: Replace one-element array with flexible-array member in
struct wmi_connect_event
ath6kl: wmi: Replace one-element array with flexible-array member in
struct wmi_disconnect_event
ath6kl: wmi: Replace one-element array with flexible-array member in
struct wmi_aplist_event
drivers/net/wireless/ath/ath6kl/wmi.c | 22 ++++------------------ drivers/net/wireless/ath/ath6kl/wmi.h | 12 ++++++------ 2 files changed, 10 insertions(+), 24 deletions(-)
Signature · 1 line
2.27.0
PATCH v2 1/6 ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_begin_scan_cmd
Replace one-element array with flexible-array member in struct wmi_begin_scan_cmd. Also, make use of the struct_size() helper.
This issue was found with the help of Coccinelle and audited and fixed, manually.
---
Changes in v2:
- Add Reviewed-by: Jeff Johnson <[email protected]> tag.
drivers/net/wireless/ath/ath6kl/wmi.c | 9 ++------- drivers/net/wireless/ath/ath6kl/wmi.h | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-)
drivers/net/wireless/ath/ath6kl/wmi.c +2 -7
@@ -2008,7 +2008,7 @@ int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,struct ieee80211_supported_band *sband;struct sk_buff *skb;struct wmi_begin_scan_cmd *sc; -s8 size, *supp_rates; +s8 *supp_rates;int i, band, ret;struct ath6kl *ar = wmi->parent_dev;int num_rates;
@@ -2023,18 +2023,13 @@ int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx, num_chan, ch_list); } - size =sizeof (struct wmi_begin_scan_cmd ); -if ((scan_type !=WMI_LONG_SCAN ) && (scan_type !=WMI_SHORT_SCAN ))return -EINVAL ;if (num_chan >WMI_MAX_CHANNELS )return -EINVAL ; -if (num_chan) - size +=sizeof (u16) * (num_chan -1 ); - - skb =ath6kl_wmi_get_new_buf (size); + skb =ath6kl_wmi_get_new_buf (struct_size (sc, ch_list, num_chan));if (!skb)return -ENOMEM ;
drivers/net/wireless/ath/ath6kl/wmi.h +1 -1
@@ -863,7 +863,7 @@ struct wmi_begin_scan_cmd {u8 num_ch;/* channels in Mhz */ -__le16 ch_list[1 ]; +__le16 ch_list[]; } __packed;/* wmi_start_scan_cmd is to be deprecated. Use
Signature · 1 line
2.27.0
Re: [PATCH v2 1/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_begin_scan_cmd
Quoted 11 lines · Gustavo A. R. Silva
Replace one-element array with flexible-array member in struct
wmi_begin_scan_cmd. Also, make use of thestruct_size()helper.This issue was found with the help of Coccinelle and audited and fixed, manually.
6 patches applied to ath-next branch of ath.git, thanks.
324edddf2505 ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_begin_scan_cmd 56f1257fdcc0 ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_start_scan_cmd 3c5e6994eea3 ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_channel_list_reply dfb0203939b1 ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_connect_event 5140df50e655 ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_disconnect_event 0dff6f05a9dc ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_aplist_event
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/1ef801ea24475501fa0f296cb5435a440135206e.1645736204.git.gustavoars@kernel.org/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
PATCH v2 2/6 ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_start_scan_cmd
In reply to Gustavo A. R. SilvaReplace one-element array with flexible-array member in struct wmi_start_scan_cmd. Also, make use of the struct_size() helper.
This issue was found with the help of Coccinelle and audited and fixed, manually.
---
Changes in v2:
- None.
drivers/net/wireless/ath/ath6kl/wmi.c | 8 +------- drivers/net/wireless/ath/ath6kl/wmi.h | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/net/wireless/ath/ath6kl/wmi.c +1 -7
@@ -1959,21 +1959,15 @@ static int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx, {struct sk_buff *skb;struct wmi_start_scan_cmd *sc; -s8 size;int i, ret; - size =sizeof (struct wmi_start_scan_cmd ); -if ((scan_type !=WMI_LONG_SCAN ) && (scan_type !=WMI_SHORT_SCAN ))return -EINVAL ;if (num_chan >WMI_MAX_CHANNELS )return -EINVAL ; -if (num_chan) - size +=sizeof (u16) * (num_chan -1 ); - - skb =ath6kl_wmi_get_new_buf (size); + skb =ath6kl_wmi_get_new_buf (struct_size (sc, ch_list, num_chan));if (!skb)return -ENOMEM ;
drivers/net/wireless/ath/ath6kl/wmi.h +1 -1
@@ -889,7 +889,7 @@ struct wmi_start_scan_cmd {u8 num_ch;/* channels in Mhz */ -__le16 ch_list[1 ]; +__le16 ch_list[]; } __packed;/*
Signature · 1 line
2.27.0
Re: [PATCH v2 2/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_start_scan_cmd
Quoted 49 lines · Gustavo A. R. Silva
Replace one-element array with flexible-array member in struct
wmi_start_scan_cmd. Also, make use of thestruct_size()helper.This issue was found with the help of Coccinelle and audited and fixed, manually.
Link https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arraysSigned-off-by Gustavo A. R. Silva <[email protected]>---
Changes in v2:
- None.drivers/net/wireless/ath/ath6kl/wmi.c | 8 +------- drivers/net/wireless/ath/ath6kl/wmi.h | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-)drivers/net/wireless/ath/ath6kl/wmi.c +1
-7@@ -1959,21 +1959,15 @@ static int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx, {struct sk_buff *skb;struct wmi_start_scan_cmd *sc; -s8 size;int i, ret; - size =sizeof (struct wmi_start_scan_cmd ); -if ((scan_type !=WMI_LONG_SCAN ) && (scan_type !=WMI_SHORT_SCAN ))return -EINVAL ;if (num_chan >WMI_MAX_CHANNELS )return -EINVAL ; -if (num_chan) - size +=sizeof (u16) * (num_chan -1 ); - - skb =ath6kl_wmi_get_new_buf (size); + skb =ath6kl_wmi_get_new_buf (struct_size (sc, ch_list, num_chan));if (!skb)return -ENOMEM ;drivers/net/wireless/ath/ath6kl/wmi.h +0
-0
drivers/net/wireless/ath/ath6kl/wmi.h struct wmi_start_scan_cmd { · line 895
Quoted 8 lines
drivers/net/wireless/ath/ath6kl/wmi.h +1
-1@@ -889,7 +889,7 @@ struct wmi_start_scan_cmd {u8 num_ch;/* channels in Mhz */ -__le16 ch_list[1 ]; +__le16 ch_list[]; } __packed;/*
my e-mail client hung while reviewing v1, so now giving
Re: [PATCH v2 2/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_start_scan_cmd
On Thu, Feb 24, 2022 at 03:35:07PM -0800, Jeff Johnson wrote:
[..]
Quoted 4 lines
my e-mail client hung while reviewing v1, so now giving
Reviewed-by Jeff Johnson <[email protected]>
Thanks, Jeff.
--
Gustavo
PATCH v2 3/6 ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_channel_list_reply
In reply to Gustavo A. R. SilvaReplace one-element array with flexible-array member in struct wmi_channel_list_reply.
This issue was found with the help of Coccinelle and audited and fixed, manually.
---
Changes in v2:
- Revert changes in if-statement logic:
if (len < sizeof(struct wmi_channel_list_reply))
- Update changelog text.
- Add Reviewed-by: Jeff Johnson <[email protected]> tag.
drivers/net/wireless/ath/ath6kl/wmi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath6kl/wmi.h +1 -1
@@ -1373,7 +1373,7 @@ struct wmi_channel_list_reply {u8 num_ch;/* channel in Mhz */ -__le16 ch_list[1 ]; +__le16 ch_list[]; } __packed;/* List of Events (target to host) */
Signature · 1 line
2.27.0
PATCH v2 4/6 ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_connect_event
In reply to Gustavo A. R. SilvaReplace one-element array with flexible-array member in struct wmi_connect_event.
This issue was found with the help of Coccinelle and audited and fixed, manually.
---
Changes in v2:
- Revert changes in if-statement logic:
if (len < sizeof(struct wmi_connect_event))
- Update changelog text.
- Add Reviewed-by: Jeff Johnson <[email protected]> tag.
drivers/net/wireless/ath/ath6kl/wmi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath6kl/wmi.h +1 -1
@@ -1545,7 +1545,7 @@ struct wmi_connect_event {u8 beacon_ie_len;u8 assoc_req_len;u8 assoc_resp_len; -u8 assoc_info[1 ]; +u8 assoc_info[]; } __packed;/* Disconnect Event */
Signature · 1 line
2.27.0
PATCH v2 5/6 ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_disconnect_event
In reply to Gustavo A. R. SilvaReplace one-element array with flexible-array member in struct wmi_disconnect_event.
This issue was found with the help of Coccinelle and audited and fixed, manually.
---
Changes in v2:
- Revert changes in if-statement logic:
if (len < sizeof(struct wmi_disconnect_event))
- Update changelog text.
- Add Reviewed-by: Jeff Johnson <[email protected]> tag.
drivers/net/wireless/ath/ath6kl/wmi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath6kl/wmi.h +1 -1
@@ -1596,7 +1596,7 @@ struct wmi_disconnect_event {u8 disconn_reason;u8 assoc_resp_len; -u8 assoc_info[1 ]; +u8 assoc_info[]; } __packed;/*
Signature · 1 line
2.27.0
PATCH v2 6/6 ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_aplist_event
In reply to Gustavo A. R. SilvaReplace one-element array with flexible-array member in struct wmi_aplist_event.
Also, make use of the struct_size() helper and remove unneeded variable ap_info_entry_size.
This issue was found with the help of Coccinelle and audited and fixed, manually.
---
Changes in v2:
- Revert changes in if-statement logic:
if (len < sizeof(struct wmi_aplist_event))
- Update changelog text.
- Add Reviewed-by: Jeff Johnson <[email protected]> tag.
drivers/net/wireless/ath/ath6kl/wmi.c | 5 +---- drivers/net/wireless/ath/ath6kl/wmi.h | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-)
drivers/net/wireless/ath/ath6kl/wmi.c +1 -4
@@ -1750,7 +1750,6 @@ static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,static int ath6kl_wmi_aplist_event_rx (struct wmi *wmi,u8 *datap,int len) { -u16 ap_info_entry_size;struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;struct wmi_ap_info_v1 *ap_info_v1;u8 index;
@@ -1759,14 +1758,12 @@ static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len) ev->ap_list_ver != APLIST_VER1)return -EINVAL ; - ap_info_entry_size =sizeof (struct wmi_ap_info_v1 ); ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;ath6kl_dbg (ATH6KL_DBG_WMI ,"number of APs in aplist event: %d\n" , ev->num_ap); -if (len < (int ) (sizeof (struct wmi_aplist_event ) + - (ev->num_ap -1 ) * ap_info_entry_size)) +if (len <struct_size (ev, ap_list, ev->num_ap))return -EINVAL ;/* AP list version 1 contents */
drivers/net/wireless/ath/ath6kl/wmi.h +1 -1
@@ -1957,7 +1957,7 @@ union wmi_ap_info {struct wmi_aplist_event {u8 ap_list_ver;u8 num_ap; -union wmi_ap_info ap_list[1 ]; +union wmi_ap_info ap_list[]; } __packed;/* Developer Commands */
Signature · 1 line
2.27.0