Skip to content

Commit

Permalink
xfs: overflow in xfs_iomap_eof_align_last_fsb
Browse files Browse the repository at this point in the history
If extsize is set and new_last_fsb is larger than 32 bits, the
roundup to extsize will overflow the align variable. Instead,
combine alignments by rounding stripe size up to extsize.

Signed-off-by: Peter Watkins <treestem@gmail.com>
Reviewed-by: Nathaniel W. Turner <nate@houseofnate.net>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
  • Loading branch information
treestem authored and dchinner committed Dec 3, 2014
1 parent e77b854 commit 76b5730
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions fs/xfs/xfs_iomap.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ xfs_iomap_eof_align_last_fsb(
xfs_extlen_t extsize,
xfs_fileoff_t *last_fsb)
{
xfs_fileoff_t new_last_fsb = 0;
xfs_extlen_t align = 0;
int eof, error;

Expand All @@ -70,23 +69,23 @@ xfs_iomap_eof_align_last_fsb(
else if (mp->m_dalign)
align = mp->m_dalign;

if (align && XFS_ISIZE(ip) >= XFS_FSB_TO_B(mp, align))
new_last_fsb = roundup_64(*last_fsb, align);
if (align && XFS_ISIZE(ip) < XFS_FSB_TO_B(mp, align))
align = 0;
}

/*
* Always round up the allocation request to an extent boundary
* (when file on a real-time subvolume or has di_extsize hint).
*/
if (extsize) {
if (new_last_fsb)
align = roundup_64(new_last_fsb, extsize);
if (align)
align = roundup_64(align, extsize);
else
align = extsize;
new_last_fsb = roundup_64(*last_fsb, align);
}

if (new_last_fsb) {
if (align) {
xfs_fileoff_t new_last_fsb = roundup_64(*last_fsb, align);
error = xfs_bmap_eof(ip, new_last_fsb, XFS_DATA_FORK, &eof);
if (error)
return error;
Expand Down

0 comments on commit 76b5730

Please sign in to comment.