From 6b3176d3e7467c2b00f29115f7bb6bfdcbd30c93 Mon Sep 17 00:00:00 2001 From: Bruno Faccini Date: Fri, 7 Jun 2024 11:22:44 +0200 Subject: [PATCH] LU-17911 lustre: fix faked flexible arrays in getinfo_fid2path faked (0-length) flexible arrays need some rework to comply with new coding rules to stay Fortify feature compliant (see document at https://people.kernel.org/kees/bounded-flexible-arrays-in-c). With this particular getinfo_fid2path struct content, we ended-up with generated code causing straight crash upon each call of lmv_fid2path routine upon strlen() first call. Lustre-change: https://review.whamcloud.com/55354 Lustre-commit: 3eb2f75836e822cdf411823330c36ba13f2339ee Signed-off-by: Bruno Faccini Change-Id: Id6f594779ca0ae86f0c2842535abccbf4df688d3 Reviewed-by: Andreas Dilger Reviewed-by: Aurelien Degremont Reviewed-by: James Simmons Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/55533 Tested-by: jenkins Tested-by: Maloo --- lustre/include/uapi/linux/lustre/lustre_idl.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lustre/include/uapi/linux/lustre/lustre_idl.h b/lustre/include/uapi/linux/lustre/lustre_idl.h index dceff6a..dc57a9a 100644 --- a/lustre/include/uapi/linux/lustre/lustre_idl.h +++ b/lustre/include/uapi/linux/lustre/lustre_idl.h @@ -123,6 +123,29 @@ extern "C" { /* #define DVS_PORTAL 63 */ /* reserved for Cray DVS - spitzcor@cray.com, roe@cray.com, n8851@cray.com */ +#ifndef DECLARE_FLEX_ARRAY +#ifdef __cplusplus +/* sizeof(struct{}) is 1 in C++, not 0, can't use C version of the macro. */ +#define DECLARE_FLEX_ARRAY(T, member) T member[0] +#else +/** + * DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union + * + * @TYPE: The type of each flexible array element + * @NAME: The name of the flexible array member + * + * In order to have a flexible array member in a union or alone in a + * struct, it needs to be wrapped in an anonymous struct with at least 1 + * named member, but that member can be empty. + */ +#define DECLARE_FLEX_ARRAY(TYPE, NAME) \ + struct { \ + struct { } __empty_ ## NAME; \ + TYPE NAME[]; \ + } +#endif +#endif /* DECLARE_FLEX_ARRAY */ + /** * Describes a range of sequence, lsr_start is included but lsr_end is * not in the range. @@ -3401,8 +3424,8 @@ struct getinfo_fid2path { __u32 gf_linkno; __u32 gf_pathlen; union { - char gf_path[0]; - struct lu_fid gf_root_fid[0]; + DECLARE_FLEX_ARRAY(char, gf_path); + DECLARE_FLEX_ARRAY(struct lu_fid, gf_root_fid); } gf_u; } __attribute__((packed)); -- 1.8.3.1