xfs: limit extsize to size of AGs and/or MAXEXTLEN

The extent size hint can be set to larger than an AG. This means
that the alignment process can push the range to be allocated
outside the bounds of the AG, resulting in assert failures or
corrupted bmbt records. Similarly, if the extsize is larger than the
maximum extent size supported, the alignment process will produce
extents that are too large to fit into the bmbt records, resulting
in a different type of assert/corruption failure.

Fix this by limiting extsize at the time іt is set firstly to be
less than MAXEXTLEN, then to be a maximum of half the size of the
AGs in the filesystem for non-realtime inodes. Realtime inodes do
not allocate out of AGs, so don't have to be restricted by the size
of AGs.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Alex Elder <aelder@sgi.com>

authored by Dave Chinner and committed by Alex Elder 5315837d 4ce15989

+18 -2
+18 -2
fs/xfs/linux-2.6/xfs_ioctl.c
··· 985 986 /* 987 * Extent size must be a multiple of the appropriate block 988 - * size, if set at all. 989 */ 990 if (fa->fsx_extsize != 0) { 991 - xfs_extlen_t size; 992 993 if (XFS_IS_REALTIME_INODE(ip) || 994 ((mask & FSX_XFLAGS) && ··· 1009 mp->m_sb.sb_blocklog; 1010 } else { 1011 size = mp->m_sb.sb_blocksize; 1012 } 1013 1014 if (fa->fsx_extsize % size) {
··· 985 986 /* 987 * Extent size must be a multiple of the appropriate block 988 + * size, if set at all. It must also be smaller than the 989 + * maximum extent size supported by the filesystem. 990 + * 991 + * Also, for non-realtime files, limit the extent size hint to 992 + * half the size of the AGs in the filesystem so alignment 993 + * doesn't result in extents larger than an AG. 994 */ 995 if (fa->fsx_extsize != 0) { 996 + xfs_extlen_t size; 997 + xfs_fsblock_t extsize_fsb; 998 + 999 + extsize_fsb = XFS_B_TO_FSB(mp, fa->fsx_extsize); 1000 + if (extsize_fsb > MAXEXTLEN) { 1001 + code = XFS_ERROR(EINVAL); 1002 + goto error_return; 1003 + } 1004 1005 if (XFS_IS_REALTIME_INODE(ip) || 1006 ((mask & FSX_XFLAGS) && ··· 997 mp->m_sb.sb_blocklog; 998 } else { 999 size = mp->m_sb.sb_blocksize; 1000 + if (extsize_fsb > mp->m_sb.sb_agblocks / 2) { 1001 + code = XFS_ERROR(EINVAL); 1002 + goto error_return; 1003 + } 1004 } 1005 1006 if (fa->fsx_extsize % size) {