[Top] [All Lists]

[3.0-stable PATCH 02/36] xfs: fix allocation length overflow in xfs_bmap

To: stable@xxxxxxxxxxxxxxx
Subject: [3.0-stable PATCH 02/36] xfs: fix allocation length overflow in xfs_bmapi_write()
From: Mark Tinguely <tinguely@xxxxxxx>
Date: Mon, 03 Dec 2012 17:42:10 -0600
Cc: xfs@xxxxxxxxxxx
References: <20121203144208.143464631@xxxxxxx>
User-agent: quilt/0.51-1
From: Dave Chinner <dchinner@xxxxxxxxxx>

Upstream commit: a99ebf43f49f4499ab0e2a8a9132ad6ed6ba2409

When testing the new xfstests --large-fs option that does very large
file preallocations, this assert was tripped deep in

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@xxxxxxxxxx>
Signed-off-by: Ben Myers <bpm@xxxxxxx>
Reviewed-by: Christoph Hellwig <hch@xxxxxx>
 fs/xfs/xfs_bmap.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Index: b/fs/xfs/xfs_bmap.c
--- a/fs/xfs/xfs_bmap.c
+++ b/fs/xfs/xfs_bmap.c
@@ -4453,8 +4453,18 @@ xfs_bmapi(
                                        xfs_bmbt_get_all(ep, &prev);
                        } else {
-                               alen = (xfs_extlen_t)
-                                       XFS_FILBLKS_MIN(len, MAXEXTLEN);
+                               /*
+                                * There's a 32/64 bit type mismatch between the
+                                * allocation length request (which can be 64
+                                * bits in length) and the bma length request,
+                                * which is xfs_extlen_t and therefore 32 bits.
+                                * Hence we have to check for 32-bit overflows
+                                * and handle them here.
+                                */
+                               if (len > (xfs_filblks_t)MAXEXTLEN)
+                                       alen = MAXEXTLEN;
+                               else
+                                       alen = len;
                                if (!eof)
                                        alen = (xfs_extlen_t)

<Prev in Thread] Current Thread [Next in Thread>