gfs2: Another gfs2_walk_metadata fix

Make sure we don't walk past the end of the metadata in gfs2_walk_metadata: the
inode holds fewer pointers than indirect blocks.

Slightly clean up gfs2_iomap_get.

Fixes: a27a0c9b6a ("gfs2: gfs2_walk_metadata fix")
Cc: stable@vger.kernel.org # v5.3+
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
This commit is contained in:
Andreas Gruenbacher
2020-04-20 19:42:04 +02:00
parent d22f69a08d
commit 566a2ab3c9

View File

@@ -528,10 +528,12 @@ lower_metapath:
/* Advance in metadata tree. */ /* Advance in metadata tree. */
(mp->mp_list[hgt])++; (mp->mp_list[hgt])++;
if (mp->mp_list[hgt] >= sdp->sd_inptrs) { if (hgt) {
if (!hgt) if (mp->mp_list[hgt] >= sdp->sd_inptrs)
break;
goto lower_metapath; goto lower_metapath;
} else {
if (mp->mp_list[hgt] >= sdp->sd_diptrs)
break;
} }
fill_up_metapath: fill_up_metapath:
@@ -876,10 +878,9 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
ret = -ENOENT; ret = -ENOENT;
goto unlock; goto unlock;
} else { } else {
/* report a hole */
iomap->offset = pos; iomap->offset = pos;
iomap->length = length; iomap->length = length;
goto do_alloc; goto hole_found;
} }
} }
iomap->length = size; iomap->length = size;
@@ -933,8 +934,6 @@ unlock:
return ret; return ret;
do_alloc: do_alloc:
iomap->addr = IOMAP_NULL_ADDR;
iomap->type = IOMAP_HOLE;
if (flags & IOMAP_REPORT) { if (flags & IOMAP_REPORT) {
if (pos >= size) if (pos >= size)
ret = -ENOENT; ret = -ENOENT;
@@ -956,6 +955,9 @@ do_alloc:
if (pos < size && height == ip->i_height) if (pos < size && height == ip->i_height)
ret = gfs2_hole_size(inode, lblock, len, mp, iomap); ret = gfs2_hole_size(inode, lblock, len, mp, iomap);
} }
hole_found:
iomap->addr = IOMAP_NULL_ADDR;
iomap->type = IOMAP_HOLE;
goto out; goto out;
} }