linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/6][next] ath6kl: wmi: Replace one-element arrays with flexible-array members
@ 2022-02-24 21:15 Gustavo A. R. Silva
  2022-02-24 21:15 ` [PATCH v2 1/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_begin_scan_cmd Gustavo A. R. Silva
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2022-02-24 21:15 UTC (permalink / raw)
  To: linux-wireless, linux-kernel, Jeff Johnson
  Cc: Kalle Valo, David S. Miller, Jakub Kicinski, netdev,
	linux-hardening, Gustavo A. R. Silva

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

Link: https://github.com/KSPP/linux/issues/79

Changes in v2:
 - Revert changes in if-statement logic for all the affected patches:
	if (len < sizeof(struct foo))
   Link: https://lore.kernel.org/linux-hardening/3abb0846-a26f-3d76-8936-cd23cf4387f1@quicinc.com/ 
 - Update changelog texts.
 - Add Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com> 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(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_begin_scan_cmd
  2022-02-24 21:15 [PATCH v2 0/6][next] ath6kl: wmi: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
@ 2022-02-24 21:15 ` Gustavo A. R. Silva
  2022-03-09 15:08   ` Kalle Valo
  2022-02-24 21:16 ` [PATCH v2 2/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_start_scan_cmd Gustavo A. R. Silva
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Gustavo A. R. Silva @ 2022-02-24 21:15 UTC (permalink / raw)
  To: linux-wireless, linux-kernel, Jeff Johnson
  Cc: Kalle Valo, David S. Miller, Jakub Kicinski, netdev,
	linux-hardening, Gustavo A. R. Silva

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.

Link: https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays
Link: https://github.com/KSPP/linux/issues/79
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
Changes in v2:
 - Add Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com> tag.

 drivers/net/wireless/ath/ath6kl/wmi.c | 9 ++-------
 drivers/net/wireless/ath/ath6kl/wmi.h | 2 +-
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/ath/ath6kl/wmi.c b/drivers/net/wireless/ath/ath6kl/wmi.c
index bd1ef6334997..e1c950014f3e 100644
--- a/drivers/net/wireless/ath/ath6kl/wmi.c
+++ b/drivers/net/wireless/ath/ath6kl/wmi.c
@@ -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;
 
diff --git a/drivers/net/wireless/ath/ath6kl/wmi.h b/drivers/net/wireless/ath/ath6kl/wmi.h
index 784940ba4c90..322539ed9c12 100644
--- a/drivers/net/wireless/ath/ath6kl/wmi.h
+++ b/drivers/net/wireless/ath/ath6kl/wmi.h
@@ -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
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_start_scan_cmd
  2022-02-24 21:15 [PATCH v2 0/6][next] ath6kl: wmi: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
  2022-02-24 21:15 ` [PATCH v2 1/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_begin_scan_cmd Gustavo A. R. Silva
@ 2022-02-24 21:16 ` Gustavo A. R. Silva
  2022-02-24 23:35   ` Jeff Johnson
  2022-02-24 21:16 ` [PATCH v2 3/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_channel_list_reply Gustavo A. R. Silva
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Gustavo A. R. Silva @ 2022-02-24 21:16 UTC (permalink / raw)
  To: linux-wireless, linux-kernel, Jeff Johnson
  Cc: Kalle Valo, David S. Miller, Jakub Kicinski, netdev,
	linux-hardening, Gustavo A. R. Silva

Replace 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.

Link: https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays
Link: https://github.com/KSPP/linux/issues/79
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
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(-)

diff --git a/drivers/net/wireless/ath/ath6kl/wmi.c b/drivers/net/wireless/ath/ath6kl/wmi.c
index e1c950014f3e..bdfc057c5a82 100644
--- a/drivers/net/wireless/ath/ath6kl/wmi.c
+++ b/drivers/net/wireless/ath/ath6kl/wmi.c
@@ -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;
 
diff --git a/drivers/net/wireless/ath/ath6kl/wmi.h b/drivers/net/wireless/ath/ath6kl/wmi.h
index 322539ed9c12..9e168752bec2 100644
--- a/drivers/net/wireless/ath/ath6kl/wmi.h
+++ b/drivers/net/wireless/ath/ath6kl/wmi.h
@@ -889,7 +889,7 @@ struct wmi_start_scan_cmd {
 	u8 num_ch;
 
 	/* channels in Mhz */
-	__le16 ch_list[1];
+	__le16 ch_list[];
 } __packed;
 
 /*
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 3/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_channel_list_reply
  2022-02-24 21:15 [PATCH v2 0/6][next] ath6kl: wmi: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
  2022-02-24 21:15 ` [PATCH v2 1/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_begin_scan_cmd Gustavo A. R. Silva
  2022-02-24 21:16 ` [PATCH v2 2/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_start_scan_cmd Gustavo A. R. Silva
@ 2022-02-24 21:16 ` Gustavo A. R. Silva
  2022-02-24 21:17 ` [PATCH v2 4/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_connect_event Gustavo A. R. Silva
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2022-02-24 21:16 UTC (permalink / raw)
  To: linux-wireless, linux-kernel, Jeff Johnson
  Cc: Kalle Valo, David S. Miller, Jakub Kicinski, netdev,
	linux-hardening, Gustavo A. R. Silva

Replace 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.

Link: https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays
Link: https://github.com/KSPP/linux/issues/79
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
Changes in v2:
 - Revert changes in if-statement logic:
	if (len < sizeof(struct wmi_channel_list_reply))
   Link: https://lore.kernel.org/linux-hardening/3abb0846-a26f-3d76-8936-cd23cf4387f1@quicinc.com/
 - Update changelog text.
 - Add Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com> tag.

 drivers/net/wireless/ath/ath6kl/wmi.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath6kl/wmi.h b/drivers/net/wireless/ath/ath6kl/wmi.h
index 9e168752bec2..432e4f428a4a 100644
--- a/drivers/net/wireless/ath/ath6kl/wmi.h
+++ b/drivers/net/wireless/ath/ath6kl/wmi.h
@@ -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) */
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 4/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_connect_event
  2022-02-24 21:15 [PATCH v2 0/6][next] ath6kl: wmi: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
                   ` (2 preceding siblings ...)
  2022-02-24 21:16 ` [PATCH v2 3/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_channel_list_reply Gustavo A. R. Silva
@ 2022-02-24 21:17 ` Gustavo A. R. Silva
  2022-02-24 21:17 ` [PATCH v2 5/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_disconnect_event Gustavo A. R. Silva
  2022-02-24 21:17 ` [PATCH v2 6/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_aplist_event Gustavo A. R. Silva
  5 siblings, 0 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2022-02-24 21:17 UTC (permalink / raw)
  To: linux-wireless, linux-kernel, Jeff Johnson
  Cc: Kalle Valo, David S. Miller, Jakub Kicinski, netdev,
	linux-hardening, Gustavo A. R. Silva

Replace 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.

Link: https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays
Link: https://github.com/KSPP/linux/issues/79
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
Changes in v2:
 - Revert changes in if-statement logic:
        if (len < sizeof(struct wmi_connect_event))
   Link: https://lore.kernel.org/linux-hardening/6106494b-a1b3-6b57-8b44-b9528127533b@quicinc.com/
 - Update changelog text.
 - Add Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com> tag.

 drivers/net/wireless/ath/ath6kl/wmi.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath6kl/wmi.h b/drivers/net/wireless/ath/ath6kl/wmi.h
index 432e4f428a4a..6b064e669d87 100644
--- a/drivers/net/wireless/ath/ath6kl/wmi.h
+++ b/drivers/net/wireless/ath/ath6kl/wmi.h
@@ -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 */
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 5/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_disconnect_event
  2022-02-24 21:15 [PATCH v2 0/6][next] ath6kl: wmi: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
                   ` (3 preceding siblings ...)
  2022-02-24 21:17 ` [PATCH v2 4/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_connect_event Gustavo A. R. Silva
@ 2022-02-24 21:17 ` Gustavo A. R. Silva
  2022-02-24 21:17 ` [PATCH v2 6/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_aplist_event Gustavo A. R. Silva
  5 siblings, 0 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2022-02-24 21:17 UTC (permalink / raw)
  To: linux-wireless, linux-kernel, Jeff Johnson
  Cc: Kalle Valo, David S. Miller, Jakub Kicinski, netdev,
	linux-hardening, Gustavo A. R. Silva

Replace 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.

Link: https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays
Link: https://github.com/KSPP/linux/issues/79
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
Changes in v2:
 - Revert changes in if-statement logic:
        if (len < sizeof(struct wmi_disconnect_event))
   Link: https://lore.kernel.org/linux-hardening/03cee2a7-1455-b788-e1f0-5fb48db3478c@quicinc.com/
 - Update changelog text.
 - Add Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com> tag.

 drivers/net/wireless/ath/ath6kl/wmi.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath6kl/wmi.h b/drivers/net/wireless/ath/ath6kl/wmi.h
index 6b064e669d87..6a7fc07cd9aa 100644
--- a/drivers/net/wireless/ath/ath6kl/wmi.h
+++ b/drivers/net/wireless/ath/ath6kl/wmi.h
@@ -1596,7 +1596,7 @@ struct wmi_disconnect_event {
 	u8 disconn_reason;
 
 	u8 assoc_resp_len;
-	u8 assoc_info[1];
+	u8 assoc_info[];
 } __packed;
 
 /*
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 6/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_aplist_event
  2022-02-24 21:15 [PATCH v2 0/6][next] ath6kl: wmi: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
                   ` (4 preceding siblings ...)
  2022-02-24 21:17 ` [PATCH v2 5/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_disconnect_event Gustavo A. R. Silva
@ 2022-02-24 21:17 ` Gustavo A. R. Silva
  5 siblings, 0 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2022-02-24 21:17 UTC (permalink / raw)
  To: linux-wireless, linux-kernel, Jeff Johnson
  Cc: Kalle Valo, David S. Miller, Jakub Kicinski, netdev,
	linux-hardening, Gustavo A. R. Silva

Replace 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.

Link: https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays
Link: https://github.com/KSPP/linux/issues/79
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
Changes in v2:
 - Revert changes in if-statement logic:
        if (len < sizeof(struct wmi_aplist_event))
   Link: https://lore.kernel.org/linux-hardening/3f408c80-cabf-5ba2-2014-2eb0550b73f9@quicinc.com/
 - Update changelog text.
 - Add Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com> tag.

 drivers/net/wireless/ath/ath6kl/wmi.c | 5 +----
 drivers/net/wireless/ath/ath6kl/wmi.h | 2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/ath/ath6kl/wmi.c b/drivers/net/wireless/ath/ath6kl/wmi.c
index bdfc057c5a82..3787b9fb0075 100644
--- a/drivers/net/wireless/ath/ath6kl/wmi.c
+++ b/drivers/net/wireless/ath/ath6kl/wmi.c
@@ -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 */
diff --git a/drivers/net/wireless/ath/ath6kl/wmi.h b/drivers/net/wireless/ath/ath6kl/wmi.h
index 6a7fc07cd9aa..a9732660192a 100644
--- a/drivers/net/wireless/ath/ath6kl/wmi.h
+++ b/drivers/net/wireless/ath/ath6kl/wmi.h
@@ -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 */
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_start_scan_cmd
  2022-02-24 21:16 ` [PATCH v2 2/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_start_scan_cmd Gustavo A. R. Silva
@ 2022-02-24 23:35   ` Jeff Johnson
  2022-02-24 23:58     ` Gustavo A. R. Silva
  0 siblings, 1 reply; 10+ messages in thread
From: Jeff Johnson @ 2022-02-24 23:35 UTC (permalink / raw)
  To: Gustavo A. R. Silva, linux-wireless, linux-kernel
  Cc: Kalle Valo, David S. Miller, Jakub Kicinski, netdev, linux-hardening

On 2/24/2022 1:16 PM, Gustavo A. R. Silva wrote:
> Replace 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.
> 
> Link: https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays
> Link: https://github.com/KSPP/linux/issues/79
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> 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(-)
> 
> diff --git a/drivers/net/wireless/ath/ath6kl/wmi.c b/drivers/net/wireless/ath/ath6kl/wmi.c
> index e1c950014f3e..bdfc057c5a82 100644
> --- a/drivers/net/wireless/ath/ath6kl/wmi.c
> +++ b/drivers/net/wireless/ath/ath6kl/wmi.c
> @@ -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;
>   
> diff --git a/drivers/net/wireless/ath/ath6kl/wmi.h b/drivers/net/wireless/ath/ath6kl/wmi.h
> index 322539ed9c12..9e168752bec2 100644
> --- a/drivers/net/wireless/ath/ath6kl/wmi.h
> +++ b/drivers/net/wireless/ath/ath6kl/wmi.h
> @@ -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

Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_start_scan_cmd
  2022-02-24 23:35   ` Jeff Johnson
@ 2022-02-24 23:58     ` Gustavo A. R. Silva
  0 siblings, 0 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2022-02-24 23:58 UTC (permalink / raw)
  To: Jeff Johnson
  Cc: linux-wireless, linux-kernel, Kalle Valo, David S. Miller,
	Jakub Kicinski, netdev, linux-hardening

On Thu, Feb 24, 2022 at 03:35:07PM -0800, Jeff Johnson wrote:

[..]

> 
> my e-mail client hung while reviewing v1, so now giving
> 
> Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>

Thanks, Jeff.

--
Gustavo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_begin_scan_cmd
  2022-02-24 21:15 ` [PATCH v2 1/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_begin_scan_cmd Gustavo A. R. Silva
@ 2022-03-09 15:08   ` Kalle Valo
  0 siblings, 0 replies; 10+ messages in thread
From: Kalle Valo @ 2022-03-09 15:08 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: linux-wireless, linux-kernel, Jeff Johnson, David S. Miller,
	Jakub Kicinski, netdev, linux-hardening, Gustavo A. R. Silva

"Gustavo A. R. Silva" <gustavoars@kernel.org> wrote:

> 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.
> 
> Link: https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays
> Link: https://github.com/KSPP/linux/issues/79
> Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>

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

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/1ef801ea24475501fa0f296cb5435a440135206e.1645736204.git.gustavoars@kernel.org/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-03-09 15:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-24 21:15 [PATCH v2 0/6][next] ath6kl: wmi: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
2022-02-24 21:15 ` [PATCH v2 1/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_begin_scan_cmd Gustavo A. R. Silva
2022-03-09 15:08   ` Kalle Valo
2022-02-24 21:16 ` [PATCH v2 2/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_start_scan_cmd Gustavo A. R. Silva
2022-02-24 23:35   ` Jeff Johnson
2022-02-24 23:58     ` Gustavo A. R. Silva
2022-02-24 21:16 ` [PATCH v2 3/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_channel_list_reply Gustavo A. R. Silva
2022-02-24 21:17 ` [PATCH v2 4/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_connect_event Gustavo A. R. Silva
2022-02-24 21:17 ` [PATCH v2 5/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_disconnect_event Gustavo A. R. Silva
2022-02-24 21:17 ` [PATCH v2 6/6][next] ath6kl: wmi: Replace one-element array with flexible-array member in struct wmi_aplist_event Gustavo A. R. Silva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).