From 4920a934baf06a81157df90abb08225517352479 Mon Sep 17 00:00:00 2001 From: Jian Yu Date: Tue, 6 Aug 2024 09:42:45 -0700 Subject: [PATCH] LU-17794 lustre: replace 0-length arrays with flexible arrays (2/3) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch replaces 0-length arrays with flexible arrays to resolve the UBSAN array-index-out-of-bounds runtime warnings. Most replacement of 0-length arrays with flexible arrays requires no special handling. Simply removing the “0” in the array declaration is sufficient. 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. This was wrapped in Linux with the DECLARE_FLEX_ARRAY() macro. Test-Parameters: optional mdtcount=4 mdscount=2 \ clientdistro=ubuntu2404 testgroup=full-dne-part-1 Test-Parameters: optional mdtcount=4 mdscount=2 \ clientdistro=ubuntu2404 testgroup=full-dne-part-2 Test-Parameters: optional mdtcount=4 mdscount=2 \ clientdistro=ubuntu2404 testgroup=full-dne-part-3 Change-Id: I833bea287764005bd4b09cd2a6a008f527f897b3 Signed-off-by: Jian Yu Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55940 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Li Xi Reviewed-by: jsimmons Reviewed-by: Oleg Drokin --- lnet/include/lnet/socklnd.h | 4 +-- lnet/klnds/kfilnd/kfilnd.h | 2 +- lnet/klnds/o2iblnd/o2iblnd-idl.h | 4 +-- lnet/klnds/o2iblnd/o2iblnd.c | 6 ++-- lustre/doc/llapi_file_get_stripe.3 | 4 +-- lustre/doc/llapi_hsm_copytool_register.3 | 4 +-- lustre/include/lustre_export.h | 2 +- lustre/include/uapi/linux/lustre/lgss.h | 4 +-- lustre/include/uapi/linux/lustre/lustre_idl.h | 16 ++++----- .../include/uapi/linux/lustre/lustre_kernelcomm.h | 2 +- lustre/include/uapi/linux/lustre/lustre_user.h | 14 ++++---- lustre/obdclass/llog_swab.c | 2 +- lustre/osp/osp_internal.h | 2 +- lustre/ptlrpc/wiretest.c | 38 ++++++++++++---------- lustre/utils/wirecheck.c | 33 ++++++++++++------- lustre/utils/wiretest.c | 38 ++++++++++++---------- 16 files changed, 95 insertions(+), 80 deletions(-) diff --git a/lnet/include/lnet/socklnd.h b/lnet/include/lnet/socklnd.h index 45d1cf1..3dee1f4 100644 --- a/lnet/include/lnet/socklnd.h +++ b/lnet/include/lnet/socklnd.h @@ -23,7 +23,7 @@ struct ksock_hello_msg { __u64 kshm_dst_incarnation; /* destination's incarnation */ __u32 kshm_ctype; /* SOCKLND_CONN_* */ __u32 kshm_nips; /* always sent as zero */ - __u32 kshm_ips[0]; /* deprecated */ + __u32 kshm_ips[]; /* deprecated */ } __packed; struct ksock_hello_msg_nid4 { @@ -37,7 +37,7 @@ struct ksock_hello_msg_nid4 { __u64 kshm_dst_incarnation; /* destination's incarnation */ __u32 kshm_ctype; /* SOCKLND_CONN_* */ __u32 kshm_nips; /* sent as zero */ - __u32 kshm_ips[0]; /* deprecated */ + __u32 kshm_ips[]; /* deprecated */ } __packed; struct ksock_msg_hdr { diff --git a/lnet/klnds/kfilnd/kfilnd.h b/lnet/klnds/kfilnd/kfilnd.h index 6237a35..96b788e 100644 --- a/lnet/klnds/kfilnd/kfilnd.h +++ b/lnet/klnds/kfilnd/kfilnd.h @@ -477,7 +477,7 @@ struct kfilnd_immed_msg { struct lnet_hdr_nid4 hdr; /* Entire LNet message payload. */ - char payload[0]; + char payload[]; } __packed; /* Bulk request message header. */ diff --git a/lnet/klnds/o2iblnd/o2iblnd-idl.h b/lnet/klnds/o2iblnd/o2iblnd-idl.h index a486c93..e4fe212 100644 --- a/lnet/klnds/o2iblnd/o2iblnd-idl.h +++ b/lnet/klnds/o2iblnd/o2iblnd-idl.h @@ -29,7 +29,7 @@ struct kib_connparams { struct kib_immediate_msg { struct lnet_hdr_nid4 ibim_hdr; /* portals header */ - char ibim_payload[0];/* piggy-backed payload */ + char ibim_payload[]; /* piggy-backed payload */ } __packed; struct kib_rdma_frag { @@ -40,7 +40,7 @@ struct kib_rdma_frag { struct kib_rdma_desc { u32 rd_key; /* local/remote key */ u32 rd_nfrags; /* # fragments */ - struct kib_rdma_frag rd_frags[0]; /* buffer frags */ + struct kib_rdma_frag rd_frags[]; /* buffer frags */ } __packed; struct kib_putreq_msg { diff --git a/lnet/klnds/o2iblnd/o2iblnd.c b/lnet/klnds/o2iblnd/o2iblnd.c index 1655615..7f1faf8 100644 --- a/lnet/klnds/o2iblnd/o2iblnd.c +++ b/lnet/klnds/o2iblnd/o2iblnd.c @@ -3944,7 +3944,7 @@ static void ko2inlnd_assert_wire_constants(void) BUILD_BUG_ON((int)offsetof(struct kib_immediate_msg, ibim_hdr) != 0); BUILD_BUG_ON((int)sizeof(((struct kib_immediate_msg *)0)->ibim_hdr) != 72); BUILD_BUG_ON((int)offsetof(struct kib_immediate_msg, ibim_payload) != 72); - BUILD_BUG_ON((int)sizeof(((struct kib_immediate_msg *)0)->ibim_payload) != 0); + BUILD_BUG_ON((int)sizeof(*((struct kib_immediate_msg *)0)->ibim_payload) != 1); BUILD_BUG_ON((int)sizeof(struct kib_rdma_frag) != 12); BUILD_BUG_ON((int)offsetof(struct kib_rdma_frag, rf_nob) != 0); @@ -3958,7 +3958,7 @@ static void ko2inlnd_assert_wire_constants(void) BUILD_BUG_ON((int)offsetof(struct kib_rdma_desc, rd_nfrags) != 4); BUILD_BUG_ON((int)sizeof(((struct kib_rdma_desc *)0)->rd_nfrags) != 4); BUILD_BUG_ON((int)offsetof(struct kib_rdma_desc, rd_frags) != 8); - BUILD_BUG_ON((int)sizeof(((struct kib_rdma_desc *)0)->rd_frags) != 0); + BUILD_BUG_ON((int)sizeof(*((struct kib_rdma_desc *)0)->rd_frags) != 12); BUILD_BUG_ON((int)sizeof(struct kib_putreq_msg) != 80); BUILD_BUG_ON((int)offsetof(struct kib_putreq_msg, ibprm_hdr) != 0); @@ -4023,7 +4023,7 @@ static void ko2inlnd_assert_wire_constants(void) BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.immediate.ibim_hdr) != 48); BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.immediate.ibim_hdr) != 72); BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.immediate.ibim_payload) != 120); - BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.immediate.ibim_payload) != 0); + BUILD_BUG_ON((int)sizeof(*((struct kib_msg *)0)->ibm_u.immediate.ibim_payload) != 1); /* PUT req message */ BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.putreq.ibprm_hdr) != 48); diff --git a/lustre/doc/llapi_file_get_stripe.3 b/lustre/doc/llapi_file_get_stripe.3 index d3232fb..5d74b73 100644 --- a/lustre/doc/llapi_file_get_stripe.3 +++ b/lustre/doc/llapi_file_get_stripe.3 @@ -29,7 +29,7 @@ struct lov_user_md_v1 { __u32 lmm_stripe_size; __u16 lmm_stripe_count; __u16 lmm_stripe_offset; - struct lov_user_ost_data_v1 lmm_objects[0]; + struct lov_user_ost_data_v1 lmm_objects[]; } __attribute__((packed)); struct lov_user_md_v3 { @@ -41,7 +41,7 @@ struct lov_user_md_v3 { __u16 lmm_stripe_count; __u16 lmm_stripe_offset; char lmm_pool_name[LOV_MAXPOOLNAME + 1]; - struct lov_user_ost_data_v1 lmm_objects[0]; + struct lov_user_ost_data_v1 lmm_objects[]; } __attribute__((packed)); .fi diff --git a/lustre/doc/llapi_hsm_copytool_register.3 b/lustre/doc/llapi_hsm_copytool_register.3 index 01dee2a..b969aa0 100644 --- a/lustre/doc/llapi_hsm_copytool_register.3 +++ b/lustre/doc/llapi_hsm_copytool_register.3 @@ -94,7 +94,7 @@ struct hsm_action_list { __u64 hal_flags; __u32 hal_archive_id; /* which archive backend */ __u32 padding1; - char hal_fsname[0]; /* null\-terminated name of filesystem */ + char hal_fsname[]; /* null\-terminated name of filesystem */ }; struct hsm_action_item { @@ -105,7 +105,7 @@ struct hsm_action_item { struct hsm_extent hai_extent; /* byte range to operate on */ __u64 hai_cookie; /* action cookie from coordinator */ __u64 hai_gid; /* grouplock id */ - char hai_data[0]; /* variable length */ + char hai_data[]; /* variable length */ }; .ft P .fi diff --git a/lustre/include/lustre_export.h b/lustre/include/lustre_export.h index a86dfb2..2bd89e8 100644 --- a/lustre/include/lustre_export.h +++ b/lustre/include/lustre_export.h @@ -560,7 +560,7 @@ enum { struct kkuc_ct_data { __u32 kcd_magic; __u32 kcd_nr_archives; - __u32 kcd_archives[0]; + __u32 kcd_archives[]; }; /** @} export */ diff --git a/lustre/include/uapi/linux/lustre/lgss.h b/lustre/include/uapi/linux/lustre/lgss.h index 618e5a4..de0b172 100644 --- a/lustre/include/uapi/linux/lustre/lgss.h +++ b/lustre/include/uapi/linux/lustre/lgss.h @@ -96,7 +96,7 @@ struct rsi_downcall_data { /* sid_val contains in_handle, in_token, * out_handle, out_token */ - char sid_val[0]; + char sid_val[]; }; #define RSC_DOWNCALL_MAGIC 0x6d6dd62b @@ -123,7 +123,7 @@ struct rsc_downcall_data { __u32 scd_len; __u32 scd_padding; /* scd_val contains handle and context token */ - char scd_val[0]; + char scd_val[]; }; /* diff --git a/lustre/include/uapi/linux/lustre/lustre_idl.h b/lustre/include/uapi/linux/lustre/lustre_idl.h index b68389d..108fe2b 100644 --- a/lustre/include/uapi/linux/lustre/lustre_idl.h +++ b/lustre/include/uapi/linux/lustre/lustre_idl.h @@ -511,7 +511,7 @@ struct lu_dirpage { __u64 ldp_hash_end; __u32 ldp_flags; __u32 ldp_pad0; - struct lu_dirent ldp_entries[0]; + struct lu_dirent ldp_entries[]; }; enum lu_dirpage_flags { @@ -1245,7 +1245,7 @@ struct lov_mds_md_v1 { /* LOV EA mds/wire data (little-endian) */ /* lmm_stripe_count used to be __u32 */ __u16 lmm_stripe_count; /* num stripes in use for this object */ __u16 lmm_layout_gen; /* layout generation number */ - struct lov_ost_data_v1 lmm_objects[0]; /* per-stripe data */ + struct lov_ost_data_v1 lmm_objects[]; /* per-stripe data */ }; #define MAX_MD_SIZE_OLD (sizeof(struct lov_mds_md) + \ @@ -1303,7 +1303,7 @@ struct lov_mds_md_v3 { /* LOV EA mds/wire data (little-endian) */ __u16 lmm_stripe_count; /* num stripes in use for this object */ __u16 lmm_layout_gen; /* layout generation number */ char lmm_pool_name[LOV_MAXPOOLNAME + 1]; /* must be 32bit aligned */ - struct lov_ost_data_v1 lmm_objects[0]; /* per-stripe data */ + struct lov_ost_data_v1 lmm_objects[]; /* per-stripe data */ }; static inline __u32 lov_mds_md_size(__u16 stripes, __u32 lmm_magic) @@ -3436,7 +3436,7 @@ struct link_ea_header { struct link_ea_entry { unsigned char lee_reclen[2]; /* __u16 big-endian, unaligned */ unsigned char lee_parent_fid[sizeof(struct lu_fid)]; - char lee_name[0]; + char lee_name[]; } __attribute__((packed)); /** fid2path request/reply structure */ @@ -3746,11 +3746,11 @@ struct update_op { } __attribute__((packed)); struct update_ops { - struct update_op uops_op[0]; + DECLARE_FLEX_ARRAY(struct update_op, uops_op); }; struct update_params { - struct object_update_param up_params[0]; + DECLARE_FLEX_ARRAY(struct object_update_param, up_params); }; enum update_records_flag { @@ -3855,7 +3855,7 @@ enum nodemap_rbac_roles { */ typedef struct netobj_s { __u32 len; - __u8 data[0]; + __u8 data[]; } netobj_t; typedef struct rawobj_s { @@ -3946,7 +3946,7 @@ struct ladvise_hdr { __u32 lah_value1; /* unused */ __u32 lah_value2; /* unused */ __u64 lah_value3; /* unused */ - struct lu_ladvise lah_advise[0]; /* advices in this header */ + struct lu_ladvise lah_advise[]; /* advices in this header */ }; #if defined(__cplusplus) diff --git a/lustre/include/uapi/linux/lustre/lustre_kernelcomm.h b/lustre/include/uapi/linux/lustre/lustre_kernelcomm.h index fcb1af0..d4a0a77 100644 --- a/lustre/include/uapi/linux/lustre/lustre_kernelcomm.h +++ b/lustre/include/uapi/linux/lustre/lustre_kernelcomm.h @@ -111,7 +111,7 @@ struct lustre_kernelcomm { __u32 lk_group; __u32 lk_data_count; __u32 lk_flags; - __u32 lk_data[0]; + __u32 lk_data[]; } __attribute__((packed)); #endif /* __UAPI_KERNELCOMM_H__ */ diff --git a/lustre/include/uapi/linux/lustre/lustre_user.h b/lustre/include/uapi/linux/lustre/lustre_user.h index 0f1262a..7c6d2d3 100644 --- a/lustre/include/uapi/linux/lustre/lustre_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_user.h @@ -571,7 +571,7 @@ struct ll_ioc_lease { __u32 lil_mode; __u32 lil_flags; __u32 lil_count; - __u32 lil_ids[0]; + __u32 lil_ids[]; }; struct ll_ioc_lease_id { @@ -581,7 +581,7 @@ struct ll_ioc_lease_id { __u16 lil_mirror_id; __u16 lil_padding1; __u64 lil_padding2; - __u32 lil_ids[0]; + __u32 lil_ids[]; }; /* @@ -850,7 +850,7 @@ struct lov_user_md_v1 { /* LOV EA user data (host-endian) */ * used when reading */ }; - struct lov_user_ost_data_v1 lmm_objects[0]; /* per-stripe data */ + struct lov_user_ost_data_v1 lmm_objects[]; /* per-stripe data */ } __attribute__((packed, __may_alias__)); struct lov_user_md_v3 { /* LOV EA user data (host-endian) */ @@ -868,7 +868,7 @@ struct lov_user_md_v3 { /* LOV EA user data (host-endian) */ */ }; char lmm_pool_name[LOV_MAXPOOLNAME + 1]; /* pool name */ - struct lov_user_ost_data_v1 lmm_objects[0]; /* per-stripe data */ + struct lov_user_ost_data_v1 lmm_objects[]; /* per-stripe data */ } __attribute__((packed, __may_alias__)); struct lov_foreign_md { @@ -2538,7 +2538,7 @@ struct hsm_user_item { struct hsm_user_request { struct hsm_request hur_request; - struct hsm_user_item hur_user_item[0]; + struct hsm_user_item hur_user_item[]; /* extra data blob at end of struct (after all * hur_user_items), only use helpers to access it */ @@ -2608,7 +2608,7 @@ struct hsm_action_item { struct hsm_extent hai_extent; /* byte range to operate on */ __u64 hai_cookie; /* action cookie from coordinator */ __u64 hai_gid; /* grouplock id */ - char hai_data[0]; /* variable length */ + char hai_data[]; /* variable length */ } __attribute__((packed)); /** @@ -2837,7 +2837,7 @@ struct llapi_ladvise_hdr { __u32 lah_value1; /* unused */ __u32 lah_value2; /* unused */ __u64 lah_value3; /* unused */ - struct llapi_lu_ladvise lah_advise[0]; /* advices in this header */ + struct llapi_lu_ladvise lah_advise[]; /* advices in this header */ }; #define LAH_COUNT_MAX (1024) diff --git a/lustre/obdclass/llog_swab.c b/lustre/obdclass/llog_swab.c index a532276..49e8c3e 100644 --- a/lustre/obdclass/llog_swab.c +++ b/lustre/obdclass/llog_swab.c @@ -250,7 +250,7 @@ void lustre_swab_llog_rec(struct llog_rec_hdr *rec) __swab64s(&arr->arr_hai.hai_gid); /* * no swabing for opaque data - * hai_data[0]; + * hai_data[]; */ break; } diff --git a/lustre/osp/osp_internal.h b/lustre/osp/osp_internal.h index c1eecaa..85110ac 100644 --- a/lustre/osp/osp_internal.h +++ b/lustre/osp/osp_internal.h @@ -313,7 +313,7 @@ struct osp_xattr_entry { unsigned short oxe_exist:1, oxe_ready:1, oxe_largebuf:1; - char oxe_name[0]; + char oxe_name[]; }; /* this is a top object */ diff --git a/lustre/ptlrpc/wiretest.c b/lustre/ptlrpc/wiretest.c index 4292383..b81281b 100644 --- a/lustre/ptlrpc/wiretest.c +++ b/lustre/ptlrpc/wiretest.c @@ -814,8 +814,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_value3)); LASSERTF((int)offsetof(struct ladvise_hdr, lah_advise) == 32, "found %lld\n", (long long)(int)offsetof(struct ladvise_hdr, lah_advise)); - LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_advise) == 0, "found %lld\n", - (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_advise)); + LASSERTF((int)sizeof(*((struct ladvise_hdr *)0)->lah_advise) == 32, "found %lld\n", + (long long)(int)sizeof(*((struct ladvise_hdr *)0)->lah_advise)); BUILD_BUG_ON(LF_ASYNC != 0x00000001); BUILD_BUG_ON(LF_UNSET != 0x00000002); BUILD_BUG_ON(LADVISE_MAGIC != 0x1adf1ce0); @@ -4527,8 +4527,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct rsi_downcall_data *)0)->sid_hash)); LASSERTF((int)offsetof(struct rsi_downcall_data, sid_val) == 40, "found %lld\n", (long long)(int)offsetof(struct rsi_downcall_data, sid_val)); - LASSERTF((int)sizeof(((struct rsi_downcall_data *)0)->sid_val) == 0, "found %lld\n", - (long long)(int)sizeof(((struct rsi_downcall_data *)0)->sid_val)); + LASSERTF((int)sizeof(*((struct rsi_downcall_data *)0)->sid_val) == 1, "found %lld\n", + (long long)(int)sizeof(*((struct rsi_downcall_data *)0)->sid_val)); /* Checks for struct rsc_downcall_data */ LASSERTF((int)sizeof(struct rsc_downcall_data) == 48, "found %lld\n", @@ -4575,8 +4575,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct rsc_downcall_data *)0)->scd_padding)); LASSERTF((int)offsetof(struct rsc_downcall_data, scd_val) == 48, "found %lld\n", (long long)(int)offsetof(struct rsc_downcall_data, scd_val)); - LASSERTF((int)sizeof(((struct rsc_downcall_data *)0)->scd_val) == 0, "found %lld\n", - (long long)(int)sizeof(((struct rsc_downcall_data *)0)->scd_val)); + LASSERTF((int)sizeof(*((struct rsc_downcall_data *)0)->scd_val) == 1, "found %lld\n", + (long long)(int)sizeof(*((struct rsc_downcall_data *)0)->scd_val)); LASSERTF(RSC_DATA_FLAG_REMOTE == 0x00000001UL, "found 0x%.8xUL\n", (unsigned)RSC_DATA_FLAG_REMOTE); LASSERTF(RSC_DATA_FLAG_ROOT == 0x00000002UL, "found 0x%.8xUL\n", @@ -5114,8 +5114,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct link_ea_entry *)0)->lee_parent_fid)); LASSERTF((int)offsetof(struct link_ea_entry, lee_name) == 18, "found %lld\n", (long long)(int)offsetof(struct link_ea_entry, lee_name)); - LASSERTF((int)sizeof(((struct link_ea_entry *)0)->lee_name) == 0, "found %lld\n", - (long long)(int)sizeof(((struct link_ea_entry *)0)->lee_name)); + LASSERTF((int)sizeof(*((struct link_ea_entry *)0)->lee_name) == 1, "found %lld\n", + (long long)(int)sizeof(*((struct link_ea_entry *)0)->lee_name)); /* Checks for struct layout_intent */ LASSERTF((int)sizeof(struct layout_intent) == 24, "found %lld\n", @@ -5184,8 +5184,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct hsm_action_item *)0)->hai_gid)); LASSERTF((int)offsetof(struct hsm_action_item, hai_data) == 72, "found %lld\n", (long long)(int)offsetof(struct hsm_action_item, hai_data)); - LASSERTF((int)sizeof(((struct hsm_action_item *)0)->hai_data) == 0, "found %lld\n", - (long long)(int)sizeof(((struct hsm_action_item *)0)->hai_data)); + LASSERTF((int)sizeof(*((struct hsm_action_item *)0)->hai_data) == 1, "found %lld\n", + (long long)(int)sizeof(*((struct hsm_action_item *)0)->hai_data)); /* Checks for struct hsm_action_list */ LASSERTF((int)sizeof(struct hsm_action_list) == 32, "found %lld\n", @@ -5431,8 +5431,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct hsm_user_request *)0)->hur_request)); LASSERTF((int)offsetof(struct hsm_user_request, hur_user_item) == 24, "found %lld\n", (long long)(int)offsetof(struct hsm_user_request, hur_user_item)); - LASSERTF((int)sizeof(((struct hsm_user_request *)0)->hur_user_item) == 0, "found %lld\n", - (long long)(int)sizeof(((struct hsm_user_request *)0)->hur_user_item)); + LASSERTF((int)sizeof(*((struct hsm_user_request *)0)->hur_user_item) == 32, "found %lld\n", + (long long)(int)sizeof(*((struct hsm_user_request *)0)->hur_user_item)); /* Checks for struct hsm_user_import */ LASSERTF((int)sizeof(struct hsm_user_import) == 48, "found %lld\n", @@ -5485,8 +5485,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct netobj_s *)0)->len)); LASSERTF((int)offsetof(struct netobj_s, data) == 4, "found %lld\n", (long long)(int)offsetof(struct netobj_s, data)); - LASSERTF((int)sizeof(((struct netobj_s *)0)->data) == 0, "found %lld\n", - (long long)(int)sizeof(((struct netobj_s *)0)->data)); + LASSERTF((int)sizeof(*((struct netobj_s *)0)->data) == 1, "found %lld\n", + (long long)(int)sizeof(*((struct netobj_s *)0)->data)); /* Checks for struct rawobj_s */ LASSERTF((int)sizeof(struct rawobj_s) == 16, "found %lld\n", @@ -6792,8 +6792,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(struct update_params)); LASSERTF((int)offsetof(struct update_params, up_params) == 0, "found %lld\n", (long long)(int)offsetof(struct update_params, up_params)); - LASSERTF((int)sizeof(((struct update_params *)0)->up_params) == 0, "found %lld\n", - (long long)(int)sizeof(((struct update_params *)0)->up_params)); + LASSERTF((int)sizeof(*((struct update_params *)0)->up_params) == 8, "found %lld\n", + (long long)(int)sizeof(*((struct update_params *)0)->up_params)); /* Checks for struct update_op */ LASSERTF((int)sizeof(struct update_op) == 20, "found %lld\n", @@ -6812,14 +6812,16 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct update_op *)0)->uop_param_count)); LASSERTF((int)offsetof(struct update_op, uop_params_off) == 20, "found %lld\n", (long long)(int)offsetof(struct update_op, uop_params_off)); + LASSERTF((int)sizeof(*((struct update_op *)0)->uop_params_off) == 2, "found %lld\n", + (long long)(int)sizeof(*((struct update_op *)0)->uop_params_off)); /* Checks for struct update_ops */ LASSERTF((int)sizeof(struct update_ops) == 0, "found %lld\n", (long long)(int)sizeof(struct update_ops)); LASSERTF((int)offsetof(struct update_ops, uops_op) == 0, "found %lld\n", (long long)(int)offsetof(struct update_ops, uops_op)); - LASSERTF((int)sizeof(((struct update_ops *)0)->uops_op) == 0, "found %lld\n", - (long long)(int)sizeof(((struct update_ops *)0)->uops_op)); + LASSERTF((int)sizeof(*((struct update_ops *)0)->uops_op) == 20, "found %lld\n", + (long long)(int)sizeof(*((struct update_ops *)0)->uops_op)); /* Checks for struct update_records */ LASSERTF((int)sizeof(struct update_records) == 32, "found %lld\n", diff --git a/lustre/utils/wirecheck.c b/lustre/utils/wirecheck.c index 0799f77..9556d51 100644 --- a/lustre/utils/wirecheck.c +++ b/lustre/utils/wirecheck.c @@ -151,6 +151,11 @@ do { \ CHECK_VALUE((int)sizeof(((s *)0)->m)); \ } while(0) +#define CHECK_MEMBER_SIZEOF_ARRAY_ELEMENT_TYPEDEF(s, m) \ +do { \ + CHECK_VALUE((int)sizeof(*((s *)0)->m)); \ +} while (0) + #define CHECK_MEMBER_IS_FLEXIBLE(s, m) \ do { \ CHECK_MEMBER_OFFSET(s, m); \ @@ -170,6 +175,12 @@ do { \ CHECK_MEMBER_SIZEOF_TYPEDEF(s, m); \ } while(0) +#define CHECK_MEMBER_IS_FLEXIBLE_TYPEDEF(s, m) \ +do { \ + CHECK_MEMBER_OFFSET_TYPEDEF(s, m); \ + CHECK_MEMBER_SIZEOF_ARRAY_ELEMENT_TYPEDEF(s, m); \ +} while (0) + #define CHECK_STRUCT(s) \ do { \ COMMENT("Checks for struct "#s); \ @@ -418,7 +429,7 @@ check_ladvise_hdr(void) CHECK_MEMBER(ladvise_hdr, lah_value1); CHECK_MEMBER(ladvise_hdr, lah_value2); CHECK_MEMBER(ladvise_hdr, lah_value3); - CHECK_MEMBER(ladvise_hdr, lah_advise); + CHECK_MEMBER_IS_FLEXIBLE(ladvise_hdr, lah_advise); CHECK_CVALUE_X(LF_ASYNC); CHECK_CVALUE_X(LF_UNSET); @@ -2067,7 +2078,7 @@ check_rsi_downcall_data(void) CHECK_MEMBER(rsi_downcall_data, sid_len); CHECK_MEMBER(rsi_downcall_data, sid_offset); CHECK_MEMBER(rsi_downcall_data, sid_hash); - CHECK_MEMBER(rsi_downcall_data, sid_val); + CHECK_MEMBER_IS_FLEXIBLE(rsi_downcall_data, sid_val); } static void @@ -2085,7 +2096,7 @@ check_rsc_downcall_data(void) CHECK_MEMBER(rsc_downcall_data, scd_offset); CHECK_MEMBER(rsc_downcall_data, scd_len); CHECK_MEMBER(rsc_downcall_data, scd_padding); - CHECK_MEMBER(rsc_downcall_data, scd_val); + CHECK_MEMBER_IS_FLEXIBLE(rsc_downcall_data, scd_val); CHECK_VALUE_X(RSC_DATA_FLAG_REMOTE); CHECK_VALUE_X(RSC_DATA_FLAG_ROOT); @@ -2327,7 +2338,7 @@ typedef struct { typedef struct { __u32 a_version; - posix_acl_xattr_entry a_entries[0]; + posix_acl_xattr_entry a_entries[]; } posix_acl_xattr_header; static void @@ -2350,7 +2361,7 @@ check_posix_acl_xattr_header(void) CHECK_STRUCT_TYPEDEF(posix_acl_xattr_header); CHECK_MEMBER_TYPEDEF(posix_acl_xattr_header, a_version); printf("#ifndef HAVE_STRUCT_POSIX_ACL_XATTR\n"); - CHECK_MEMBER_TYPEDEF(posix_acl_xattr_header, a_entries); + CHECK_MEMBER_IS_FLEXIBLE_TYPEDEF(posix_acl_xattr_header, a_entries); printf("#endif /* HAVE_STRUCT_POSIX_ACL_XATTR */\n"); printf("#endif /* CONFIG_FS_POSIX_ACL */\n"); } @@ -2419,7 +2430,7 @@ check_link_ea_entry(void) CHECK_STRUCT(link_ea_entry); CHECK_MEMBER(link_ea_entry, lee_reclen); CHECK_MEMBER(link_ea_entry, lee_parent_fid); - CHECK_MEMBER(link_ea_entry, lee_name); + CHECK_MEMBER_IS_FLEXIBLE(link_ea_entry, lee_name); } static void @@ -2455,7 +2466,7 @@ check_hsm_action_item(void) CHECK_MEMBER(hsm_action_item, hai_extent); CHECK_MEMBER(hsm_action_item, hai_cookie); CHECK_MEMBER(hsm_action_item, hai_gid); - CHECK_MEMBER(hsm_action_item, hai_data); + CHECK_MEMBER_IS_FLEXIBLE(hsm_action_item, hai_data); } static void @@ -2585,7 +2596,7 @@ static void check_hsm_user_request(void) BLANK_LINE(); CHECK_STRUCT(hsm_user_request); CHECK_MEMBER(hsm_user_request, hur_request); - CHECK_MEMBER(hsm_user_request, hur_user_item); + CHECK_MEMBER_IS_FLEXIBLE(hsm_user_request, hur_user_item); } static void check_hsm_user_import(void) @@ -2608,7 +2619,7 @@ static void check_netobj_s(void) BLANK_LINE(); CHECK_STRUCT(netobj_s); CHECK_MEMBER(netobj_s, len); - CHECK_MEMBER(netobj_s, data); + CHECK_MEMBER_IS_FLEXIBLE(netobj_s, data); } static void check_rawobj_s(void) @@ -3168,7 +3179,7 @@ static void check_update_params(void) { BLANK_LINE(); CHECK_STRUCT(update_params); - CHECK_MEMBER(update_params, up_params); + CHECK_MEMBER_IS_FLEXIBLE(update_params, up_params); } static void check_update_op(void) @@ -3185,7 +3196,7 @@ static void check_update_ops(void) { BLANK_LINE(); CHECK_STRUCT(update_ops); - CHECK_MEMBER(update_ops, uops_op); + CHECK_MEMBER_IS_FLEXIBLE(update_ops, uops_op); } static void check_update_records(void) diff --git a/lustre/utils/wiretest.c b/lustre/utils/wiretest.c index 0876eda..750a2b9 100644 --- a/lustre/utils/wiretest.c +++ b/lustre/utils/wiretest.c @@ -839,8 +839,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_value3)); LASSERTF((int)offsetof(struct ladvise_hdr, lah_advise) == 32, "found %lld\n", (long long)(int)offsetof(struct ladvise_hdr, lah_advise)); - LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_advise) == 0, "found %lld\n", - (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_advise)); + LASSERTF((int)sizeof(*((struct ladvise_hdr *)0)->lah_advise) == 32, "found %lld\n", + (long long)(int)sizeof(*((struct ladvise_hdr *)0)->lah_advise)); BUILD_BUG_ON(LF_ASYNC != 0x00000001); BUILD_BUG_ON(LF_UNSET != 0x00000002); BUILD_BUG_ON(LADVISE_MAGIC != 0x1adf1ce0); @@ -4552,8 +4552,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct rsi_downcall_data *)0)->sid_hash)); LASSERTF((int)offsetof(struct rsi_downcall_data, sid_val) == 40, "found %lld\n", (long long)(int)offsetof(struct rsi_downcall_data, sid_val)); - LASSERTF((int)sizeof(((struct rsi_downcall_data *)0)->sid_val) == 0, "found %lld\n", - (long long)(int)sizeof(((struct rsi_downcall_data *)0)->sid_val)); + LASSERTF((int)sizeof(*((struct rsi_downcall_data *)0)->sid_val) == 1, "found %lld\n", + (long long)(int)sizeof(*((struct rsi_downcall_data *)0)->sid_val)); /* Checks for struct rsc_downcall_data */ LASSERTF((int)sizeof(struct rsc_downcall_data) == 48, "found %lld\n", @@ -4600,8 +4600,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct rsc_downcall_data *)0)->scd_padding)); LASSERTF((int)offsetof(struct rsc_downcall_data, scd_val) == 48, "found %lld\n", (long long)(int)offsetof(struct rsc_downcall_data, scd_val)); - LASSERTF((int)sizeof(((struct rsc_downcall_data *)0)->scd_val) == 0, "found %lld\n", - (long long)(int)sizeof(((struct rsc_downcall_data *)0)->scd_val)); + LASSERTF((int)sizeof(*((struct rsc_downcall_data *)0)->scd_val) == 1, "found %lld\n", + (long long)(int)sizeof(*((struct rsc_downcall_data *)0)->scd_val)); LASSERTF(RSC_DATA_FLAG_REMOTE == 0x00000001UL, "found 0x%.8xUL\n", (unsigned)RSC_DATA_FLAG_REMOTE); LASSERTF(RSC_DATA_FLAG_ROOT == 0x00000002UL, "found 0x%.8xUL\n", @@ -5139,8 +5139,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct link_ea_entry *)0)->lee_parent_fid)); LASSERTF((int)offsetof(struct link_ea_entry, lee_name) == 18, "found %lld\n", (long long)(int)offsetof(struct link_ea_entry, lee_name)); - LASSERTF((int)sizeof(((struct link_ea_entry *)0)->lee_name) == 0, "found %lld\n", - (long long)(int)sizeof(((struct link_ea_entry *)0)->lee_name)); + LASSERTF((int)sizeof(*((struct link_ea_entry *)0)->lee_name) == 1, "found %lld\n", + (long long)(int)sizeof(*((struct link_ea_entry *)0)->lee_name)); /* Checks for struct layout_intent */ LASSERTF((int)sizeof(struct layout_intent) == 24, "found %lld\n", @@ -5209,8 +5209,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct hsm_action_item *)0)->hai_gid)); LASSERTF((int)offsetof(struct hsm_action_item, hai_data) == 72, "found %lld\n", (long long)(int)offsetof(struct hsm_action_item, hai_data)); - LASSERTF((int)sizeof(((struct hsm_action_item *)0)->hai_data) == 0, "found %lld\n", - (long long)(int)sizeof(((struct hsm_action_item *)0)->hai_data)); + LASSERTF((int)sizeof(*((struct hsm_action_item *)0)->hai_data) == 1, "found %lld\n", + (long long)(int)sizeof(*((struct hsm_action_item *)0)->hai_data)); /* Checks for struct hsm_action_list */ LASSERTF((int)sizeof(struct hsm_action_list) == 32, "found %lld\n", @@ -5456,8 +5456,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct hsm_user_request *)0)->hur_request)); LASSERTF((int)offsetof(struct hsm_user_request, hur_user_item) == 24, "found %lld\n", (long long)(int)offsetof(struct hsm_user_request, hur_user_item)); - LASSERTF((int)sizeof(((struct hsm_user_request *)0)->hur_user_item) == 0, "found %lld\n", - (long long)(int)sizeof(((struct hsm_user_request *)0)->hur_user_item)); + LASSERTF((int)sizeof(*((struct hsm_user_request *)0)->hur_user_item) == 32, "found %lld\n", + (long long)(int)sizeof(*((struct hsm_user_request *)0)->hur_user_item)); /* Checks for struct hsm_user_import */ LASSERTF((int)sizeof(struct hsm_user_import) == 48, "found %lld\n", @@ -5510,8 +5510,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct netobj_s *)0)->len)); LASSERTF((int)offsetof(struct netobj_s, data) == 4, "found %lld\n", (long long)(int)offsetof(struct netobj_s, data)); - LASSERTF((int)sizeof(((struct netobj_s *)0)->data) == 0, "found %lld\n", - (long long)(int)sizeof(((struct netobj_s *)0)->data)); + LASSERTF((int)sizeof(*((struct netobj_s *)0)->data) == 1, "found %lld\n", + (long long)(int)sizeof(*((struct netobj_s *)0)->data)); /* Checks for struct rawobj_s */ LASSERTF((int)sizeof(struct rawobj_s) == 16, "found %lld\n", @@ -6817,8 +6817,8 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(struct update_params)); LASSERTF((int)offsetof(struct update_params, up_params) == 0, "found %lld\n", (long long)(int)offsetof(struct update_params, up_params)); - LASSERTF((int)sizeof(((struct update_params *)0)->up_params) == 0, "found %lld\n", - (long long)(int)sizeof(((struct update_params *)0)->up_params)); + LASSERTF((int)sizeof(*((struct update_params *)0)->up_params) == 8, "found %lld\n", + (long long)(int)sizeof(*((struct update_params *)0)->up_params)); /* Checks for struct update_op */ LASSERTF((int)sizeof(struct update_op) == 20, "found %lld\n", @@ -6837,14 +6837,16 @@ void lustre_assert_wire_constants(void) (long long)(int)sizeof(((struct update_op *)0)->uop_param_count)); LASSERTF((int)offsetof(struct update_op, uop_params_off) == 20, "found %lld\n", (long long)(int)offsetof(struct update_op, uop_params_off)); + LASSERTF((int)sizeof(*((struct update_op *)0)->uop_params_off) == 2, "found %lld\n", + (long long)(int)sizeof(*((struct update_op *)0)->uop_params_off)); /* Checks for struct update_ops */ LASSERTF((int)sizeof(struct update_ops) == 0, "found %lld\n", (long long)(int)sizeof(struct update_ops)); LASSERTF((int)offsetof(struct update_ops, uops_op) == 0, "found %lld\n", (long long)(int)offsetof(struct update_ops, uops_op)); - LASSERTF((int)sizeof(((struct update_ops *)0)->uops_op) == 0, "found %lld\n", - (long long)(int)sizeof(((struct update_ops *)0)->uops_op)); + LASSERTF((int)sizeof(*((struct update_ops *)0)->uops_op) == 20, "found %lld\n", + (long long)(int)sizeof(*((struct update_ops *)0)->uops_op)); /* Checks for struct update_records */ LASSERTF((int)sizeof(struct update_records) == 32, "found %lld\n", -- 1.8.3.1