]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: refactor file range validation
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 7 Jan 2021 20:59:17 +0000 (15:59 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 7 Jan 2021 20:59:17 +0000 (15:59 -0500)
Source kernel commit: 33005fd0a537501111fc97ec330b721388c6b451

Refactor all the open-coded validation of file block ranges into a
single helper, and teach the bmap scrubber to check the ranges.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_bmap.c
libxfs/xfs_types.c
libxfs/xfs_types.h

index 96fadc8f5c1d31753d6a79ce49d47483f1753520..458085e3479a857738feb588683b04fd57d22829 100644 (file)
@@ -6220,7 +6220,7 @@ xfs_bmap_validate_extent(
 {
        struct xfs_mount        *mp = ip->i_mount;
 
-       if (irec->br_startoff + irec->br_blockcount <= irec->br_startoff)
+       if (!xfs_verify_fileext(mp, irec->br_startoff, irec->br_blockcount))
                return __this_address;
 
        if (XFS_IS_REALTIME_INODE(ip) && whichfork == XFS_DATA_FORK) {
index 9d25de6bdfab73233ed7bdeac14130900c0028e3..af9f6343499f44d4ce9c91cb819e787652dc9681 100644 (file)
@@ -258,3 +258,28 @@ xfs_verify_dablk(
 
        return dabno <= max_dablk;
 }
+
+/* Check that a file block offset does not exceed the maximum. */
+bool
+xfs_verify_fileoff(
+       struct xfs_mount        *mp,
+       xfs_fileoff_t           off)
+{
+       return off <= XFS_MAX_FILEOFF;
+}
+
+/* Check that a range of file block offsets do not exceed the maximum. */
+bool
+xfs_verify_fileext(
+       struct xfs_mount        *mp,
+       xfs_fileoff_t           off,
+       xfs_fileoff_t           len)
+{
+       if (off + len <= off)
+               return false;
+
+       if (!xfs_verify_fileoff(mp, off))
+               return false;
+
+       return xfs_verify_fileoff(mp, off + len - 1);
+}
index 18e83ce465681513c0f92bb6ac9aef82ed0fa620..064bd6e8c922f74836b5eafba805e6ab6a472df6 100644 (file)
@@ -203,5 +203,8 @@ bool xfs_verify_icount(struct xfs_mount *mp, unsigned long long icount);
 bool xfs_verify_dablk(struct xfs_mount *mp, xfs_fileoff_t off);
 void xfs_icount_range(struct xfs_mount *mp, unsigned long long *min,
                unsigned long long *max);
+bool xfs_verify_fileoff(struct xfs_mount *mp, xfs_fileoff_t off);
+bool xfs_verify_fileext(struct xfs_mount *mp, xfs_fileoff_t off,
+               xfs_fileoff_t len);
 
 #endif /* __XFS_TYPES_H__ */