Skip to content

Commit c36a71b

Browse files
harshadjstytso
authored andcommitted
ext4: fix EXT_MAX_EXTENT/INDEX to check for zeroed eh_max
If eh->eh_max is 0, EXT_MAX_EXTENT/INDEX would evaluate to unsigned (-1) resulting in illegal memory accesses. Although there is no consistent repro, we see that generic/019 sometimes crashes because of this bug. Ran gce-xfstests smoke and verified that there were no regressions. Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com> Link: https://lore.kernel.org/r/20200421023959.20879-2-harshadshirwadkar@gmail.com Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@kernel.org
1 parent 39c0ae1 commit c36a71b

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎fs/ext4/ext4_extents.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,13 @@ struct partial_cluster {
170170
(EXT_FIRST_EXTENT((__hdr__)) + le16_to_cpu((__hdr__)->eh_entries) - 1)
171171
#define EXT_LAST_INDEX(__hdr__) \
172172
(EXT_FIRST_INDEX((__hdr__)) + le16_to_cpu((__hdr__)->eh_entries) - 1)
173-
#define EXT_MAX_EXTENT(__hdr__) \
174-
(EXT_FIRST_EXTENT((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1)
173+
#define EXT_MAX_EXTENT(__hdr__) \
174+
((le16_to_cpu((__hdr__)->eh_max)) ? \
175+
((EXT_FIRST_EXTENT((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1)) \
176+
: 0)
175177
#define EXT_MAX_INDEX(__hdr__) \
176-
(EXT_FIRST_INDEX((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1)
178+
((le16_to_cpu((__hdr__)->eh_max)) ? \
179+
((EXT_FIRST_INDEX((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1)) : 0)
177180

178181
static inline struct ext4_extent_header *ext_inode_hdr(struct inode *inode)
179182
{

0 commit comments

Comments
 (0)