Skip to content

Commit c95346a

Browse files
andypriceAndreas Gruenbacher
authored andcommitted
gfs2: Fix invalid metadata access in punch_hole
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 <[email protected]> Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent e8f897f commit c95346a

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
@@ -1718,7 +1718,8 @@ static int punch_hole(struct gfs2_inode *ip, u64 offset, u64 length)
17181718
struct buffer_head *dibh, *bh;
17191719
struct gfs2_holder rd_gh;
17201720
unsigned int bsize_shift = sdp->sd_sb.sb_bsize_shift;
1721-
u64 lblock = (offset + (1 << bsize_shift) - 1) >> bsize_shift;
1721+
unsigned int bsize = 1 << bsize_shift;
1722+
u64 lblock = (offset + bsize - 1) >> bsize_shift;
17221723
__u16 start_list[GFS2_MAX_META_HEIGHT];
17231724
__u16 __end_list[GFS2_MAX_META_HEIGHT], *end_list = NULL;
17241725
unsigned int start_aligned, end_aligned;
@@ -1729,7 +1730,7 @@ static int punch_hole(struct gfs2_inode *ip, u64 offset, u64 length)
17291730
u64 prev_bnr = 0;
17301731
__be64 *start, *end;
17311732

1732-
if (offset >= maxsize) {
1733+
if (offset + bsize - 1 >= maxsize) {
17331734
/*
17341735
* The starting point lies beyond the allocated metadata;
17351736
* there are no blocks to deallocate.

0 commit comments

Comments
 (0)