diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2017-12-22 16:14:34 -0500 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2018-01-02 13:16:32 -0500 |
commit | b4d8ad7fd3a18e6d92d4ebe858185c704604a57d (patch) | |
tree | 6c26c75b1a436f78f53b285c3ab676ea3098831f | |
parent | 3a3882ff26fbdbaf5f7e13f6a0bccfbf7121041d (diff) |
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 <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
-rw-r--r-- | fs/xfs/xfs_aops.c | 4 | ||||
-rw-r--r-- | fs/xfs/xfs_iomap.c | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 21e2d70884e1..4fc526a27a94 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c | |||
@@ -399,7 +399,7 @@ xfs_map_blocks( | |||
399 | (ip->i_df.if_flags & XFS_IFEXTENTS)); | 399 | (ip->i_df.if_flags & XFS_IFEXTENTS)); |
400 | ASSERT(offset <= mp->m_super->s_maxbytes); | 400 | ASSERT(offset <= mp->m_super->s_maxbytes); |
401 | 401 | ||
402 | if ((xfs_ufsize_t)offset + count > mp->m_super->s_maxbytes) | 402 | if (offset > mp->m_super->s_maxbytes - count) |
403 | count = mp->m_super->s_maxbytes - offset; | 403 | count = mp->m_super->s_maxbytes - offset; |
404 | end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count); | 404 | end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count); |
405 | offset_fsb = XFS_B_TO_FSBT(mp, offset); | 405 | offset_fsb = XFS_B_TO_FSBT(mp, offset); |
@@ -1312,7 +1312,7 @@ xfs_get_blocks( | |||
1312 | lockmode = xfs_ilock_data_map_shared(ip); | 1312 | lockmode = xfs_ilock_data_map_shared(ip); |
1313 | 1313 | ||
1314 | ASSERT(offset <= mp->m_super->s_maxbytes); | 1314 | 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) |
1316 | size = mp->m_super->s_maxbytes - offset; | 1316 | size = mp->m_super->s_maxbytes - offset; |
1317 | end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + size); | 1317 | end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + size); |
1318 | offset_fsb = XFS_B_TO_FSBT(mp, offset); | 1318 | offset_fsb = XFS_B_TO_FSBT(mp, offset); |
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 7ab52a8bc0a9..66e1edbfb2b2 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c | |||
@@ -1006,7 +1006,7 @@ xfs_file_iomap_begin( | |||
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | ASSERT(offset <= mp->m_super->s_maxbytes); | 1008 | 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) |
1010 | length = mp->m_super->s_maxbytes - offset; | 1010 | length = mp->m_super->s_maxbytes - offset; |
1011 | offset_fsb = XFS_B_TO_FSBT(mp, offset); | 1011 | offset_fsb = XFS_B_TO_FSBT(mp, offset); |
1012 | end_fsb = XFS_B_TO_FSB(mp, offset + length); | 1012 | end_fsb = XFS_B_TO_FSB(mp, offset + length); |