Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocfs2: replace zero-length arrays with DECLARE_FLEX_ARRAY() helper

Zero-length arrays are deprecated and we are moving towards adopting C99
flexible-array members, instead. So, replace zero-length array
declarations in a couple of structures and unions with the new
DECLARE_FLEX_ARRAY() helper macro.

This helper allows for a flexible-array member in a union and as only
member in a structure.

Also, this addresses multiple warnings reported when building with
Clang-15 and -Wzero-length-array.

Lastly, this will also help memcpy (in a coming hardening update) execute
proper bounds-checking on variable length object i_symlink at
fs/ocfs2/namei.c:1973:

fs/ocfs2/namei.c:
1973 memcpy((char *) fe->id2.i_symlink, symname, l);

Link: https://github.com/KSPP/linux/issues/21
Link: https://github.com/KSPP/linux/issues/193
Link: https://github.com/KSPP/linux/issues/197
Link: https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
Link: https://lkml.kernel.org/r/YxKY6O2hmdwNh8r8@work
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Gang He <ghe@suse.com>
Cc: Jun Piao <piaojun@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Gustavo A. R. Silva and committed by
Andrew Morton
6e4a53ee b8147511

+4 -4
+4 -4
fs/ocfs2/ocfs2_fs.h
··· 527 527 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty. 528 528 */ 529 529 struct ocfs2_slot_map { 530 - /*00*/ __le16 sm_slots[0]; 530 + /*00*/ DECLARE_FLEX_ARRAY(__le16, sm_slots); 531 531 /* 532 532 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255, 533 533 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize. ··· 548 548 * i_size. 549 549 */ 550 550 struct ocfs2_slot_map_extended { 551 - /*00*/ struct ocfs2_extended_slot se_slots[0]; 551 + /*00*/ DECLARE_FLEX_ARRAY(struct ocfs2_extended_slot, se_slots); 552 552 /* 553 553 * Actual size is i_size of the slot_map system file. It should 554 554 * match s_max_slots * sizeof(struct ocfs2_extended_slot) ··· 727 727 struct ocfs2_extent_list i_list; 728 728 struct ocfs2_truncate_log i_dealloc; 729 729 struct ocfs2_inline_data i_data; 730 - __u8 i_symlink[0]; 730 + DECLARE_FLEX_ARRAY(__u8, i_symlink); 731 731 } id2; 732 732 /* Actual on-disk size is one block */ 733 733 }; ··· 892 892 /*30*/ struct ocfs2_block_check bg_check; /* Error checking */ 893 893 __le64 bg_reserved2; 894 894 /*40*/ union { 895 - __u8 bg_bitmap[0]; 895 + DECLARE_FLEX_ARRAY(__u8, bg_bitmap); 896 896 struct { 897 897 /* 898 898 * Block groups may be discontiguous when