2023-12-13 17:07:24

by Jeff Johnson

[permalink] [raw]
Subject: [PATCH 5/6] wifi: ath10k: use flexible array in struct wmi_tdls_peer_capabilities

Currently struct wmi_tdls_peer_capabilities defines:
struct wmi_channel peer_chan_list[1];

Per the guidance in [1] this should be a flexible array, and at one
point Gustavo was trying to fix this [2], but had questions about the
correct behavior when the associated peer_chan_len is 0.

I have been unable to determine if firmware requires that at least one
record be present even if peer_chan_len is 0. But since that is the
current behavior, follow the example from [3] and replace the
one-element array with a union that contains both a flexible array and
a single instance of the array element. This results in a struct that
has the same footprint as the original, so no other driver changes are
required.

No functional changes, compile tested only.

[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
[2] https://lore.kernel.org/linux-wireless/[email protected]/
[3] https://lore.kernel.org/linux-wireless/202308301529.AC90A9EF98@keescook/

Signed-off-by: Jeff Johnson <[email protected]>
---
drivers/net/wireless/ath/ath10k/wmi.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath10k/wmi.h b/drivers/net/wireless/ath/ath10k/wmi.h
index e16410e348ca..b64b6e214bae 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.h
+++ b/drivers/net/wireless/ath/ath10k/wmi.h
@@ -7162,7 +7162,13 @@ struct wmi_tdls_peer_capabilities {
__le32 is_peer_responder;
__le32 pref_offchan_num;
__le32 pref_offchan_bw;
- struct wmi_channel peer_chan_list[1];
+ union {
+ /* to match legacy implementation allocate room for
+ * at least one record even if peer_chan_len is 0
+ */
+ struct wmi_channel peer_chan_min_allocation;
+ DECLARE_FLEX_ARRAY(struct wmi_channel, peer_chan_list);
+ };
} __packed;

struct wmi_10_4_tdls_peer_update_cmd {

--
2.42.0



2023-12-13 19:13:16

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH 5/6] wifi: ath10k: use flexible array in struct wmi_tdls_peer_capabilities

On Wed, Dec 13, 2023 at 09:06:43AM -0800, Jeff Johnson wrote:
> Currently struct wmi_tdls_peer_capabilities defines:
> struct wmi_channel peer_chan_list[1];
>
> Per the guidance in [1] this should be a flexible array, and at one
> point Gustavo was trying to fix this [2], but had questions about the
> correct behavior when the associated peer_chan_len is 0.
>
> I have been unable to determine if firmware requires that at least one
> record be present even if peer_chan_len is 0. But since that is the
> current behavior, follow the example from [3] and replace the
> one-element array with a union that contains both a flexible array and
> a single instance of the array element. This results in a struct that
> has the same footprint as the original, so no other driver changes are
> required.
>
> No functional changes, compile tested only.
>
> [1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
> [2] https://lore.kernel.org/linux-wireless/[email protected]/
> [3] https://lore.kernel.org/linux-wireless/202308301529.AC90A9EF98@keescook/
>
> Signed-off-by: Jeff Johnson <[email protected]>

Again, good to keep the struct the same size.

Reviewed-by: Kees Cook <[email protected]>

--
Kees Cook

2023-12-13 20:19:53

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH 5/6] wifi: ath10k: use flexible array in struct wmi_tdls_peer_capabilities



On 12/13/23 11:06, Jeff Johnson wrote:
> Currently struct wmi_tdls_peer_capabilities defines:
> struct wmi_channel peer_chan_list[1];
>
> Per the guidance in [1] this should be a flexible array, and at one
> point Gustavo was trying to fix this [2], but had questions about the
> correct behavior when the associated peer_chan_len is 0.
>
> I have been unable to determine if firmware requires that at least one
> record be present even if peer_chan_len is 0. But since that is the
> current behavior, follow the example from [3] and replace the
> one-element array with a union that contains both a flexible array and
> a single instance of the array element. This results in a struct that
> has the same footprint as the original, so no other driver changes are
> required.
>
> No functional changes, compile tested only.
>
> [1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
> [2] https://lore.kernel.org/linux-wireless/[email protected]/
> [3] https://lore.kernel.org/linux-wireless/202308301529.AC90A9EF98@keescook/
>
> Signed-off-by: Jeff Johnson <[email protected]>

Reviewed-by: Gustavo A. R. Silva <[email protected]>

Thanks!
--
Gustavo

> ---
> drivers/net/wireless/ath/ath10k/wmi.h | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/wireless/ath/ath10k/wmi.h b/drivers/net/wireless/ath/ath10k/wmi.h
> index e16410e348ca..b64b6e214bae 100644
> --- a/drivers/net/wireless/ath/ath10k/wmi.h
> +++ b/drivers/net/wireless/ath/ath10k/wmi.h
> @@ -7162,7 +7162,13 @@ struct wmi_tdls_peer_capabilities {
> __le32 is_peer_responder;
> __le32 pref_offchan_num;
> __le32 pref_offchan_bw;
> - struct wmi_channel peer_chan_list[1];
> + union {
> + /* to match legacy implementation allocate room for
> + * at least one record even if peer_chan_len is 0
> + */
> + struct wmi_channel peer_chan_min_allocation;
> + DECLARE_FLEX_ARRAY(struct wmi_channel, peer_chan_list);
> + };
> } __packed;
>
> struct wmi_10_4_tdls_peer_update_cmd {
>