* [PATCH][next] iavf: Replace one-element array with flexible-array member
@ 2023-05-16 0:44 Gustavo A. R. Silva
2023-05-16 10:19 ` Simon Horman
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Gustavo A. R. Silva @ 2023-05-16 0:44 UTC (permalink / raw)
To: Jesse Brandeburg, Tony Nguyen, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: intel-wired-lan, netdev, linux-kernel, Gustavo A. R. Silva,
linux-hardening
One-element arrays are deprecated, and we are replacing them with flexible
array members instead. So, replace one-element array with flexible-array
member in struct iavf_qvlist_info, and refactor the rest of the code,
accordingly.
This helps with the ongoing efforts to tighten the FORTIFY_SOURCE
routines on memcpy() and help us make progress towards globally
enabling -fstrict-flex-arrays=3 [1].
Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/289
Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/net/ethernet/intel/iavf/iavf_client.c | 2 +-
drivers/net/ethernet/intel/iavf/iavf_client.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/intel/iavf/iavf_client.c b/drivers/net/ethernet/intel/iavf/iavf_client.c
index 93c903c02c64..782384b3aa38 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_client.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_client.c
@@ -470,7 +470,7 @@ static int iavf_client_setup_qvlist(struct iavf_info *ldev,
v_qvlist_info = (struct virtchnl_rdma_qvlist_info *)qvlist_info;
msg_size = struct_size(v_qvlist_info, qv_info,
- v_qvlist_info->num_vectors - 1);
+ v_qvlist_info->num_vectors);
adapter->client_pending |= BIT(VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP);
err = iavf_aq_send_msg_to_pf(&adapter->hw,
diff --git a/drivers/net/ethernet/intel/iavf/iavf_client.h b/drivers/net/ethernet/intel/iavf/iavf_client.h
index c5d51d7dc7cc..500269bc0f5b 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_client.h
+++ b/drivers/net/ethernet/intel/iavf/iavf_client.h
@@ -53,7 +53,7 @@ struct iavf_qv_info {
struct iavf_qvlist_info {
u32 num_vectors;
- struct iavf_qv_info qv_info[1];
+ struct iavf_qv_info qv_info[];
};
#define IAVF_CLIENT_MSIX_ALL 0xFFFFFFFF
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH][next] iavf: Replace one-element array with flexible-array member 2023-05-16 0:44 [PATCH][next] iavf: Replace one-element array with flexible-array member Gustavo A. R. Silva @ 2023-05-16 10:19 ` Simon Horman 2023-05-16 19:01 ` Kees Cook 2023-05-23 18:19 ` Tony Nguyen 2 siblings, 0 replies; 5+ messages in thread From: Simon Horman @ 2023-05-16 10:19 UTC (permalink / raw) To: Gustavo A. R. Silva Cc: Jesse Brandeburg, Tony Nguyen, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, intel-wired-lan, netdev, linux-kernel, linux-hardening On Mon, May 15, 2023 at 06:44:12PM -0600, Gustavo A. R. Silva wrote: > One-element arrays are deprecated, and we are replacing them with flexible > array members instead. So, replace one-element array with flexible-array > member in struct iavf_qvlist_info, and refactor the rest of the code, > accordingly. > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > routines on memcpy() and help us make progress towards globally > enabling -fstrict-flex-arrays=3 [1]. > > Link: https://github.com/KSPP/linux/issues/79 > Link: https://github.com/KSPP/linux/issues/289 > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Simon Horman <simon.horman@corigine.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][next] iavf: Replace one-element array with flexible-array member 2023-05-16 0:44 [PATCH][next] iavf: Replace one-element array with flexible-array member Gustavo A. R. Silva 2023-05-16 10:19 ` Simon Horman @ 2023-05-16 19:01 ` Kees Cook 2023-05-23 18:19 ` Tony Nguyen 2 siblings, 0 replies; 5+ messages in thread From: Kees Cook @ 2023-05-16 19:01 UTC (permalink / raw) To: Gustavo A. R. Silva Cc: Jesse Brandeburg, Tony Nguyen, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, intel-wired-lan, netdev, linux-kernel, linux-hardening On Mon, May 15, 2023 at 06:44:12PM -0600, Gustavo A. R. Silva wrote: > One-element arrays are deprecated, and we are replacing them with flexible > array members instead. So, replace one-element array with flexible-array > member in struct iavf_qvlist_info, and refactor the rest of the code, > accordingly. > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > routines on memcpy() and help us make progress towards globally > enabling -fstrict-flex-arrays=3 [1]. > > Link: https://github.com/KSPP/linux/issues/79 > Link: https://github.com/KSPP/linux/issues/289 > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org> -- Kees Cook ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][next] iavf: Replace one-element array with flexible-array member 2023-05-16 0:44 [PATCH][next] iavf: Replace one-element array with flexible-array member Gustavo A. R. Silva 2023-05-16 10:19 ` Simon Horman 2023-05-16 19:01 ` Kees Cook @ 2023-05-23 18:19 ` Tony Nguyen 2023-05-26 21:00 ` Kees Cook 2 siblings, 1 reply; 5+ messages in thread From: Tony Nguyen @ 2023-05-23 18:19 UTC (permalink / raw) To: Gustavo A. R. Silva, Jesse Brandeburg, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, keescook Cc: intel-wired-lan, netdev, linux-kernel, linux-hardening, Keller, Jacob E On 5/15/2023 5:44 PM, Gustavo A. R. Silva wrote: > One-element arrays are deprecated, and we are replacing them with flexible > array members instead. So, replace one-element array with flexible-array > member in struct iavf_qvlist_info, and refactor the rest of the code, > accordingly. > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > routines on memcpy() and help us make progress towards globally > enabling -fstrict-flex-arrays=3 [1]. > > Link: https://github.com/KSPP/linux/issues/79 > Link: https://github.com/KSPP/linux/issues/289 > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > --- > drivers/net/ethernet/intel/iavf/iavf_client.c | 2 +- > drivers/net/ethernet/intel/iavf/iavf_client.h | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/intel/iavf/iavf_client.c b/drivers/net/ethernet/intel/iavf/iavf_client.c > index 93c903c02c64..782384b3aa38 100644 > --- a/drivers/net/ethernet/intel/iavf/iavf_client.c > +++ b/drivers/net/ethernet/intel/iavf/iavf_client.c > @@ -470,7 +470,7 @@ static int iavf_client_setup_qvlist(struct iavf_info *ldev, > > v_qvlist_info = (struct virtchnl_rdma_qvlist_info *)qvlist_info; > msg_size = struct_size(v_qvlist_info, qv_info, > - v_qvlist_info->num_vectors - 1); > + v_qvlist_info->num_vectors); The problem is this mirrors the virtchnl struct (virtchnl_rdma_qvlist_info) so that structure needs to change as well... However, this goes back to the interface that virtchnl provides between PF and VF [1]. I think removing the iavf structure and directly using the virtchnl one would make sense. We'd need to adjust virtchnl and follow Kees' suggestion [2]. > adapter->client_pending |= BIT(VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP); > err = iavf_aq_send_msg_to_pf(&adapter->hw, > diff --git a/drivers/net/ethernet/intel/iavf/iavf_client.h b/drivers/net/ethernet/intel/iavf/iavf_client.h > index c5d51d7dc7cc..500269bc0f5b 100644 > --- a/drivers/net/ethernet/intel/iavf/iavf_client.h > +++ b/drivers/net/ethernet/intel/iavf/iavf_client.h > @@ -53,7 +53,7 @@ struct iavf_qv_info { > > struct iavf_qvlist_info { > u32 num_vectors; > - struct iavf_qv_info qv_info[1]; > + struct iavf_qv_info qv_info[]; > }; > > #define IAVF_CLIENT_MSIX_ALL 0xFFFFFFFF [1] https://lore.kernel.org/intel-wired-lan/f3674339c0390ced22b365101f2d3e3a2bf26845.camel@intel.com/ [2] https://lore.kernel.org/intel-wired-lan/202106091424.37E833794@keescook/ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][next] iavf: Replace one-element array with flexible-array member 2023-05-23 18:19 ` Tony Nguyen @ 2023-05-26 21:00 ` Kees Cook 0 siblings, 0 replies; 5+ messages in thread From: Kees Cook @ 2023-05-26 21:00 UTC (permalink / raw) To: Tony Nguyen Cc: Gustavo A. R. Silva, Jesse Brandeburg, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, intel-wired-lan, netdev, linux-kernel, linux-hardening, Keller, Jacob E On Tue, May 23, 2023 at 11:19:00AM -0700, Tony Nguyen wrote: > On 5/15/2023 5:44 PM, Gustavo A. R. Silva wrote: > > One-element arrays are deprecated, and we are replacing them with flexible > > array members instead. So, replace one-element array with flexible-array > > member in struct iavf_qvlist_info, and refactor the rest of the code, > > accordingly. > > > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > > routines on memcpy() and help us make progress towards globally > > enabling -fstrict-flex-arrays=3 [1]. > > > > Link: https://github.com/KSPP/linux/issues/79 > > Link: https://github.com/KSPP/linux/issues/289 > > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] > > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > > --- > > drivers/net/ethernet/intel/iavf/iavf_client.c | 2 +- > > drivers/net/ethernet/intel/iavf/iavf_client.h | 2 +- > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/net/ethernet/intel/iavf/iavf_client.c b/drivers/net/ethernet/intel/iavf/iavf_client.c > > index 93c903c02c64..782384b3aa38 100644 > > --- a/drivers/net/ethernet/intel/iavf/iavf_client.c > > +++ b/drivers/net/ethernet/intel/iavf/iavf_client.c > > @@ -470,7 +470,7 @@ static int iavf_client_setup_qvlist(struct iavf_info *ldev, > > v_qvlist_info = (struct virtchnl_rdma_qvlist_info *)qvlist_info; > > msg_size = struct_size(v_qvlist_info, qv_info, > > - v_qvlist_info->num_vectors - 1); > > + v_qvlist_info->num_vectors); > > The problem is this mirrors the virtchnl struct (virtchnl_rdma_qvlist_info) > so that structure needs to change as well... However, this goes back to the > interface that virtchnl provides between PF and VF [1]. > > I think removing the iavf structure and directly using the virtchnl one > would make sense. We'd need to adjust virtchnl and follow Kees' suggestion > [2]. Note that at the time I suggested "[0]", but it should have been "[]". But, yes, Keeping the "over allocation" is fine since it's a hardware ABI. Alternatively, it could be defined with a union to keep all the sizes the same: struct iavf_qvlist_info { u32 num_vectors; - struct iavf_qv_info qv_info[1]; + union { + struct iavf_qv_info single_qv_info; + DECLARE_FLEX_ARRAY(struct iavf_qv_info, qv_info) + }; }; -Kees > > > adapter->client_pending |= BIT(VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP); > > err = iavf_aq_send_msg_to_pf(&adapter->hw, > > diff --git a/drivers/net/ethernet/intel/iavf/iavf_client.h b/drivers/net/ethernet/intel/iavf/iavf_client.h > > index c5d51d7dc7cc..500269bc0f5b 100644 > > --- a/drivers/net/ethernet/intel/iavf/iavf_client.h > > +++ b/drivers/net/ethernet/intel/iavf/iavf_client.h > > @@ -53,7 +53,7 @@ struct iavf_qv_info { > > struct iavf_qvlist_info { > > u32 num_vectors; > > - struct iavf_qv_info qv_info[1]; > > + struct iavf_qv_info qv_info[]; > > }; > > #define IAVF_CLIENT_MSIX_ALL 0xFFFFFFFF > > [1] https://lore.kernel.org/intel-wired-lan/f3674339c0390ced22b365101f2d3e3a2bf26845.camel@intel.com/ > [2] https://lore.kernel.org/intel-wired-lan/202106091424.37E833794@keescook/ -- Kees Cook ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-05-26 21:00 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-05-16 0:44 [PATCH][next] iavf: Replace one-element array with flexible-array member Gustavo A. R. Silva 2023-05-16 10:19 ` Simon Horman 2023-05-16 19:01 ` Kees Cook 2023-05-23 18:19 ` Tony Nguyen 2023-05-26 21:00 ` Kees Cook
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).