summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2020-10-25 17:16:15 -0700
committerDarrick J. Wong <darrick.wong@oracle.com>2020-10-26 18:32:34 -0700
commit62de4d9443b11652ed3f12a11034397057f438ad (patch)
treeca78d6f8fa66dca52464ea8da3eafe0a83b93193 /fs
parentd98d6bd7327874d9fede9f46f24d1fc877febfeb (diff)
xfs: improve the code that checks recovered rmap intent items
The code that validates recovered rmap intent items is kind of a mess -- it doesn't use the standard xfs type validators, and it doesn't check for things that it should. Fix the validator function to use the standard validation helpers and look for more types of obvious errors. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/xfs/xfs_rmap_item.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/fs/xfs/xfs_rmap_item.c b/fs/xfs/xfs_rmap_item.c
index 3510f96027b8..33f8f7401be3 100644
--- a/fs/xfs/xfs_rmap_item.c
+++ b/fs/xfs/xfs_rmap_item.c
@@ -466,11 +466,11 @@ xfs_rui_validate_map(
struct xfs_mount *mp,
struct xfs_map_extent *rmap)
{
- xfs_fsblock_t startblock_fsb;
- bool op_ok;
+ xfs_fsblock_t end;
+
+ if (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS)
+ return false;
- startblock_fsb = XFS_BB_TO_FSB(mp,
- XFS_FSB_TO_DADDR(mp, rmap->me_startblock));
switch (rmap->me_flags & XFS_RMAP_EXTENT_TYPE_MASK) {
case XFS_RMAP_EXTENT_MAP:
case XFS_RMAP_EXTENT_MAP_SHARED:
@@ -480,17 +480,24 @@ xfs_rui_validate_map(
case XFS_RMAP_EXTENT_CONVERT_SHARED:
case XFS_RMAP_EXTENT_ALLOC:
case XFS_RMAP_EXTENT_FREE:
- op_ok = true;
break;
default:
- op_ok = false;
- break;
+ return false;
}
- if (!op_ok || startblock_fsb == 0 ||
- rmap->me_len == 0 ||
- startblock_fsb >= mp->m_sb.sb_dblocks ||
- rmap->me_len >= mp->m_sb.sb_agblocks ||
- (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS))
+
+ if (!xfs_verify_ino(mp, rmap->me_owner) &&
+ !XFS_RMAP_NON_INODE_OWNER(rmap->me_owner))
+ return false;
+
+ if (rmap->me_startoff + rmap->me_len <= rmap->me_startoff)
+ return false;
+
+ if (rmap->me_startblock + rmap->me_len <= rmap->me_startblock)
+ return false;
+
+ end = rmap->me_startblock + rmap->me_len - 1;
+ if (!xfs_verify_fsbno(mp, rmap->me_startblock) ||
+ !xfs_verify_fsbno(mp, end))
return false;
return true;