Skip to content

Commit 4d8cbf6

Browse files
fs: omfs: Use flexible-array member in struct omfs_extent
Memory for 'struct omfs_extent' and a 'e_extent_count' number of extent entries is indirectly allocated through 'bh->b_data', which is a pointer to data within the page. This implies that the member 'e_entry' (which is the start of extent entries) functions more like an array than a single object of type 'struct omfs_extent_entry'. So we better turn this object into a proper array, in this case a flexible-array member, and with that, fix the following -Wstringop-overflow warning seen after building s390 architecture with allyesconfig (GCC 13): fs/omfs/file.c: In function 'omfs_grow_extent': include/linux/fortify-string.h:57:33: warning: writing 16 bytes into a region of size 0 [-Wstringop-overflow=] 57 | #define __underlying_memcpy __builtin_memcpy | ^ include/linux/fortify-string.h:648:9: note: in expansion of macro '__underlying_memcpy' 648 | __underlying_##op(p, q, __fortify_size); \ | ^~~~~~~~~~~~~ include/linux/fortify-string.h:693:26: note: in expansion of macro '__fortify_memcpy_chk' 693 | #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \ | ^~~~~~~~~~~~~~~~~~~~ fs/omfs/file.c:170:9: note: in expansion of macro 'memcpy' 170 | memcpy(terminator, entry, sizeof(struct omfs_extent_entry)); | ^~~~~~ In file included from fs/omfs/omfs.h:8, from fs/omfs/file.c:11: fs/omfs/omfs_fs.h:80:34: note: at offset 16 into destination object 'e_entry' of size 16 80 | struct omfs_extent_entry e_entry; /* start of extent entries */ | ^~~~~~~ There are some binary differences before and after changes, but this are expected due to the change in the size of 'struct omfs_extent' and the necessary adjusments. This helps with the ongoing efforts to globally enable -Wstringop-overflow. Link: KSPP#330 Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
1 parent 221a4b5 commit 4d8cbf6

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

fs/omfs/file.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static u32 omfs_max_extents(struct omfs_sb_info *sbi, int offset)
1414
{
1515
return (sbi->s_sys_blocksize - offset -
1616
sizeof(struct omfs_extent)) /
17-
sizeof(struct omfs_extent_entry) + 1;
17+
sizeof(struct omfs_extent_entry);
1818
}
1919

2020
void omfs_make_empty_table(struct buffer_head *bh, int offset)
@@ -24,8 +24,8 @@ void omfs_make_empty_table(struct buffer_head *bh, int offset)
2424
oe->e_next = ~cpu_to_be64(0ULL);
2525
oe->e_extent_count = cpu_to_be32(1),
2626
oe->e_fill = cpu_to_be32(0x22),
27-
oe->e_entry.e_cluster = ~cpu_to_be64(0ULL);
28-
oe->e_entry.e_blocks = ~cpu_to_be64(0ULL);
27+
oe->e_entry[0].e_cluster = ~cpu_to_be64(0ULL);
28+
oe->e_entry[0].e_blocks = ~cpu_to_be64(0ULL);
2929
}
3030

3131
int omfs_shrink_inode(struct inode *inode)
@@ -68,7 +68,7 @@ int omfs_shrink_inode(struct inode *inode)
6868

6969
last = next;
7070
next = be64_to_cpu(oe->e_next);
71-
entry = &oe->e_entry;
71+
entry = oe->e_entry;
7272

7373
/* ignore last entry as it is the terminator */
7474
for (; extent_count > 1; extent_count--) {
@@ -117,7 +117,7 @@ static int omfs_grow_extent(struct inode *inode, struct omfs_extent *oe,
117117
u64 *ret_block)
118118
{
119119
struct omfs_extent_entry *terminator;
120-
struct omfs_extent_entry *entry = &oe->e_entry;
120+
struct omfs_extent_entry *entry = oe->e_entry;
121121
struct omfs_sb_info *sbi = OMFS_SB(inode->i_sb);
122122
u32 extent_count = be32_to_cpu(oe->e_extent_count);
123123
u64 new_block = 0;
@@ -245,7 +245,7 @@ static int omfs_get_block(struct inode *inode, sector_t block,
245245

246246
extent_count = be32_to_cpu(oe->e_extent_count);
247247
next = be64_to_cpu(oe->e_next);
248-
entry = &oe->e_entry;
248+
entry = oe->e_entry;
249249

250250
if (extent_count > max_extents)
251251
goto out_brelse;

fs/omfs/omfs_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct omfs_extent {
7777
__be64 e_next; /* next extent table location */
7878
__be32 e_extent_count; /* total # extents in this table */
7979
__be32 e_fill;
80-
struct omfs_extent_entry e_entry; /* start of extent entries */
80+
struct omfs_extent_entry e_entry[]; /* start of extent entries */
8181
};
8282

8383
#endif

0 commit comments

Comments
 (0)