]> git.baikalelectronics.ru Git - kernel.git/commit
xfs: prevent creating negative-sized file via INSERT_RANGE
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 17 Apr 2018 06:07:45 +0000 (23:07 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Wed, 18 Apr 2018 00:29:11 +0000 (17:29 -0700)
commit3f18a4e45836611f06270bedd3b287758f1950a8
tree81813ecfc69323304465a776b397d5775b092c7a
parentfa703c39501bb5fa8341dc8199cc3566347faef6
xfs: prevent creating negative-sized file via INSERT_RANGE

During the "insert range" fallocate operation, i_size grows by the
specified 'len' bytes.  XFS verifies that i_size + len < s_maxbytes, as
it should.  But this comparison is done using the signed 'loff_t', and
'i_size + len' can wrap around to a negative value, causing the check to
incorrectly pass, resulting in an inode with "negative" i_size.  This is
possible on 64-bit platforms, where XFS sets s_maxbytes = LLONG_MAX.
ext4 and f2fs don't run into this because they set a smaller s_maxbytes.

Fix it by using subtraction instead.

Reproducer:
    xfs_io -f file -c "truncate $(((1<<63)-1))" -c "finsert 0 4096"

Fixes: 0515d12600d0 ("xfs: Add support FALLOC_FL_INSERT_RANGE for fallocate")
Cc: <stable@vger.kernel.org> # v4.1+
Originally-From: Eric Biggers <ebiggers@google.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: fix signed integer addition overflow too]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
fs/xfs/xfs_file.c