Skip to contentSkip to conversation

xfs: use xfs_vn_setattr_size to check on new size

PATCH In review Eryu Guan 2 participants 3 messages Dec 1, 2016 XFS filesystem

lore
Share & tools
lore

Eryu Guan

author
#0 lore raw

PATCH 1/1 xfs: use xfs_vn_setattr_size to check on new size

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
---
 fs/xfs/xfs_iops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_iops.c +1 -1
index c962999..b930be0 100644
@@ -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);
Signature · 1 line
2.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Eryu Guan

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.

Oops, looks like this was a merge error..

Quoted 11 lines

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

Quoted 6 lines
  # 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

Can you add this to xfstests?

The patch looks good:

author
#2 lore raw
Quoted 21 lines · Christoph Hellwig
Quoted 6 lines · Eryu Guan

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.

Oops, looks like this was a merge error..

Quoted 11 lines

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

Quoted 8 lines
Quoted 6 lines
  # 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

Can you add this to xfstests?

Sure, I'll work on it.

Quoted 4 lines

The patch looks good:

Thanks!

Eryu