[Devel] [PATCH VZ10] fs/fuse kio: replace zero-length array with flexible array syntax
Konstantin Khorenko
khorenko at virtuozzo.com
Fri May 15 18:57:29 MSK 2026
On 5/6/26 12:27, Liu Kui wrote:
> With FORTIFY_SOURCE, memcpy to a zero-length arrary field is flagged
> as field-spanning, causing kernel warning. Switch to the C99 flexible
> array [] syntax to fix this.
>
> Changes:
> - _data_buf[0] -> _data_buf[] in struct krpc_completion
> - sync_resp[0] -> sync_resp[] in struct pcs_cs_iohdr
> - nodes[0] -> nodes[] in struct pcs_cs_map_prop
> - cs[0] -> cs[] in struct pcs_cs_list
> - cs[0] -> cs[] in struct pcs_ioc_getmap
>
> Link: https://virtuozzo.atlassian.net/browse/VSTOR-130548
>
> Signed-off-by: Liu Kui <kui.liu at virtuozzo.com>
> ---
...
> diff --git a/fs/fuse/kio/pcs/pcs_krpc.h b/fs/fuse/kio/pcs/pcs_krpc.h
> index 6a090ef66185..d5a7a56d84c8 100644
> --- a/fs/fuse/kio/pcs/pcs_krpc.h
> +++ b/fs/fuse/kio/pcs/pcs_krpc.h
> @@ -99,7 +99,7 @@ struct krpc_completion {
>
> void *private;
> int data_len;
> - u8 _data_buf[0];
> + u8 _data_buf[];
> };
struct krpc_completion is embedded in struct krpc_req as a non-last member:
fs/fuse/kio/pcs/pcs_krpc.h lines 134-137
struct krpc_completion completion;
u32 gen;
struct llist_node llist_link;
A struct with a C99 flexible array member embedded as a non-last member of another struct is formally
undefined behavior. GCC's zero-length array extension [0] handled this correctly, but [] should
trigger warnings.
May be the compiler is very smart and detects that _data_buf is not used when struct krpc_completion
is embedded into struct krpc_req, but i think it's quite error prone.
May be better just to move struct krpc_completion to the end of struct krpc_req ?
Also, minor typo in the commit message: "arrary" should be "array".
>
> #define KRPC_MAX_DATA_PAGES 256
> diff --git a/fs/fuse/kio/pcs/pcs_map.h b/fs/fuse/kio/pcs/pcs_map.h
> index bf8a0e7177d0..788a8cb16d8e 100644
> --- a/fs/fuse/kio/pcs/pcs_map.h
> +++ b/fs/fuse/kio/pcs/pcs_map.h
> @@ -127,7 +127,7 @@ struct pcs_cs_list
> int write_timeout;
> int nsrv;
> PCS_MAP_VERSION_T version; /* version inherented from map */
> - struct pcs_cs_record cs[0];
> + struct pcs_cs_record cs[];
> };
>
> /* TODO, LOCKING!!!!!
More information about the Devel
mailing list