]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
xfs: use xfs_vn_setattr_size to check on new size
authorEryu Guan <eguan@redhat.com>
Fri, 9 Dec 2016 05:49:54 +0000 (16:49 +1100)
committerDave Chinner <david@fromorbit.com>
Fri, 9 Dec 2016 05:49:54 +0000 (16:49 +1100)
Commit 6552321831dc ("xfs: remove i_iolock and use i_rwsem in the
VFS inode instead") introduced a regression that truncate(2) doesn't
check on new size, so it succeeds even if the new size exceeds the
current resource limit. Because xfs_setattr_size() was used instead
of xfs_vn_setattr_size(), and the latter calls xfs_vn_change_ok()
first to do sanity check on permission and new size.

This is found by truncate03 test from ltp, and the following is a
simplified reproducer:

  #!/bin/bash
  dev=/dev/sda5
  mnt=/mnt/xfs

  mkfs -t xfs -f $dev
  mount $dev $mnt

  # set max file size to 16k
  ulimit -f 16
  truncate -s $((16 * 1024 + 1)) /mnt/xfs/testfile
  [ $? -eq 0 ] && echo "FAIL: truncate exceeded max file size"
  ulimit -f unlimited
  umount $mnt

Signed-off-by: Eryu Guan <eguan@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fs/xfs/xfs_iops.c

index c962999a87ab7c4c5db851a6dea7a950a730023b..b930be0b1596592de8fc71aecbb25c033c513f17 100644 (file)
@@ -988,7 +988,7 @@ xfs_vn_setattr(
                        return error;
 
                xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
-               error = xfs_setattr_size(ip, iattr);
+               error = xfs_vn_setattr_size(dentry, iattr);
                xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
        } else {
                error = xfs_vn_setattr_nonsize(dentry, iattr);