Skip to contentSkip to conversation

media: venus: hfi_msgs.h: Replace one-element arrays with flexible-array members

PATCH In review Gustavo A. R. Silva 3 participants 8 messages Feb 11, 2021 – Jun 4, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: venus: hfi_msgs.h: Replace one-element arrays with flexible-array members

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

Use flexible-array members in struct hfi_msg_sys_property_info_pkt and hfi_msg_session_property_info_pkt instead of one-element arrays.

Also, this helps with the ongoing efforts to enable -Warray-bounds by fixing the following warnings:

CC [M] drivers/media/platform/qcom/venus/hfi_msgs.o
drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_sys_property_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:246:35: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
246 | if (req_bytes < 128 || !pkt->data[1] || pkt->num_properties > 1)

      |                          ~~~~~~~~~^~~

drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_session_prop_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:342:62: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
342 | if (!req_bytes || req_bytes % sizeof(*buf_req) || !pkt->data[1])
| ~~~~~~~~~^~~

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9/process/deprecated.html#zero-length-and-one-element-arrays

---
 drivers/media/platform/qcom/venus/hfi_msgs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/hfi_msgs.h +2 -2
index 526d9f5b487b..e2d2ccfbdd24 100644
@@ -113,7 +113,7 @@ struct hfi_msg_sys_ping_ack_pkt {
 struct hfi_msg_sys_property_info_pkt {
 	struct hfi_pkt_hdr hdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_load_resources_done_pkt {
@@ -233,7 +233,7 @@ struct hfi_msg_session_parse_sequence_header_done_pkt {
 struct hfi_msg_session_property_info_pkt {
 	struct hfi_session_hdr_pkt shdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_release_resources_done_pkt {
Signature · 1 line
2.27.0
#1 lore raw

Hi all,

Friendly ping: who can take this, please?

Thanks
--
Gustavo

Quoted 58 lines · Gustavo A. R. Silva

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

Use flexible-array members in struct hfi_msg_sys_property_info_pkt and hfi_msg_session_property_info_pkt instead of one-element arrays.

Also, this helps with the ongoing efforts to enable -Warray-bounds by fixing the following warnings:

CC [M] drivers/media/platform/qcom/venus/hfi_msgs.o
drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_sys_property_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:246:35: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
246 | if (req_bytes < 128 || !pkt->data[1] || pkt->num_properties > 1)

      |                          ~~~~~~~~~^~~

drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_session_prop_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:342:62: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
342 | if (!req_bytes || req_bytes % sizeof(*buf_req) || !pkt->data[1])
| ~~~~~~~~~^~~

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9/process/deprecated.html#zero-length-and-one-element-arrays

---
 drivers/media/platform/qcom/venus/hfi_msgs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/hfi_msgs.h +2 -2
index 526d9f5b487b..e2d2ccfbdd24 100644
@@ -113,7 +113,7 @@ struct hfi_msg_sys_ping_ack_pkt {
 struct hfi_msg_sys_property_info_pkt {
 	struct hfi_pkt_hdr hdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_load_resources_done_pkt {
@@ -233,7 +233,7 @@ struct hfi_msg_session_parse_sequence_header_done_pkt {
 struct hfi_msg_session_property_info_pkt {
 	struct hfi_session_hdr_pkt shdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_release_resources_done_pkt {
Signature · 1 line
2.27.0
#2 lore raw
In reply to Gustavo A. R. Silva

Hi all,

Friendly ping:

We are about to be able to globally enable -Warray-bounds and, these are one of the last out-of-bounds warnings in linux-next.

Could someone take this, please?

Thanks
--
Gustavo

Quoted 56 lines · Gustavo A. R. Silva

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

Use flexible-array members in struct hfi_msg_sys_property_info_pkt and hfi_msg_session_property_info_pkt instead of one-element arrays.

Also, this helps with the ongoing efforts to enable -Warray-bounds by fixing the following warnings:

CC [M] drivers/media/platform/qcom/venus/hfi_msgs.o
drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_sys_property_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:246:35: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
246 | if (req_bytes < 128 || !pkt->data[1] || pkt->num_properties > 1)

      |                          ~~~~~~~~~^~~

drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_session_prop_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:342:62: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
342 | if (!req_bytes || req_bytes % sizeof(*buf_req) || !pkt->data[1])
| ~~~~~~~~~^~~

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9/process/deprecated.html#zero-length-and-one-element-arrays

---
 drivers/media/platform/qcom/venus/hfi_msgs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/hfi_msgs.h +2 -2
index 526d9f5b487b..e2d2ccfbdd24 100644
@@ -113,7 +113,7 @@ struct hfi_msg_sys_ping_ack_pkt {
 struct hfi_msg_sys_property_info_pkt {
 	struct hfi_pkt_hdr hdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_load_resources_done_pkt {
@@ -233,7 +233,7 @@ struct hfi_msg_session_parse_sequence_header_done_pkt {
 struct hfi_msg_session_property_info_pkt {
 	struct hfi_session_hdr_pkt shdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_release_resources_done_pkt {
#3 lore raw

Hi,

Quoted 8 lines · Gustavo A. R. Silva

Hi all,

Friendly ping:

We are about to be able to globally enable -Warray-bounds and, these are one of the last out-of-bounds warnings in linux-next.

Could someone take this, please?

This one introduces regressions, so I cannot take it. It needs some more work.

Quoted 62 lines

Thanks
--
Gustavo

Quoted 56 lines · Gustavo A. R. Silva

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

Use flexible-array members in struct hfi_msg_sys_property_info_pkt and hfi_msg_session_property_info_pkt instead of one-element arrays.

Also, this helps with the ongoing efforts to enable -Warray-bounds by fixing the following warnings:

CC [M] drivers/media/platform/qcom/venus/hfi_msgs.o
drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_sys_property_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:246:35: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
246 | if (req_bytes < 128 || !pkt->data[1] || pkt->num_properties > 1)

      |                          ~~~~~~~~~^~~

drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_session_prop_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:342:62: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
342 | if (!req_bytes || req_bytes % sizeof(*buf_req) || !pkt->data[1])
| ~~~~~~~~~^~~

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9/process/deprecated.html#zero-length-and-one-element-arrays

---
 drivers/media/platform/qcom/venus/hfi_msgs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/hfi_msgs.h +2 -2
index 526d9f5b487b..e2d2ccfbdd24 100644
@@ -113,7 +113,7 @@ struct hfi_msg_sys_ping_ack_pkt {
 struct hfi_msg_sys_property_info_pkt {
 	struct hfi_pkt_hdr hdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_load_resources_done_pkt {
@@ -233,7 +233,7 @@ struct hfi_msg_session_parse_sequence_header_done_pkt {
 struct hfi_msg_session_property_info_pkt {
 	struct hfi_session_hdr_pkt shdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_release_resources_done_pkt {
Signature · 2 lines
regards,
Stan
#4 lore raw
Quoted 7 lines · Stanimir Varbanov

Hi,

Quoted 4 lines · Gustavo A. R. Silva

Hi all,

Friendly ping:

Quoted 7 lines
Quoted 4 lines

We are about to be able to globally enable -Warray-bounds and, these are one of the last out-of-bounds warnings in linux-next.

Could someone take this, please?

This one introduces regressions, so I cannot take it. It needs some more work.

Please, share with me the errors or warnings you see with this. So, I can have an idea of what is going on. Unfortunately, I don't have access to the test suite or hardware to test this.

Thanks!
--
Gustavo

Quoted 63 lines
Quoted 62 lines

Thanks
--
Gustavo

Quoted 56 lines · Gustavo A. R. Silva

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

Use flexible-array members in struct hfi_msg_sys_property_info_pkt and hfi_msg_session_property_info_pkt instead of one-element arrays.

Also, this helps with the ongoing efforts to enable -Warray-bounds by fixing the following warnings:

CC [M] drivers/media/platform/qcom/venus/hfi_msgs.o
drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_sys_property_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:246:35: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
246 | if (req_bytes < 128 || !pkt->data[1] || pkt->num_properties > 1)

      |                          ~~~~~~~~~^~~

drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_session_prop_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:342:62: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
342 | if (!req_bytes || req_bytes % sizeof(*buf_req) || !pkt->data[1])
| ~~~~~~~~~^~~

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9/process/deprecated.html#zero-length-and-one-element-arrays

---
 drivers/media/platform/qcom/venus/hfi_msgs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/hfi_msgs.h +2 -2
index 526d9f5b487b..e2d2ccfbdd24 100644
@@ -113,7 +113,7 @@ struct hfi_msg_sys_ping_ack_pkt {
 struct hfi_msg_sys_property_info_pkt {
 	struct hfi_pkt_hdr hdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_load_resources_done_pkt {
@@ -233,7 +233,7 @@ struct hfi_msg_session_parse_sequence_header_done_pkt {
 struct hfi_msg_session_property_info_pkt {
 	struct hfi_session_hdr_pkt shdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_release_resources_done_pkt {
#5 lore raw

Hi,

Quoted 13 lines · Gustavo A. R. Silva
Quoted 10 lines · Stanimir Varbanov

Hi,

Quoted 7 lines · Gustavo A. R. Silva

Hi all,

Friendly ping:

We are about to be able to globally enable -Warray-bounds and, these are one of the last out-of-bounds warnings in linux-next.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Could someone take this, please?

This one introduces regressions, so I cannot take it. It needs some more work.

Please, share with me the errors or warnings you see with this. So, I can have an idea of what is going on. Unfortunately, I don't have access to the test suite or hardware to test this.

I guess it needs more debugging, but the simple answer is that the driver refuse to start streaming with this patch.

Quoted 70 lines

Thanks!
--
Gustavo

Quoted 63 lines
Quoted 62 lines

Thanks
--
Gustavo

Quoted 56 lines · Gustavo A. R. Silva

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

Use flexible-array members in struct hfi_msg_sys_property_info_pkt and hfi_msg_session_property_info_pkt instead of one-element arrays.

Also, this helps with the ongoing efforts to enable -Warray-bounds by fixing the following warnings:

CC [M] drivers/media/platform/qcom/venus/hfi_msgs.o
drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_sys_property_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:246:35: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
246 | if (req_bytes < 128 || !pkt->data[1] || pkt->num_properties > 1)

      |                          ~~~~~~~~~^~~

drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_session_prop_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:342:62: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
342 | if (!req_bytes || req_bytes % sizeof(*buf_req) || !pkt->data[1])
| ~~~~~~~~~^~~

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9/process/deprecated.html#zero-length-and-one-element-arrays

---
 drivers/media/platform/qcom/venus/hfi_msgs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/hfi_msgs.h +2 -2
index 526d9f5b487b..e2d2ccfbdd24 100644
@@ -113,7 +113,7 @@ struct hfi_msg_sys_ping_ack_pkt {
 struct hfi_msg_sys_property_info_pkt {
 	struct hfi_pkt_hdr hdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_load_resources_done_pkt {
@@ -233,7 +233,7 @@ struct hfi_msg_session_parse_sequence_header_done_pkt {
 struct hfi_msg_session_property_info_pkt {
 	struct hfi_session_hdr_pkt shdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_release_resources_done_pkt {
Signature · 2 lines
regards,
Stan
#6 lore raw

Hi Stanimir,

Quoted 9 lines · Stanimir Varbanov
Quoted 6 lines
Quoted 2 lines

This one introduces regressions, so I cannot take it. It needs some more work.

Please, share with me the errors or warnings you see with this. So, I can have an idea of what is going on. Unfortunately, I don't have access to the test suite or hardware to test this.

I guess it needs more debugging, but the simple answer is that the driver refuse to start streaming with this patch.

I see. Please, share with me the details about your test setup. Are you using qemu or actual hardware for this?

Please, also help me by sending me your .config file and dmesg output, as well. So, I can try to debug this.

Thanks!
--
Gustavo

#7 lore raw
In reply to Stanimir Varbanov

Hi Stanimir,

Quoted 21 lines · Stanimir Varbanov

Hi,

Quoted 18 lines · Gustavo A. R. Silva
Quoted 14 lines · Stanimir Varbanov

Hi,

Quoted 8 lines · Gustavo A. R. Silva

Hi all,

Friendly ping:

We are about to be able to globally enable -Warray-bounds and, these are one of the last out-of-bounds warnings in linux-next.

Could someone take this, please?

This one introduces regressions, so I cannot take it. It needs some more work.

Quoted 6 lines
Quoted 3 lines

Please, share with me the errors or warnings you see with this. So, I can have an idea of what is going on. Unfortunately, I don't have access to the test suite or hardware to test this.

I guess it needs more debugging, but the simple answer is that the driver refuse to start streaming with this patch.

This patch should fix the problems you are seeing:

https://lore.kernel.org/linux-hardening/20210604004338.GA140710@embeddedor/

Could you please help me to test it?

Thanks!
--
Gustavo

Quoted 72 lines
Quoted 71 lines

Thanks!
--
Gustavo

Quoted 63 lines
Quoted 62 lines

Thanks
--
Gustavo

Quoted 56 lines · Gustavo A. R. Silva

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

Use flexible-array members in struct hfi_msg_sys_property_info_pkt and hfi_msg_session_property_info_pkt instead of one-element arrays.

Also, this helps with the ongoing efforts to enable -Warray-bounds by fixing the following warnings:

CC [M] drivers/media/platform/qcom/venus/hfi_msgs.o
drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_sys_property_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:246:35: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
246 | if (req_bytes < 128 || !pkt->data[1] || pkt->num_properties > 1)

      |                          ~~~~~~~~~^~~

drivers/media/platform/qcom/venus/hfi_msgs.c: In function ‘hfi_session_prop_info’:
drivers/media/platform/qcom/venus/hfi_msgs.c:342:62: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
342 | if (!req_bytes || req_bytes % sizeof(*buf_req) || !pkt->data[1])
| ~~~~~~~~~^~~

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9/process/deprecated.html#zero-length-and-one-element-arrays

---
 drivers/media/platform/qcom/venus/hfi_msgs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/hfi_msgs.h +2 -2
index 526d9f5b487b..e2d2ccfbdd24 100644
@@ -113,7 +113,7 @@ struct hfi_msg_sys_ping_ack_pkt {
 struct hfi_msg_sys_property_info_pkt {
 	struct hfi_pkt_hdr hdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_load_resources_done_pkt {
@@ -233,7 +233,7 @@ struct hfi_msg_session_parse_sequence_header_done_pkt {
 struct hfi_msg_session_property_info_pkt {
 	struct hfi_session_hdr_pkt shdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data[];
 };
 
 struct hfi_msg_session_release_resources_done_pkt {