Skip to content

Commit 1faa3ab

Browse files
committed
gfs2: Fix invalid metadata access in punch_hole
jira LE-1907 Rebuild_History Non-Buildable kernel-3.10.0-1160.118.1.el7 commit-author Andrew Price <anprice@redhat.com> commit c95346a In punch_hole(), when the offset lies in the final block for a given height, there is no hole to punch, but the maximum size check fails to detect that. Consequently, punch_hole() will try to punch a hole beyond the end of the metadata and fail. Fix the maximum size check. Signed-off-by: Andrew Price <anprice@redhat.com> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> (cherry picked from commit c95346a) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent ebbc3de commit 1faa3ab

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/gfs2/bmap.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,8 @@ static int punch_hole(struct gfs2_inode *ip, u64 offset, u64 length)
17591759
struct buffer_head *dibh, *bh;
17601760
struct gfs2_holder rd_gh;
17611761
unsigned int bsize_shift = sdp->sd_sb.sb_bsize_shift;
1762-
u64 lblock = (offset + (1 << bsize_shift) - 1) >> bsize_shift;
1762+
unsigned int bsize = 1 << bsize_shift;
1763+
u64 lblock = (offset + bsize - 1) >> bsize_shift;
17631764
__u16 start_list[GFS2_MAX_META_HEIGHT];
17641765
__u16 __end_list[GFS2_MAX_META_HEIGHT], *end_list = NULL;
17651766
unsigned int start_aligned, uninitialized_var(end_aligned);
@@ -1770,7 +1771,7 @@ static int punch_hole(struct gfs2_inode *ip, u64 offset, u64 length)
17701771
u64 prev_bnr = 0;
17711772
__be64 *start, *end;
17721773

1773-
if (offset >= maxsize) {
1774+
if (offset + bsize - 1 >= maxsize) {
17741775
/*
17751776
* The starting point lies beyond the allocated meta-data;
17761777
* there are no blocks do deallocate.

0 commit comments

Comments
 (0)