xfs
[Top] [All Lists]

[PATCH v2] xfs: overflow in xfs_iomap_eof_align_last_fsb

To: xfs@xxxxxxxxxxx
Subject: [PATCH v2] xfs: overflow in xfs_iomap_eof_align_last_fsb
From: Peter Watkins <treestem@xxxxxxxxx>
Date: Mon, 1 Dec 2014 17:45:28 -0500
Cc: Peter Watkins <treestem@xxxxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yjw/9VoovpccXOnSKUXADxp/FvLeBoCJSGvanjl6Opg=; b=PwN+MKsGW6GU942zLKAHAJSC65lzePxtRKcC0UgtFBENYJ9lGoWcmlZHeL9dnl9XBY +KJhnc98XLCwzTQii4RspH+ImYhVsRGI6dGRgUFHLsmpCx2T8SY+HuD/t4zKzqNnzQf+ C0ONAmAu7B0qn6ym3kWWG9enMNFmzDM5LijpjDJiAM7HSQ8ax1wQ/SBWrQMFskJcsKFx Xrx7YXWCQYlv6mHz16fbx8AsBq0SIhmrBYAX138bLVQv+rkayD+AugHGGAi/xUM0odNC kW3QVMamk+eNfe0a1AB/omNSYv7avR9rfgTZi+2Avruvbo7hzIVeIbkAtOICg5mzDlTJ DB8g==
In-reply-to: <1416855973-6359-1-git-send-email-treestem@xxxxxxxxx>
References: <1416855973-6359-1-git-send-email-treestem@xxxxxxxxx>
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@xxxxxxxxx>
Reviewed-by: Nathaniel W. Turner <nate@xxxxxxxxxxxxxxx>
---
 fs/xfs/xfs_iomap.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index afcf3c9..3fad071 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -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;
 
@@ -70,8 +69,8 @@ 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;
        }
 
        /*
@@ -79,14 +78,14 @@ xfs_iomap_eof_align_last_fsb(
         * (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;
-- 
1.7.9.5

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