linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] media: venus: Replace one-element arrays with flexible-array members
@ 2023-05-16 20:17 Gustavo A. R. Silva
  2023-05-16 20:18 ` Kees Cook
  2023-05-25 11:20 ` Vikash Garodia
  0 siblings, 2 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2023-05-16 20:17 UTC (permalink / raw)
  To: Stanimir Varbanov, Vikash Garodia, Andy Gross, Bjorn Andersson,
	Konrad Dybcio, Mauro Carvalho Chehab
  Cc: linux-media, linux-arm-msm, 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 arrays with flexible-array
members in multiple structures, 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].

This results in no differences in binary output.

Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/291
Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/media/platform/qcom/venus/hfi_msgs.c |  4 ++--
 drivers/media/platform/qcom/venus/hfi_msgs.h | 14 +++++++-------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/hfi_msgs.c b/drivers/media/platform/qcom/venus/hfi_msgs.c
index df96db3761a7..6efd78606d9b 100644
--- a/drivers/media/platform/qcom/venus/hfi_msgs.c
+++ b/drivers/media/platform/qcom/venus/hfi_msgs.c
@@ -233,7 +233,7 @@ static void hfi_sys_init_done(struct venus_core *core, struct venus_inst *inst,
 		goto done;
 	}
 
-	rem_bytes = pkt->hdr.size - sizeof(*pkt) + sizeof(u32);
+	rem_bytes = pkt->hdr.size - sizeof(*pkt);
 	if (rem_bytes <= 0) {
 		/* missing property data */
 		error = HFI_ERR_SYS_INSUFFICIENT_RESOURCES;
@@ -434,7 +434,7 @@ static void hfi_session_init_done(struct venus_core *core,
 	if (!IS_V1(core))
 		goto done;
 
-	rem_bytes = pkt->shdr.hdr.size - sizeof(*pkt) + sizeof(u32);
+	rem_bytes = pkt->shdr.hdr.size - sizeof(*pkt);
 	if (rem_bytes <= 0) {
 		error = HFI_ERR_SESSION_INSUFFICIENT_RESOURCES;
 		goto done;
diff --git a/drivers/media/platform/qcom/venus/hfi_msgs.h b/drivers/media/platform/qcom/venus/hfi_msgs.h
index 510513697335..8c2e17b0d36f 100644
--- a/drivers/media/platform/qcom/venus/hfi_msgs.h
+++ b/drivers/media/platform/qcom/venus/hfi_msgs.h
@@ -50,7 +50,7 @@ struct hfi_msg_event_notify_pkt {
 	u32 event_id;
 	u32 event_data1;
 	u32 event_data2;
-	u32 ext_event_data[1];
+	u32 ext_event_data[];
 };
 
 struct hfi_msg_event_release_buffer_ref_pkt {
@@ -63,7 +63,7 @@ struct hfi_msg_sys_init_done_pkt {
 	struct hfi_pkt_hdr hdr;
 	u32 error_type;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_sys_pc_prep_done_pkt {
@@ -81,7 +81,7 @@ struct hfi_msg_session_init_done_pkt {
 	struct hfi_session_hdr_pkt shdr;
 	u32 error_type;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_end_done_pkt {
@@ -228,7 +228,7 @@ struct hfi_msg_session_parse_sequence_header_done_pkt {
 	struct hfi_session_hdr_pkt shdr;
 	u32 error_type;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_property_info_pkt {
@@ -247,7 +247,7 @@ struct hfi_msg_session_release_buffers_done_pkt {
 	struct hfi_session_hdr_pkt shdr;
 	u32 error_type;
 	u32 num_buffers;
-	u32 buffer_info[1];
+	u32 buffer_info[];
 };
 
 struct hfi_msg_sys_debug_pkt {
@@ -256,7 +256,7 @@ struct hfi_msg_sys_debug_pkt {
 	u32 msg_size;
 	u32 time_stamp_hi;
 	u32 time_stamp_lo;
-	u8 msg_data[1];
+	u8 msg_data[];
 };
 
 struct hfi_msg_sys_coverage_pkt {
@@ -264,7 +264,7 @@ struct hfi_msg_sys_coverage_pkt {
 	u32 msg_size;
 	u32 time_stamp_hi;
 	u32 time_stamp_lo;
-	u8 msg_data[1];
+	u8 msg_data[];
 };
 
 struct venus_core;
-- 
2.34.1


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

* Re: [PATCH][next] media: venus: Replace one-element arrays with flexible-array members
  2023-05-16 20:17 [PATCH][next] media: venus: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
@ 2023-05-16 20:18 ` Kees Cook
  2023-05-17  3:44   ` Gustavo A. R. Silva
  2023-05-25 11:20 ` Vikash Garodia
  1 sibling, 1 reply; 4+ messages in thread
From: Kees Cook @ 2023-05-16 20:18 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Stanimir Varbanov, Vikash Garodia, Andy Gross, Bjorn Andersson,
	Konrad Dybcio, Mauro Carvalho Chehab, linux-media, linux-arm-msm,
	linux-kernel, linux-hardening

On Tue, May 16, 2023 at 02:17:32PM -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 arrays with flexible-array
> members in multiple structures, 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].
> 
> This results in no differences in binary output.
> 
> Link: https://github.com/KSPP/linux/issues/79
> Link: https://github.com/KSPP/linux/issues/291
> Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Oh fun, a subtraction variant! :)

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

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

* Re: [PATCH][next] media: venus: Replace one-element arrays with flexible-array members
  2023-05-16 20:18 ` Kees Cook
@ 2023-05-17  3:44   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2023-05-17  3:44 UTC (permalink / raw)
  To: Kees Cook
  Cc: Stanimir Varbanov, Vikash Garodia, Andy Gross, Bjorn Andersson,
	Konrad Dybcio, Mauro Carvalho Chehab, linux-media, linux-arm-msm,
	linux-kernel, linux-hardening

On Tue, May 16, 2023 at 01:18:39PM -0700, Kees Cook wrote:
> On Tue, May 16, 2023 at 02:17:32PM -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 arrays with flexible-array
> > members in multiple structures, 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].
> > 
> > This results in no differences in binary output.
> > 
> > Link: https://github.com/KSPP/linux/issues/79
> > Link: https://github.com/KSPP/linux/issues/291
> > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
> > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> 
> Oh fun, a subtraction variant! :)

This code has everything, subtractions and additions :p

https://lore.kernel.org/linux-hardening/ZGQn63U4IeRUiJWb@work/

> Reviewed-by: Kees Cook <keescook@chromium.org>

Thanks!
--
Gustavo

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

* Re: [PATCH][next] media: venus: Replace one-element arrays with flexible-array members
  2023-05-16 20:17 [PATCH][next] media: venus: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
  2023-05-16 20:18 ` Kees Cook
@ 2023-05-25 11:20 ` Vikash Garodia
  1 sibling, 0 replies; 4+ messages in thread
From: Vikash Garodia @ 2023-05-25 11:20 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Stanimir Varbanov, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Mauro Carvalho Chehab
  Cc: linux-media, linux-arm-msm, linux-kernel, linux-hardening



On 5/17/2023 1:47 AM, Gustavo A. R. Silva wrote:
> One-element arrays are deprecated, and we are replacing them with flexible
> array members instead. So, replace one-element arrays with flexible-array
> members in multiple structures, 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].
> 
> This results in no differences in binary output.
> 
> Link: https://github.com/KSPP/linux/issues/79
> Link: https://github.com/KSPP/linux/issues/291
> Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

The patch looks good to me. It would be nice if we can combine all the patches
related to flexible array handling in video driver in a single patch series. At
the moment, there are multiple patches with similar subject.

> ---
>  drivers/media/platform/qcom/venus/hfi_msgs.c |  4 ++--
>  drivers/media/platform/qcom/venus/hfi_msgs.h | 14 +++++++-------
>  2 files changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/media/platform/qcom/venus/hfi_msgs.c b/drivers/media/platform/qcom/venus/hfi_msgs.c
> index df96db3761a7..6efd78606d9b 100644
> --- a/drivers/media/platform/qcom/venus/hfi_msgs.c
> +++ b/drivers/media/platform/qcom/venus/hfi_msgs.c
> @@ -233,7 +233,7 @@ static void hfi_sys_init_done(struct venus_core *core, struct venus_inst *inst,
>  		goto done;
>  	}
>  
> -	rem_bytes = pkt->hdr.size - sizeof(*pkt) + sizeof(u32);
> +	rem_bytes = pkt->hdr.size - sizeof(*pkt);
>  	if (rem_bytes <= 0) {
>  		/* missing property data */
>  		error = HFI_ERR_SYS_INSUFFICIENT_RESOURCES;
> @@ -434,7 +434,7 @@ static void hfi_session_init_done(struct venus_core *core,
>  	if (!IS_V1(core))
>  		goto done;
>  
> -	rem_bytes = pkt->shdr.hdr.size - sizeof(*pkt) + sizeof(u32);
> +	rem_bytes = pkt->shdr.hdr.size - sizeof(*pkt);
>  	if (rem_bytes <= 0) {
>  		error = HFI_ERR_SESSION_INSUFFICIENT_RESOURCES;
>  		goto done;
> diff --git a/drivers/media/platform/qcom/venus/hfi_msgs.h b/drivers/media/platform/qcom/venus/hfi_msgs.h
> index 510513697335..8c2e17b0d36f 100644
> --- a/drivers/media/platform/qcom/venus/hfi_msgs.h
> +++ b/drivers/media/platform/qcom/venus/hfi_msgs.h
> @@ -50,7 +50,7 @@ struct hfi_msg_event_notify_pkt {
>  	u32 event_id;
>  	u32 event_data1;
>  	u32 event_data2;
> -	u32 ext_event_data[1];
> +	u32 ext_event_data[];
>  };
>  
>  struct hfi_msg_event_release_buffer_ref_pkt {
> @@ -63,7 +63,7 @@ struct hfi_msg_sys_init_done_pkt {
>  	struct hfi_pkt_hdr hdr;
>  	u32 error_type;
>  	u32 num_properties;
> -	u32 data[1];
> +	u32 data[];
>  };
>  
>  struct hfi_msg_sys_pc_prep_done_pkt {
> @@ -81,7 +81,7 @@ struct hfi_msg_session_init_done_pkt {
>  	struct hfi_session_hdr_pkt shdr;
>  	u32 error_type;
>  	u32 num_properties;
> -	u32 data[1];
> +	u32 data[];
>  };
>  
>  struct hfi_msg_session_end_done_pkt {
> @@ -228,7 +228,7 @@ struct hfi_msg_session_parse_sequence_header_done_pkt {
>  	struct hfi_session_hdr_pkt shdr;
>  	u32 error_type;
>  	u32 num_properties;
> -	u32 data[1];
> +	u32 data[];
>  };
>  
>  struct hfi_msg_session_property_info_pkt {
> @@ -247,7 +247,7 @@ struct hfi_msg_session_release_buffers_done_pkt {
>  	struct hfi_session_hdr_pkt shdr;
>  	u32 error_type;
>  	u32 num_buffers;
> -	u32 buffer_info[1];
> +	u32 buffer_info[];
>  };
>  
>  struct hfi_msg_sys_debug_pkt {
> @@ -256,7 +256,7 @@ struct hfi_msg_sys_debug_pkt {
>  	u32 msg_size;
>  	u32 time_stamp_hi;
>  	u32 time_stamp_lo;
> -	u8 msg_data[1];
> +	u8 msg_data[];
>  };
>  
>  struct hfi_msg_sys_coverage_pkt {
> @@ -264,7 +264,7 @@ struct hfi_msg_sys_coverage_pkt {
>  	u32 msg_size;
>  	u32 time_stamp_hi;
>  	u32 time_stamp_lo;
> -	u8 msg_data[1];
> +	u8 msg_data[];
>  };
>  
>  struct venus_core;

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

end of thread, other threads:[~2023-05-25 11:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-16 20:17 [PATCH][next] media: venus: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
2023-05-16 20:18 ` Kees Cook
2023-05-17  3:44   ` Gustavo A. R. Silva
2023-05-25 11:20 ` Vikash Garodia

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