Skip to content

Commit a99ebf4

Browse files
dgchinnerBen Myers
authored andcommitted
xfs: fix allocation length overflow in xfs_bmapi_write()
When testing the new xfstests --large-fs option that does very large file preallocations, this assert was tripped deep in xfs_alloc_vextent(): XFS: Assertion failed: args->minlen <= args->maxlen, file: fs/xfs/xfs_alloc.c, line: 2239 The allocation was trying to allocate a zero length extent because the lower 32 bits of the allocation length was zero. The remaining length of the allocation to be done was an exact multiple of 2^32 - the first case I saw was at 496TB remaining to be allocated. This turns out to be an overflow when converting the allocation length (a 64 bit quantity) into the extent length to allocate (a 32 bit quantity), and it requires the length to be allocated an exact multiple of 2^32 blocks to trip the assert. Fix it by limiting the extent lenth to allocate to MAXEXTLEN. Signed-off-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Ben Myers <bpm@sgi.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent 4c393a6 commit a99ebf4

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎fs/xfs/xfs_bmap.c‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2383,6 +2383,8 @@ xfs_bmap_btalloc(
23832383
int tryagain;
23842384
int error;
23852385

2386+
ASSERT(ap->length);
2387+
23862388
mp = ap->ip->i_mount;
23872389
align = ap->userdata ? xfs_get_extsz_hint(ap->ip) : 0;
23882390
if (unlikely(align)) {
@@ -4629,6 +4631,8 @@ xfs_bmapi_allocate(
46294631
int error;
46304632
int rt;
46314633

4634+
ASSERT(bma->length > 0);
4635+
46324636
rt = (whichfork == XFS_DATA_FORK) && XFS_IS_REALTIME_INODE(bma->ip);
46334637

46344638
/*
@@ -4849,6 +4853,7 @@ xfs_bmapi_write(
48494853
ASSERT(*nmap <= XFS_BMAP_MAX_NMAP);
48504854
ASSERT(!(flags & XFS_BMAPI_IGSTATE));
48514855
ASSERT(tp != NULL);
4856+
ASSERT(len > 0);
48524857

48534858
whichfork = (flags & XFS_BMAPI_ATTRFORK) ?
48544859
XFS_ATTR_FORK : XFS_DATA_FORK;
@@ -4918,9 +4923,22 @@ xfs_bmapi_write(
49184923
bma.eof = eof;
49194924
bma.conv = !!(flags & XFS_BMAPI_CONVERT);
49204925
bma.wasdel = wasdelay;
4921-
bma.length = len;
49224926
bma.offset = bno;
49234927

4928+
/*
4929+
* There's a 32/64 bit type mismatch between the
4930+
* allocation length request (which can be 64 bits in
4931+
* length) and the bma length request, which is
4932+
* xfs_extlen_t and therefore 32 bits. Hence we have to
4933+
* check for 32-bit overflows and handle them here.
4934+
*/
4935+
if (len > (xfs_filblks_t)MAXEXTLEN)
4936+
bma.length = MAXEXTLEN;
4937+
else
4938+
bma.length = len;
4939+
4940+
ASSERT(len > 0);
4941+
ASSERT(bma.length > 0);
49244942
error = xfs_bmapi_allocate(&bma, flags);
49254943
if (error)
49264944
goto error0;

0 commit comments

Comments
 (0)