Skip to content

Commit b4d8ad7

Browse files
committed
xfs: fix s_maxbytes overflow problems
Fix some integer overflow problems if offset + count happen to be large enough to cause an integer overflow. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 3a3882f commit b4d8ad7

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

fs/xfs/xfs_aops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ xfs_map_blocks(
399399
(ip->i_df.if_flags & XFS_IFEXTENTS));
400400
ASSERT(offset <= mp->m_super->s_maxbytes);
401401

402-
if ((xfs_ufsize_t)offset + count > mp->m_super->s_maxbytes)
402+
if (offset > mp->m_super->s_maxbytes - count)
403403
count = mp->m_super->s_maxbytes - offset;
404404
end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count);
405405
offset_fsb = XFS_B_TO_FSBT(mp, offset);
@@ -1312,7 +1312,7 @@ xfs_get_blocks(
13121312
lockmode = xfs_ilock_data_map_shared(ip);
13131313

13141314
ASSERT(offset <= mp->m_super->s_maxbytes);
1315-
if ((xfs_ufsize_t)offset + size > mp->m_super->s_maxbytes)
1315+
if (offset > mp->m_super->s_maxbytes - size)
13161316
size = mp->m_super->s_maxbytes - offset;
13171317
end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + size);
13181318
offset_fsb = XFS_B_TO_FSBT(mp, offset);

fs/xfs/xfs_iomap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ xfs_file_iomap_begin(
10061006
}
10071007

10081008
ASSERT(offset <= mp->m_super->s_maxbytes);
1009-
if ((xfs_fsize_t)offset + length > mp->m_super->s_maxbytes)
1009+
if (offset > mp->m_super->s_maxbytes - length)
10101010
length = mp->m_super->s_maxbytes - offset;
10111011
offset_fsb = XFS_B_TO_FSBT(mp, offset);
10121012
end_fsb = XFS_B_TO_FSB(mp, offset + length);

0 commit comments

Comments
 (0)