2023-03-17 16:59:29

by Gustavo A. R. Silva

[permalink] [raw]
Subject: [PATCH][next] uapi: target: Replace fake flex-array with flexible-array member

Zero-length arrays as fake flexible arrays are deprecated and we are
moving towards adopting C99 flexible-array members instead.

Address the following warning found with GCC-13 and
-fstrict-flex-arrays=3 enabled:
CC drivers/target/target_core_user.o
drivers/target/target_core_user.c: In function ‘queue_cmd_ring’:
drivers/target/target_core_user.c:1096:15: warning: array subscript 0 is outside array bounds of ‘struct iovec[0]’ [-Warray-bounds=]
1096 | iov = &entry->req.iov[0];
| ^~~~~~~~~~~~~~~~~~
In file included from drivers/target/target_core_user.c:31:
./include/uapi/linux/target_core_user.h:122:38: note: while referencing ‘iov’
122 | struct iovec iov[0];
| ^~~

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/21
Link: https://github.com/KSPP/linux/issues/270
Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
Signed-off-by: Gustavo A. R. Silva <[email protected]>
---
include/uapi/linux/target_core_user.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/target_core_user.h b/include/uapi/linux/target_core_user.h
index fbd8ca67e107..f925a77f19ed 100644
--- a/include/uapi/linux/target_core_user.h
+++ b/include/uapi/linux/target_core_user.h
@@ -119,7 +119,7 @@ struct tcmu_cmd_entry {
__u64 cdb_off;
__u64 __pad1;
__u64 __pad2;
- struct iovec iov[0];
+ __DECLARE_FLEX_ARRAY(struct iovec, iov);
} req;
struct {
__u8 scsi_status;
--
2.34.1



2023-03-18 13:01:06

by Bodo Stroesser

[permalink] [raw]
Subject: Re: [PATCH][next] uapi: target: Replace fake flex-array with flexible-array member

On 17.03.23 17:59, Gustavo A. R. Silva wrote:
> Zero-length arrays as fake flexible arrays are deprecated and we are
> moving towards adopting C99 flexible-array members instead.
>
> Address the following warning found with GCC-13 and
> -fstrict-flex-arrays=3 enabled:
> CC drivers/target/target_core_user.o
> drivers/target/target_core_user.c: In function ‘queue_cmd_ring’:
> drivers/target/target_core_user.c:1096:15: warning: array subscript 0 is outside array bounds of ‘struct iovec[0]’ [-Warray-bounds=]
> 1096 | iov = &entry->req.iov[0];
> | ^~~~~~~~~~~~~~~~~~
> In file included from drivers/target/target_core_user.c:31:
> ./include/uapi/linux/target_core_user.h:122:38: note: while referencing ‘iov’
> 122 | struct iovec iov[0];
> | ^~~
>
> 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/21
> Link: https://github.com/KSPP/linux/issues/270
> Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
> Signed-off-by: Gustavo A. R. Silva <[email protected]>
> ---
> include/uapi/linux/target_core_user.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/uapi/linux/target_core_user.h b/include/uapi/linux/target_core_user.h
> index fbd8ca67e107..f925a77f19ed 100644
> --- a/include/uapi/linux/target_core_user.h
> +++ b/include/uapi/linux/target_core_user.h
> @@ -119,7 +119,7 @@ struct tcmu_cmd_entry {
> __u64 cdb_off;
> __u64 __pad1;
> __u64 __pad2;
> - struct iovec iov[0];
> + __DECLARE_FLEX_ARRAY(struct iovec, iov);
> } req;
> struct {
> __u8 scsi_status;

Looks good. Thank you.

Reviewed-by: Bodo Stroesser <[email protected]>

2023-03-20 18:41:46

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH][next] uapi: target: Replace fake flex-array with flexible-array member

On Fri, Mar 17, 2023 at 10:59:48AM -0600, Gustavo A. R. Silva wrote:
> Zero-length arrays as fake flexible arrays are deprecated and we are
> moving towards adopting C99 flexible-array members instead.
>
> Address the following warning found with GCC-13 and
> -fstrict-flex-arrays=3 enabled:
> CC drivers/target/target_core_user.o
> drivers/target/target_core_user.c: In function ‘queue_cmd_ring’:
> drivers/target/target_core_user.c:1096:15: warning: array subscript 0 is outside array bounds of ‘struct iovec[0]’ [-Warray-bounds=]
> 1096 | iov = &entry->req.iov[0];
> | ^~~~~~~~~~~~~~~~~~
> In file included from drivers/target/target_core_user.c:31:
> ./include/uapi/linux/target_core_user.h:122:38: note: while referencing ‘iov’
> 122 | struct iovec iov[0];
> | ^~~
>
> 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/21
> Link: https://github.com/KSPP/linux/issues/270
> Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
> Signed-off-by: Gustavo A. R. Silva <[email protected]>

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

--
Kees Cook

2023-03-24 21:05:38

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH][next] uapi: target: Replace fake flex-array with flexible-array member


Gustavo,

> Zero-length arrays as fake flexible arrays are deprecated and we are
> moving towards adopting C99 flexible-array members instead.

Applied to 6.4/scsi-staging, thanks!

--
Martin K. Petersen Oracle Linux Engineering

2023-04-03 02:16:24

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH][next] uapi: target: Replace fake flex-array with flexible-array member

On Fri, 17 Mar 2023 10:59:48 -0600, Gustavo A. R. Silva wrote:

> Zero-length arrays as fake flexible arrays are deprecated and we are
> moving towards adopting C99 flexible-array members instead.
>
> Address the following warning found with GCC-13 and
> -fstrict-flex-arrays=3 enabled:
> CC drivers/target/target_core_user.o
> drivers/target/target_core_user.c: In function ‘queue_cmd_ring’:
> drivers/target/target_core_user.c:1096:15: warning: array subscript 0 is outside array bounds of ‘struct iovec[0]’ [-Warray-bounds=]
> 1096 | iov = &entry->req.iov[0];
> | ^~~~~~~~~~~~~~~~~~
> In file included from drivers/target/target_core_user.c:31:
> ./include/uapi/linux/target_core_user.h:122:38: note: while referencing ‘iov’
> 122 | struct iovec iov[0];
> | ^~~
>
> [...]

Applied to 6.4/scsi-queue, thanks!

[1/1] uapi: target: Replace fake flex-array with flexible-array member
https://git.kernel.org/mkp/scsi/c/5c8c74ef20e7

--
Martin K. Petersen Oracle Linux Engineering